I am fairly new to Pine script and have already created an automated system.
But the problem is with calculating SL. With TP I have no problem, it is always precise but SL is always way off what it should be.

My logic for SL, if I am going short the SL will be high[1] + Sl for particular pair. But I need an exact number of pips so I am doing (high[1] - low[1]) + SL. I do not know why, it calculating just wrong.

This is an example of my script. Thank you

i_stopLoss = switch syminfo.ticker
CADJPY => 18
GBPCHF => -10
USDJPY => 9
GBPUSD => 2
=> -2

commision = switch syminfo.ticker
CADJPY => 2
GBPCHF => 4
USDJPY => 1
GBPUSD => 2
=> 2

i_tp = switch syminfo.ticker
CADJPY => 80
GBPCHF => 95
USDJPY => 104
GBPUSD => 105
=> 95

ratio = switch syminfo.ticker
USDJPY => 100
CADJPY => 100
GBPCHF => 10000
GBPUSD => 10000
=> 10000

TP = i_tp //Real
SL = i_stopLoss + commision

difference = (high[1] - low[1]) * ratio
total_sl = difference + SL

if something
strategy.entry('Buy Stop', strategy.long, stop=high, oca_name='Breakout', oca_type=strategy.oca.cancel, alert_message = buy, + str.tostring(syminfo.ticker) + .r,risk= + str.tostring(risk) + ,sl= + str.tostring(total_sl) + ,tp= + str.tostring(TP)) //Real

strategy.entry('Sell Stop', strategy.short, stop=low, oca_name='Breakout', oca_type=strategy.oca.cancel, alert_message = sell, + str.tostring(syminfo.ticker) + .r,risk= + str.tostring(risk) + ,sl= + str.tostring(total_sl)+ ,tp= + str.tostring(TP)) //Real

Pine script.jpg