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)
I made an indicator that colors bars with a smaller open to close range than the previous 3 bars. I used this code:
I like now to improve that indicator by adding a selectable look back period and made these changes:
Unfortunately that didn´t work and it colors every bar, with a smaller open to close range than the entire selected look back period
(see attached chart). What I´m doing wrong here?
Many thanks in advance for every tip.
Can you help answer these questions from other members on NexusFi?
It colors every bar because the code does not keep in mind the prior result. Basically your condition would be false, if there is a single bar within the lookback period "barsback" that has a smaller body then the current bar. A workaround would be to use a boolean variable "narrowBody", set that variable to true, and then loop through the prior bars. In case that you find a single bar that has a smaller body than the current bar you may set the boolean to false and exit the loop:
The baisc logic of the indicator - detecting a narrow range - requires that it runs in mode "CalculateOnBarClose = true". If you wish to run it in "CalculateOnBarClose = false" to get a preliminary result, then the code above would be highly inefficient, as you would need to run through the entire loop with every incoming tick. Therefore to make the indicator efficient for use with "CalculateOnBarClose = false" you would need to modify the code, for example:
It makes no sense to run this indicator in mode "CalculateOnBarClose = false. I will try therefore your first code.
Does the complete code goes to the "OnBarUpdate()" section?
It makes no sense to run this indicator in mode "CalculateOnBarClose = false. I will try therefore your first code.
Does the complete code goes to the "OnBarUpdate()" section?
The first example should be included with OnBarUpdate().