How to prioritize market on open exit even if later that same day profit target limit order would have been true?
I trade long/short on daily bars and have three types of exits
- PreviousClose exit: if yesterday’s close is higher than 2 days ago close (for longs) then exit next day at open
- NBar exit: If it’s been 5 days, exit on the 6th day at open
- ProfitTarget exit: If a 5% profit target has been reached, exit same bar at limit order
I want to make exits #1 and #2 higher priority than exit #3. As an example, if I went long at $100, next day the stock closed up at $102, I would want to exit Market On Open the following day with my exit #1. The problem is sometimes after the open that stock keeps on going up to say $105, and my ProfitTarget exit kicks in instead, which is not feasible in real life, so I would want to prevent exit #3 in this scenario in a backtest…
// 1) PreviousClose exit
// SellPrice = Open;
// Sell = YesterdaysClose > TwoDaysAgoClose;
// 2) NBar exit
NBarExit = 5;
ApplyStop( stopTypeNBar, stopModeBars, NBarExit, ExitAtStop = 1 ); // N-bar exit; If ExitAtStop = 1 then N-bar stop has highest priority and it is evaluated before all other stops.
// 3) ProfitTarget exit
ProfitTargetNormal = 5;
ProfitTargetDisabled = 100;
LongProfit = IIf ( YesterdaysClose > TwoDaysAgoClose OR BarsSince( Buy ) > NBarExit, ProfitTargetDisabled, ProfitTargetNormal ); // If PreviousClose or NBars exit is true then do not want ProfitTarget exit to kick in, want to exit at Open
ShortProfit = IIf ( YesterdaysClose < TwoDaysAgoClose OR BarsSince( Short ) > NBarExit, ProfitTargetDisabled, ProfitTargetNormal ); // If PreviousClose or NBars exit is true then do not want ProfitTarget exit to kick in, want to exit at Open
ProfitTarget = IIf( Short, ShortProfit, LongProfit );
ApplyStop( stopTypeProfit, stopModePercent, ProfitTarget, ExitAtStop = 1 );