如何根据条件为真,只有一次触发标签 我是松树脚本的新手,所以要忍受我。我试图弄清楚如何在“长”条件变为成立时绘制购买标签,但仅是第一次而不是每一个condi ...

问题描述 投票:0回答:2

这是解决方法
 if (longConditions and strategy.position_size < 0)
     strategy.entry("Long", true)
     longLabel = label.new(
      x=bar_index, 
      y=na, 
      text="Long",
      xloc=xloc.bar_index,
      yloc=yloc.belowbar, 
      color=color.green, 
      textcolor=color.white, 
      style=label.style_label_up, 
      size=size.normal)

if (closeLongConditions and strategy.position_size>0)
    strategy.close("Long")
    closeLongLabel = label.new(
     x=bar_index, 
     y=na, 
     text="Close",
     xloc=xloc.bar_index,
     yloc=yloc.abovebar, 
     color=color.red, 
     textcolor=color.white, 
     style=label.style_label_down, 
     size=size.normal)

pine-script
2个回答
0
投票
adamo

,这是另一种方式

if enterCondition
    if strategy.opentrades == 0
        label.new(bar_index, low,
                  text="Placing OCO order:" +
                       "\nTarget Price: " + str.tostring(TargetPrice, "#.##") +
                       "\nStop Loss Price: " + str.tostring(stopLossPrice, "#.##"),
                  style=label.style_label_up, color=color.rgb(211, 183, 55), textcolor=color.white, size=size.tiny)

0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.