Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change color on a EMA up and Down

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

    Change color on a EMA up and Down

    I am trying a very simple strategy to change color when going up and down. I get error message "double" doesn not contain a definition for Plots. The following is the code

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Color change on EMA from down to up and reverse
    /// </summary>
    [Description("Color change on EMA from down to up and reverse")]
    public class EMA15 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int ticks = 1; // Default setting for Ticks
    private string red = @""; // Default setting for Red
    private string green = @""; // Default setting for Green
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(EMA(15));
    Add(EMA(15));
    Add(EMA(15));
    Add(EMA(15));

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1

    if (Rising(EMA(15)))
    EMA(15)[0].Plots[0].Pen.Color = Color.Aqua;



    // Condition set 2
    if (Falling(EMA(15)))

    EMA(15)[0].Plots[0].Pen.Color = Color.Orange;

    }

    #region Properties
    [Description("Ticks to change")]
    [Category("Parameters")]
    public int Ticks
    {
    get { return ticks; }
    set { ticks = Math.Max(1, value); }
    }

    [Description("RED")]
    [Category("Parameters")]
    public string Red
    {
    get { return red; }
    set { red = value; }
    }

    [Description("Green")]
    [Category("Parameters")]
    public string Green
    {
    get { return green; }
    set { green = value; }
    }
    #endregion
    }
    }

    #2
    perryg, welcome to the forums! I suggest you follow this sample here and modify the code presented to use an EMA as base - http://www.ninjatrader-support2.com/...ead.php?t=3227

    Comment


      #3
      Much obliged. It works perfectly

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 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
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X