I'm trying to draw long and short positions like the ones on the image automatically using pinescript.
Asked
Active
Viewed 1,118 times
5

Karl
- 481
- 1
- 6
- 13
-
1Were you able to achieve it ? – Sixteen Dec 13 '21 at 08:28
-
No, haven't figured it out yet – Karl Jun 19 '22 at 14:36
1 Answers
1
With strategy.position_size you can create a rule with your colors
Something like that:
// tpLvl = Your Take Profit level
// slLvl = Your Stop Loss level
p_tpLvl = plot(
strategy.position_size != 0 ? tpLvl : na,
title = 'Take Profit',
color = strategy.position_size != 0 and
strategy.position_size == strategy.position_size[1] ?
color.new(color.green, 0) : na,
linewidth = 1,
style = plot.style_linebr)
p_slLvl = plot(
strategy.position_size != 0 ? slLvl : na,
title = 'Stop Loss',
color = strategy.position_size != 0 and
strategy.position_size == strategy.position_size[1] ?
color.new(color.red, 0) : na,
linewidth = 1,
style = plot.style_linebr)
p_entryLvl = plot(
strategy.position_size != 0 ? strategy.opentrades.entry_price : na,
title = 'Entry Price',
color = strategy.position_size != 0 and
strategy.position_size == strategy.position_size[1] ?
color.new(color.white, 0) : na,
linewidth = 1,
style = plot.style_linebr)
fill(
p_entryLvl, p_tpLvl,
color = strategy.position_size != 0 and
strategy.position_size == strategy.position_size[1] ?
color.new(color.green, 80) : na,
title = 'Take Profit Area')
fill(
p_entryLvl, p_slLvl,
color = strategy.position_size != 0 and
strategy.position_size == strategy.position_size[1] ?
color.new(color.red, 80) : na,
title = 'Stop Loss Area')

Gu5tavo71
- 706
- 1
- 4
- 11