|
Toronto
Experience: Advanced
Platform: NinjaTrader
Posts: 109 since Sep 2009
Thanks Given: 30
Thanks Received: 193
|
Hey there...
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:
if (Close[0] > Bollinger(2, 14).Middle[0])
{
DrawRegion("tag1", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Middle, Color.Empty, Color.Lime, 2);
}
else
{
DrawRegion("tag2", CurrentBar, 0, Bollinger(2, 14).Lower, Bollinger(2, 14).Middle, Color.Empty, Color.Red, 2);
}
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.
|