准确的进入和退出价格的策略背景



我只想简单地强调我的策略,在进入和退出价格范围内添加背景。我试着用填充、背景色、情节等来做,但我真的不知道如何才能得到入口和出口价格。

我使用限价订单进入,止损/获利回吐订单退出。我的代码如下:


if (longCondition)
longEnterPrice = high + (high * 0.0011)
strategy.entry("LONG_POS_ID", strategy.long, stop = longEnterPrice, limit = longEnterPrice, comment = "LONG_ENTRY")
strategy.exit("LONG_POS_ID", limit = longEnterPrice + longEnterPrice * 0.01, stop = longEnterPrice - longEnterPrice * 0.01, comment = "LONG_EXIT")

感谢您的帮助!

试试这个朋友

longEnterPrice = strategy.opentrades.entry_price(0)
limit = longEnterPrice + longEnterPrice * 0.01
stop = longEnterPrice - longEnterPrice * 0.01
if (longCondition)
strategy.entry("LONG_POS_ID", strategy.long, comment = "LONG_ENTRY")
strategy.exit("LONG_POS_ID", limit = limit, stop = stop, comment = "LONG_EXIT", when = strategy.position_size > 0)
p1 = plot(strategy.position_size > 0 ? limit : na,          color= color.green  , style=plot.style_linebr)
p2 = plot(strategy.position_size > 0 ? longEnterPrice : na, color=color.gray    , style=plot.style_linebr)
p3 = plot(strategy.position_size > 0 ? stop : na,           color=color.red     , style=plot.style_linebr)
fill(p1,p2, color= color.new(color.green, 80))
fill(p2,p3, color= color.new(color.red,   80))

加油,祝你的编码好运

最新更新