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)
Has anyone got their code to have the 2 different settings of CalculateOnBarClose working on some part of their indicator?
I have a code that HAS to have CalculateOnBarClase = true.
I now have decided to add to the code.
However, the new additions to code, would need it to run CalculateOnBarClose = false, while the rest of the code needs to
run CalculateOnBarClose = true.
How do I get to have only a certain section of code to run on CalculateOnBarClose = false, while the other is on CalculateOnBarClose = true?
Can you help answer these questions from other members on NexusFi?
Use the 'FirstTickOfBar' variable (NT7). ('IsFirstTickOfBar' in NT8)
When it's true you then know that the previous bar just closed and the new bar is just opening (i.e effectively the same as running code with CalculateOnBarClose = true), otherwise it's any old tick in a forming bar. But do also check that the barsAgo subscript [e.g. 0/1] is then appropriate depending on what you want to do, (i.e. [0] for the new bar, [1] for the just closed bar.)
[and use CalculateOnBarClose = false so you then have the choice, and NB this is no use in backtesting, which always runs on COBC = true anyway]
Saying 'logic errors' doesn't help much, it's used often and works fine, e.g with CalculateOnBarClose set to false, then in OnBarUpdate:
However, like I said, it's no use in backtesting, and of course you can get logic errors from a gazillion things, it's usually us that puts them in. It is worth spending time learning C#, using the NT help guide and looking at running code in the download section or on the Ninja support forum, remember NT7 v NT8 differences if appropriate.
Don't ever underestimate the value of a simple 'Print' statement either. Very little software can't have a bug shown up with one of those.