NexusFi: Find Your Edge


Home Menu

 





Using DrawRegion to shade between two data series


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one FBJS with 3 posts (0 thanks)
    2. looks_two Silvester17 with 1 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 cory with 1 posts (3 thanks)
    1. trending_up 5,732 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 2 attachments




 
Search this Thread

Using DrawRegion to shade between two data series

  #1 (permalink)
 FBJS 
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.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


somebody else just request the same thing, here you go

Attached Files
Elite Membership required to download: BBand2.cs
Reply With Quote
Thanked by:
  #4 (permalink)
 FBJS 
Toronto
 
Experience: Advanced
Platform: NinjaTrader
Posts: 109 since Sep 2009
Thanks Given: 30
Thanks Received: 193

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:

DrawRegion("tag1" + CurrentBar, 1, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Middle, Color.Empty, Color.Lime, 2);

I wish this was better explained...

Started this thread Reply With Quote
  #5 (permalink)
 FBJS 
Toronto
 
Experience: Advanced
Platform: NinjaTrader
Posts: 109 since Sep 2009
Thanks Given: 30
Thanks Received: 193


cory View Post
somebody else just request the same thing, here you go

Thanks... apparently I found the answer myself just as you posted it... much appreciated!

Started this thread Reply With Quote
  #6 (permalink)
 
aligator's Avatar
 aligator 
Las Vegas, NV
Legendary Market Wizard
 
Experience: Advanced
Platform: Abacus, Slide Rule, HP-65
Trading: Futures, Stocks, Options
Posts: 3,618 since Aug 2010
Thanks Given: 1,071
Thanks Received: 5,991

This is a simple modification to draw region between Default RSI and the 50 line level.

The code will compile but regions are not painted.

Any hints please?

Attached Files
Elite Membership required to download: RSIRegion.cs
Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
Silvester17's Avatar
 Silvester17 
Columbus, OH
Market Wizard
 
Experience: None
Platform: NT 8, TOS
Trading: ES
Posts: 3,603 since Aug 2009
Thanks Given: 5,139
Thanks Received: 11,527


aligator View Post
This is a simple modification to draw region between Default RSI and the 50 line level.

The code will compile but regions are not painted.

Any hints please?

@aligator,

I'm pretty sure it does paint, but on the price panel above and below the 50 points

try to add "DrawOnPricePanel = false;" in initialize

Reply With Quote
Thanked by:




Last Updated on March 6, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts