Hi how can I optimize taking profit after n days. For example If my condition then exit after n days and I want to see what n days has the best winrate to exit the trade.
If you are working on a Daily chart, you can compare the elapsed bars:
IF OnMarket AND (BarIndex - TradeIndex) = 8 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
if you want to exit the trade PROVIDED it’s profitable, this is the modified code:
IF OnMarket AND (BarIndex - TradeIndex) = 8 AND PositionPerf > 0 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF