im very new to coding and made the following parameters to automate my trading strategy. my stop loss just isnt working and i have no explanation as to why. also i think my TP and SL are flipped. but even if flipped the TP works just the SL doesnt. help me solve it please. heres where the script mentions SL and TP. there must be an issue somewhere. thank u in advance:
p=input.float(2.0,"Desired Profit %")
sl= input.float(1,"Desired Stop loss %")
TP = strategy.position_avg_price * (1 + (p* 0.01))
SL = strategy.position_avg_price * (1 - (sl* 0.01))
if long
strategy.entry("Long", strategy.long)
if short
strategy.entry("Short", strategy.short)
strategy.exit("Exit", "Long",limit=TP)
strategy.exit("Exit", "Long",limit=SL)
strategy.exit("Exit", "Short",limit=TP)
strategy.exit("Exit", "Short",limit=SL)