Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by FishTrade, Yesterday, 11:11 PM
    3 responses
    10 views
    0 likes
    Last Post FishTrade  
    Started by Graci117, Today, 09:02 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by ETFVoyageur, Today, 07:55 PM
    0 responses
    8 views
    0 likes
    Last Post ETFVoyageur  
    Started by janio973, Today, 07:24 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by aligator, 01-06-2022, 12:14 PM
    4 responses
    248 views
    0 likes
    Last Post john_44573  
    Working...
    X