Pine Script - strategy, using ATR to take profit and stop loss

Viewed 453

I'm having issues getting the correct take profit and stop levels, I'd aiming to get a risk to reward 1:5. Is there a way i can get the number of pips of my SL then I can just times that by 1.5 but I'm currently getting the value.

Code sample below

twoTimes = ATR * 2
threeTimes = ATR * 3
SL = low - two
TP =  close + three
long_stop_level = na
long_profit_level = na
long_stop_level := longCondition ? SL : long_stop_level[1]
long_profit_level := longCondition ? TP : long_profit_level[1]

if strategy.position_size > 0
    strategy.exit("Exit Long", stop=long_stop_level, limit=long_profit_level) 


plot(strategy.position_size <= 0 ? na : long_stop_level, color=red, style=linebr, linewidth=2)
plot(strategy.position_size <= 0 ? na : long_profit_level, color=green, style=linebr, linewidth=2)
0 Answers
Related