In Pine Script I'm coding a Donchian Channel trading system, where you go long on a 20-day high, and go short on a 20-day low.
I'm fine with coding the opening and closing of the positions, but I'm struggling with coding the initial Stop-Loss level, which I need to remain *fixed *while the whole position is open.
E.g. When you go long on the break of a 20-day high, I would like the initial stop loss to remain fixed at the 20-day low at the time of entry - and for this stop loss to not change.
I can code other versions of stop losses - like "strategy.position_average_price - atr(4)" but how would I link the stop loss to be fixed at the 20-day low at the point of entry?
Many, many thanks,
David.
DonchianLow=ta.lowest(close[1],20)
strategy.exit("Exit Long", from_entry="Long", stop=strategy.average_position_price - DonchianLow)