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 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 bmartz, Today, 09:30 AM
    2 responses
    11 views
    0 likes
    Last Post bltdavid  
    Started by f.saeidi, Today, 11:02 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by geotrades1, Today, 10:02 AM
    4 responses
    12 views
    0 likes
    Last Post geotrades1  
    Started by rajendrasubedi2023, Today, 09:50 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by lorem, Today, 09:18 AM
    2 responses
    11 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X