Reputation: 23
I'd like to just simply highlight my strategy with adding a background in the range of entry and exit price. I tried to do it with fill, bgcolor, plot, etc but I don't really find how can I get the entry and exit prices.
I'm using a limit order to the entry and stop loss/take profit orders for exit. My code looks like this:
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")
Any help is appreciated!
Upvotes: 0
Views: 658
Reputation: 2310
try this friend
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))
cheers and best of luck with your coding
Upvotes: 0