I use SessionIterator a lot in my trading tools and have noticed that when I combine it with base.IsFirstTickOfBar and base.Bars.IsFirstBarOfSession, it is getting called when it should not be. I am doing several if checks, see below.
if (this.sessionIterator != null)
{
if (base.IsFirstTickOfBar && base.Bars.IsFirstBarOfSession)
{
if (this.sessionIterator.GetNextSession(base.Time[0], true))
{
this.sessionHighPrice = double.MinValue;
this.sessionLowPrice = double.MaxValue;
}
}
}
- I was using market replay data for ES 09-20 on 8/3
- Trading hour CME US Index Futures RTH
- 8 Renko bars
- 09:30:01, first bar prints, no problems, base.IsFirstTickOfBar is false base.Bars.IsFirstBarOfSession is still true (makes sense)
- approximately 09:30:27 plus or minus a few seconds, the second bar prints, base.IsFirstTickOfBar && base.Bars.IsFirstBarOfSession are both true again (I believe incorrectly)
Problem 1:
I know some bars use the internal remove last bar which I believe Renko bars do as well. However, the IsFirstBarOfSession should not return true but it does.
Problem 2:
Exactly when this happens, Close[0], Low[0] are both set to 3263.75 which is not a valid print anywhere in the orderbook during that moment. It appears to be exactly the low/closing of the previous session 7/31. The actual low price at the moment was 3281.25 plus or minus a few ticks but nowhere near the 3263
Entire solution code available here on GitLab. The JDT.NT8.Indicators mid price indicator (non sharpdx version) or JDT.NT8.Indicators.Demos DemoSessionIterator are probably the easiest to reproduce with but any which use this mechanism exhibit the same behavior. Either of those could be copy/pasted into the NinjaScript Editor and compile straight away or the solution will place the JDT.NT8.dll in the bin/Custom folder and picked up when NT8 starts (then in Visual Studio attach to process and set breakpoints).
Like I mentioned, I use this a lot so I'm very interested to see any pointers toward a solution or maybe a bugfix started.

Comment