I wanted to code a method to exit strategy before session close to avoid margin increase on the last hour of the session.
However, it ignores my efforts and I will post a screen here and explain what has been done.
1) Exit name column: Only 6 trades were exited using ADX_XSM_SessionClose name, which suggests it has been following my formula.
While much more trades were closed using default system's Exit on session close function (suggested by the name), and that ALSO suggests that my formula for Exit BEFORE session close was IGNORED.
How I coded that Exit BEFORE session close:
1.1) In OnBarUpdate method, I first define this condition:
STmFxXCond = ((endTime.AddMinutes(-50).TimeOfDay <= Time[0].TimeOfDay) ? true : false); // Condition: Stop At 50 Minutes Before Session Close Exit
sessionIterator.GetNextSession(Time[0], true); beginTime = sessionIterator.ActualSessionBegin; // DateTime Of Session Begin endTime = sessionIterator.ActualSessionEnd; // DateTime Of Session End
1.2) Exit method that is written after all entry conditions and variations:
if (Position.MarketPosition == MarketPosition.Long && STmFxXCond) { ExitLong(Qty, NameXL, NameELS); ExitLong(Qty, NameXL, NameELM); }
In my timezone, endTime should be 24:00:00 (or 0:00:00) or midnight. So, the default NinjaTrader method exit trades 1-4 seconds before session close.
My method uses earlier exit, but still it doesn't exit closer to 50 minutes (or 23:10:00 in my timezone). I understand, that using calculation on bar close instead of each tick I accept the risk that there may no be a bar from 23:10:00 till the end of the session, but from personal experience, activity before session close increases.
I also used TraceOrders = true, but, as you can see from output window - no lines have been generated.
So the focal question is: How to get that formula to work, that my exits would 1) use my formula correctly and generate 0 default Ninja exits with name "Exit on session close" and 2) exit closer to 23:10:00 (if 50 minutes to session close are set) than several minutes or seconds to session close?
Comment