Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to fill zone between moving averages?
Collapse
X
-
-
Came to this thread because I was having issues changing the region's colors at the crossing of two indicators. That's done now (thanks ballboy11 and NinjaTrader_PaulH).
I also wanted to change colors within the area/region (in between crossings) depending on the direction of one indicator, but I found that it would be creating too many objects and affect performance. Any ideas would be appreciated. For example: a fast EMA crossing up a slower EMA, the area/region is drawn green, but when it starts falling, the color switches to a darker green (still green until it crosses down). Probably not worth the effort or compute resources but people like the visual effects.
Comment
-
i copied the code from here but i am full of erorrs.....
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.MyIndicator
{
public class MyIndicator: Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"My Indicator developed in ninja";
Name = "MyIndicator";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Displacement = 0;
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Minute, 60);
AddDataSeries(BarsPeriodType.Minute, 60);
AddPlot(Brushes.Transparent, "Primary");
AddPlot(Brushes.Red, "Second");
AddPlot(Brushes.Aqua,"Third");
}
}
protected override void OnBarUpdate()
{
if(CurrentBars[1] <20 || CurrentBars[0]<20 || CurrentBars[2]<20 ) return;
Values[0][0]=DEMA(Opens[0], 5)[0];
Values[1][0]=DEMA(Closes[1], 5)[0];
Values[2][0]=DEMA(Opens[1], 5)[0];
if(Values[2][0]>Values[1][0])
{
Draw.Region(this, "tag1", CurrentBar, 0, Values[1][0], Values[2][0], null, Brushes.Aqua, 50);
if (bCloudSwitchGreen == true)
{
Draw.Region(this, "Tag" + nRegionStart, nCount, 0, LongTrend, MidTrend, Brushes.Transparent, pCloudUpColor, nOpacity);
nCount++;
}
if (bCloudSwitchGreen == false)
{
Draw.Region(this, "Tag" + nRegionStart, nCount, 0, LongTrend, MidTrend, Brushes.Transparent, pCloudDownColor, nOpacity);
nCount++;
}}
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MyIndicator.MyIndicator[] cacheMyIndicator;
public MyIndicator.MyIndicator MyIndicator()
{
return MyIndicator(Input);
}
public MyIndicator.MyIndicator MyIndicator(ISeries<double> input)
{
if (cacheMyIndicator != null)
for (int idx = 0; idx < cacheMyIndicator.Length; idx++)
if (cacheMyIndicator[idx] != null && cacheMyIndicator[idx].EqualsInput(input))
return cacheMyIndicator[idx];
return CacheIndicator<MyIndicator.MyIndicator>(new MyIndicator.MyIndicator(), input, ref cacheMyIndicator);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MyIndicator.MyIndicator MyIndicator()
{
return indicator.MyIndicator(Input);
}
public Indicators.MyIndicator.MyIndicator MyIndicator(ISeries<double> input )
{
return indicator.MyIndicator(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MyIndicator.MyIndicator MyIndicator()
{
return indicator.MyIndicator(Input);
}
public Indicators.MyIndicator.MyIndicator MyIndicator(ISeries<double> input )
{
return indicator.MyIndicator(input);
}
}
}
#endregion
Comment
-
Here is the file for you and what you are trying to do. It will work. It looks like you want to compare with the 60 minute chart and what other time frame you are trading with MyIndicator.zip
Comment
-
i want to place it on 75 tick chart, and need sma 20/70 bandOriginally posted by ballboy11 View Posthere is the file for you and what you are trying to do. It will work. It looks like you want to compare with the 60 minute chart and what other time frame you are trading with [ATTACH]n1057757[/ATTACH]
thaknsLast edited by hir04068; 05-17-2019, 04:37 AM.
Comment
-
hello,Originally posted by ballboy11 View PostHere is the file for you and what you are trying to do. It will work. It looks like you want to compare with the 60 minute chart and what other time frame you are trading with [ATTACH]n1057757[/ATTACH]
I can't see an option to put sma period in the indicator?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
605 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
351 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
561 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment