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 am trying to use DrawRegion to shade the background between data series, but I am noticing a bit of an interesting side effect that I am wondering if someone can help me with.
Let's suppose we take something simple like shading the area between the middle/upper and middle/lower bollinger bands, depending on whether price is above or below the midline:
This should shade the upper part of the bollinger band green when price is in the upper half, and red when price is in the lower half.
However, two things occur when I put this code in OnBarUpdate():
1. Upon loading the chart, BOTH regions are colored all the way back to the beginning of the chart.
2. As price starts to move, only one region starts out colored (the correct one, based on whether price is above or below). However, the minute price crosses back into the other region, it is automatically colored all the way back. So for example if price stays above the middle BB line for 5 minutes after I load the chart then the upper portion is green, but as soon as it crosses below it the lower region gets colored red, including the entire portion of time where price stayed above the middle band.
I am not an expert on this, so any help would be appreciated. I'd like to know how to color a region based only on the current location of price, so that when it crosses the middle bollinger band it starts coloring the proper area from that point forward and leaves the past bars alone.
Can you help answer these questions from other members on NexusFi?
Never mind... I got it to work after some experimentation. The key is to rename the "tag1" to "tag1" + CurrentBar, so it creates a different draw object instead of repainting the last one. I also changed parameters 2 and 3 to be the values 1 and 0, so it only draws one bar back: