Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color on Strategy Chart

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

    Color on Strategy Chart

    I am adding multiple SMA lines to my Startegy chart with the following command:
    Add(SMA(SMAVariable1); Add(SMA(SMAVariable2) etc.
    I want to show these SMA lines with different colors on the Chart Tab of my Strategy Analyzer.
    How can I do this?

    #2
    Hello PaulZ,

    Thank you for writing in. Unfortunately this is not possible using the default SMA indicator. Please follow the steps below to create a custom version of the SMA indicator which allows you to set the plot color programatically:

    1) Navigate to Tools -> Edit NinjaScript -> Indicator -> SMA -> OK
    2) Right click in the code editor and press "Save As". Save the file as "ColorSMA" and press OK.
    3) Adjust the following segments of code:
    OLD:
    Code:
    #region Variables
    private int		period	= 14;
    #endregion
    NEW:
    Code:
    #region Variables
    private int		period	= 14;
    private Color plotColor = Color.Orange;
    #endregion
    OLD:
    Code:
    protected override void Initialize()
    {
    	Add(new Plot(Color.Orange, "SMA"));
    	Overlay = true;
    }
    NEW:
    Code:
    protected override void Initialize()
    {
    	Add(new Plot(plotColor, "ColorSMA"));
    	Overlay = true;
    }
    OLD:
    Code:
    #region Properties
    /// <summary>
    /// </summary>
    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    	get { return period; }
    	set { period = Math.Max(1, value); }
    }
    #endregion
    NEW:
    Code:
    #region Properties
    /// <summary>
    /// </summary>
    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    	get { return period; }
    	set { period = Math.Max(1, value); }
    }
    [XmlIgnore()]
    [Description("Color of SMA plot")]
    [GridCategory("Parameters")]
    public Color PlotColor
    {
    	get { return plotColor; }
    	set { plotColor = value; }
    }
    [Browsable(false)]
    public string PlotColorSerialize
    {
    	get { return NinjaTrader.Gui.Design.SerializableColor.ToString(plotColor); }
    	set { plotColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
    }
    #endregion
    4) After making the above changes, press F5 on your keyboard to recompile
    5) Now in your Strategy, use the following override to add a colored SMA to your chart:
    Code:
    Add(ColorSMA(int period, Color plotColor));
    //For example: Add(ColorSMA(14, Color.Red));
    Please let me know if you have any questions or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X