这是解决方法
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)
,这是另一种方式
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)