Here is what the attached toy strategy does:
In Initialize:
Create a secondary data series which effectively duplicates the primary data series (eg, call Add() with same BarType and same BarInterval as primary data series).
In OnBarUpdate:
Compare EMA(n)[0] against EMA(BarsArray[1], n)[0] ... I chose n = 7 ...
[Note carefully: the intent is to create BarsArray[1] to be the same as the primary data series of the chart, in effect the data in BarsArray[1] should become an exact duplicate of data in primary BarsArray[0], right?]
Compile:
Run strategy in Strategy Analyzer. Run simple test. Eq, try ES, 3 min, and test just a few days, such as 11/3 -> 11/4. But choice of instrument or BarType or BarInterval doesn't seem to matter.
Check OutputWindow:
Note that the Strategy prints "NOT EQUALS" for quite a few of these comparisons, but eventually starts printing "EQUALS".
Shouldn't these values *ALWAYS* be equal?
Why are they not equal?
I did some further experimenting with BarsRequired.
In SA window, I changed property "Min. bars required" (same as BarsRequired
property in the code) ... I found that ...
When BarsRequired = 0 all comparisons are always "EQUALS".
When BarsRequired != 0 the initial number of comparisons printing "NOT EQUALS" will vary, but the Strategy eventually starts printing "EQUALS".
Why does BarsRequired effect the output of this strategy?
Is this a bug in NinjaTrader?
I'm extremely concerned because I'm trying to track down an issue in my strategy where the selection of a "higher time frame" for the EMA is showing different results when the selected HTF just happens to be the same as the primary data series of the underlying chart window.
Yeah, I know, why select an HTF at all if you're just going to use the same period and interval as what's already on the chart, right? Well, whatever, but I'm trying not to have to limit user's selections, so was wondering why the HTF EMA vs BIP=0 EMA were giving different results? Ok, so I came up with this sample strategy, and found that BarsRequired=0 seems to fix the problem (perhaps by syncing BarsArray[0] and BarsArray[1] under the hood?)
I'm deeply concerned and quite stumped, because setting BarsRequired=0 in my very large and complex strategy did not magically "fix" my problem like it "fixed" the sample strategy I've attached.
In trying to track down my original issue, it seems I have found this other BarsRequired-effects-BarsArray issue. Feeling kinda stuck, so I thought I'd ask for some help.
Can someone explain what is going on?
I'm really at a loss, what am I missing?

Comment