Welcome to NexusFi: the best trading community on the planet, with over 150,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 -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
The above code is correct, so I can only speculate. Please post the entire indicator next time, export via File -> Utilities -> Export NinjaScript.
The code references the bars CurrentBar - 1 and CurrentBar - 2 for the condition. When OnBarUpdate() starts its course, it will start with CurrentBar = 0, which is the first bar of the bar series. For the first bar you cannot reference prior bars, because they do not exist. NinjaTrader will therefore throw an exception and show it in the logs.
The correct way of doing it, is to only access the two prior bars starting with CurrentBar = 2, because now you have two prior bars that exist, the bars numbered 0 and 1. The modified code below should run.
Hello Fat Tails, you are correct. That was it. I always have a if(CurrentBar<1) return; at the beginning of my scripts just in case. I had only forgotten to put it at 2 :tape:
Hello Fat Tails, you are correct. That was it. I always have a if(CurrentBar<1) return; at the beginning of my scripts just in case. I had only forgotten to put it at 2 :tape:
Thanks mucho
The "just in case" is dangerous, it really depends on the code. For some indicators you may want to write special instructions for (CurrentBar < period).