thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Drawing a smooth band
Collapse
X
-
Drawing a smooth band
Hello, to draw a band off of the EMA, I am using the "DrawRegion" command. For example, I will draw 10 ticks above and 10 ticks below the EMA, creating the band. This works ok but I would like for the outer edges of my band to be smooth. Using the DrawRegion command causes the edges to be jagged. Is there a way I can achieve this?
thanksTags: None
-
That looks like you have a separate DrawRegion() for each bar. If you want a smooth curve, you will have to draw the region from start to finish as one region, not a series of regions that are pairwise abutting each other.Originally posted by pman777 View PostSure, see attached. Not sure what you mean by 'series' ... sorry.
Comment
-
thank you for your feedback. I understand what you are saying but being sort of new to ninjascrpt, I'm not sure how to modify my code to get the desired result. Below are my DrawRegion statements, which are executed OnBarUpdate. The upper and lower boundaries are calculated from the center EMA for that given bar. Can you suggest any modifications? thanks in advance.
DrawRegion("tag1" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] + (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);
DrawRegion("tag2" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] - (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);
Comment
-
Turn your upper and lower edges into Plots, then use DrawRegion() to color between them, using a single fixed tag, ending at the CurrentBar, and starting from however far back you want to start.Originally posted by pman777 View Postthank you for your feedback. I understand what you are saying but being sort of new to ninjascrpt, I'm not sure how to modify my code to get the desired result. Below are my DrawRegion statements, which are executed OnBarUpdate. The upper and lower boundaries are calculated from the center EMA for that given bar. Can you suggest any modifications? thanks in advance.
DrawRegion("tag1" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] + (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);
DrawRegion("tag2" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] - (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);
You might prefer to use DataSeries instead of Plots, as the DataSeries will not be shown in the config GUI, whereas Plots will be by default.Code:Plot1.Set(EMA(myEMA)[0] + (myBand * TickSize)); Plot2.Set(EMA(myEMA)[0] - (myBand * TickSize)); DrawRegion("RegionTag", CurrentBar, 0, Plot1, Plot2, Color.Empty, trendColorUp, 3);
Comment
-
Ok ... I was able to get the band to be smooth! However, I'm having one issue regarding the color of the band. If the EMA is rising, I want the band color to be green; conversely when the EMA is falling, I want the band color to be red. Below is my code. Currently it only paints the band one color regardless of the direction of the EMA. What am I doing wrong?
thanks again!
Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize));
Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize));
if (Rising(EMA(myEMA))) DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorUp, 3);
else DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorDn, 3);
Comment
-
Hello pman777,
If you try the below code then are you able to get the correct color.
Code:if (CurrentBar < 1 ) return; Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize)); Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize)); if (Rising(EMA(myEMA))) DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Blue, 3); else DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Red, 3);JoydeepNinjaTrader Customer Service
Comment
-
I cannot see anything wrong with your syntax. Are you sure that after editing your code, you compiled the indicator and reloaded the chart?Originally posted by pman777 View PostOk ... I was able to get the band to be smooth! However, I'm having one issue regarding the color of the band. If the EMA is rising, I want the band color to be green; conversely when the EMA is falling, I want the band color to be red. Below is my code. Currently it only paints the band one color regardless of the direction of the EMA. What am I doing wrong?
thanks again!
Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize));
Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize));
if (Rising(EMA(myEMA))) DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorUp, 3);
else DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorDn, 3);
Comment
-
Your code takes him back to creating a jagged region, which was the problem that he initially wanted to solve.Originally posted by NinjaTrader_Joydeep View PostHello pman777,
If you try the below code then are you able to get the correct color.
Code:if (CurrentBar < 1 ) return; Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize)); Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize)); if (Rising(EMA(myEMA))) DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Blue, 3); else DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Red, 3);
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
600 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
346 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment