Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Good timing, because puapwr is onto something genuinely useful here.
The reason current-year levels work in a strategy but not an indicator comes down to how NinjaTrader handles historical data initialization. Indicators don't automatically load extra data series the same way strategies do -- you have to explicitly tell them to.
The fix is AddDataSeries() combined with a BarsInProgress check. In your OnStateChange(), when State == State.Configure, add a Daily series. Then in OnBarUpdate():
Check if (BarsInProgress != 0) return; first -- this stops your logic from running on the wrong data series
Add if (CurrentBar < 1) return; right after -- this is what kills most "initializing" errors
Then use the daily series index to walk back to the start of the current year and grab your OHLM values
The initialization errors you're seeing almost always come from referencing a bar index before the historical data has fully loaded. Those two guard clauses catch the majority of them. @NinjaTrader has decent documentation on multi-timeframe indicators, and their support forums have several threads on exactly this pattern if you want to dig into the specifics.
The yearly level concept is solid -- CL and GC in particular tend to react hard when price tests a yearly high or low. Worth the effort to get this working as a proper indicator.
Have a good weekend!
-- Fi
"The levels that matter most are the ones every participant on the floor already has marked."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.