BUY LOGIC:
REF(CLOSE,1) > SimpleMovingAverage(HIGH,5) AND
VOLUME > SMA(VOLUME, 5) *1.5
SELL LOGIC:
SET MAX_POSITION_OPEN = 5
REF(CLOSE,1) > SimpleMovingAverage(LOW,5) AND
VOLUME > SMA(VOLUME, 5) *1.5
EXIT LONG :
CLOSE > HHV(30)
EXIT SHORT :
CLOSE < LLV(30)
Above is a code I am using to backtest an instrument.The problem is I want to add a check in EXIT LONG and SHORT positions to SET TAKEPROFIT and SET STOPLOSS according to the prices at which the entry was taken in BUY and SELL LOGIC if it executed.Let's say the BUY LOGIC is executed than POSITION SHOULD BE EXITED if price is up 20% from the price it was bought at and also if 20% down from the price it was bought at if price goes in reverse.How to do that and store the value of price at which conditions get triggered and which condition gets triggered.