Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color the zone between 2 EMA's

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Color the zone between 2 EMA's

    Hello,

    I want to color the zone between 2 EMA's on the main chart.
    When the fast EMA upcrosses the slow EMA the zone must be colored ForestGreen
    When the fast EMA downcrosses the slow EMA the zone must be colored orange.Red

    I have written a script, but nothing is plotted.
    Can Someone help me out. What am I doing wrong? I already added some Print commands but they never get executed

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class EMACrossFillZone : Indicator
    {
    private Series<double> emaFast;
    private Series<double> emaSlow;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Custom Indicator to plot zone between two EMAs with customizable settings";
    Name = "EMACrossFillZone";
    IsOverlay = true;
    FastEMA = 20;
    SlowEMA = 110;
    FastEMACrossColor = Brushes.OrangeRed;
    SlowEMACrossColor = Brushes.ForestGreen;
    Opacity = 25;
    }
    else if (State == State.DataLoaded)
    {
    emaFast = new Series<double>(this);
    emaSlow = new Series<double>(this);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < SlowEMA || CurrentBar < FastEMA)
    return;

    emaFast[0] = EMA(Close, FastEMA)[0];
    emaSlow[0] = EMA(Close, SlowEMA)[0];

    if (CrossAbove(emaFast, emaSlow, 1))
    {
    PlotBrushes[0][0] = FastEMACrossColor;
    Print("Fast EMA Crossed Above Slow EMA");
    }
    else if (CrossBelow(emaFast, emaSlow, 1))
    {
    PlotBrushes[0][0] = SlowEMACrossColor;
    Print("Slow EMA Crossed Above Fast EMA");
    }
    else
    {
    PlotBrushes[0][0] = null;
    }

    // Plotting zone between EMAs
    if (emaFast[0] > emaSlow[0])
    {
    PlotBrushes[1][0] = FastEMACrossColor;
    PlotBrushes[2][0] = null;
    Print("Zone Color: " + FastEMACrossColor.ToString());
    }
    else
    {
    PlotBrushes[1][0] = null;
    PlotBrushes[2][0] = SlowEMACrossColor;
    Print("Zone Color: " + SlowEMACrossColor.ToString());
    }
    }

    region Properties
    [Range(1, int.MaxValue), NinjaScriptProperty]
    public int FastEMA { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    public int SlowEMA { get; set; }

    [Display(Name = "Fast EMA Cross Color"), NinjaScriptProperty]
    public Brush FastEMACrossColor { get; set; }

    [Display(Name = "Slow EMA Cross Color"), NinjaScriptProperty]
    public Brush SlowEMACrossColor { get; set; }

    [Range(0, 100), NinjaScriptProperty]
    public int Opacity { get; set; }
    #endregion
    }
    }​

    #2
    Hello Tobees,

    Thanks for your post and welcome to the NinjaTrader Forums!

    You are not adding any plots to the indicator script in the code you shared by calling the AddPlot() method.

    To add plots to an indicator, you would need to use the AddPlot() method in the script.

    After adding plots to the script, you would need to assign values to those plots so that they appear on the chart window.

    See the help guide documentation for more information about AddPlot() and sample code.

    AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm

    To color the region between two Series you would use the Draw.Region() method in the script.

    See this help guide page for more information about Draw.Region() and sample code: https://ninjatrader.com/support/help...raw_region.htm

    Here is a link to the help guide documentation on the Developing Indicators tutorials which you might find helpful: https://ninjatrader.com/support/help...indicators.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    574 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X