Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA Color change

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

    SMA Color change

    Hello fellow traders,
    I am after an SMA indicator which color changes depending on the slope. Would anyone have this indicator for NT8? thanks in advance

    #2
    Hello borge,

    Thank you for your note.

    Actually, the example on this page does exactly that - it's an SMA that colors the plot depending on whether the line is rising or falling:



    This is meant as an example, but I believe it does what you're looking for.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thanks for that but it seems to print 2 parallel lines. I was after an actual SMA which has color slopes grren up red down etc

      Comment


        #4
        Hello borge,

        Thank you for your reply.

        My mistake there, I got that example mixed up with this one from our User App Share that is a similar existing script that demonstrates this using the EMA that can be adapted to your needs.

        Below is a public link to the User App Share section of the NinjaTrader Ecosystem.
        https://ninjatraderecosystem.com/use...emaslopecolor/

        This script could be copied and then modified to call the SMA instead of the EMA.

        I am happy to answer any questions you may have about NinjaScript if you decide to code this yourself.

        This thread will remain open for any community members that may know of an existing script that already uses the SMA or would like to make the modifications on your behalf.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.

        Please let us know if we may be of further assistance to you.

        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

        Comment


          #5
          Lovely thanks for that. Which part of the code is required to edit the EMA to an SMA? Is it a simple change or a complex change? I have no coding abilities but i am great at copy and paste. cheers

          Comment


            #6
            Hello borge,

            The logic on line 57 could be substituted with the logic in the SMA indicator on lines 59 to 80.

            However, it may be easier to just call the SMA value and set this to the Value[0].

            Value[0] = SMA(Period)[0];
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello ChelseaB,

              So,
              Value[0] = CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]; sho
              uld be deleted and replaced with
              Value[0] = SMA(Period)[0];


              Is that correct?

              thx in advance

              Comment


                #8
                Hello borge,

                Yes, that is correct.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB,

                  ok so i have done as stated above, but unfortunately, the EMA still plots as an EMA rather than an SMA.. Could there be further changes required within the code?
                  Cheers,

                  Comment


                    #10
                    Hello borge,

                    Thank you for your reply.

                    It's likely it's just labeling the plot as EMA_Slope_Color unless you changed that to say SMA_Slope_Color.

                    Just make sure you're also changed any references to "EMA" in the script to SMA:

                    Code:
                    namespace NinjaTrader.NinjaScript.Indicators
                    {
                        public class SMASlopeColor : Indicator
                        {
                            protected override void OnStateChange()
                            {
                                if (State == State.SetDefaults)
                                {
                                    Description                                    = @"SMASlopeColor";
                                    Name                                        = "SMASlopeColor";
                                    Calculate                                    = Calculate.OnBarClose;
                                    IsOverlay                                    = true;
                                    DisplayInDataBox                            = true;
                                    DrawOnPricePanel                            = true;
                                    DrawHorizontalGridLines                        = true;
                                    DrawVerticalGridLines                        = true;
                                    PaintPriceMarkers                            = true;
                                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                                    //See Help Guide for additional information.
                                    IsSuspendedWhileInactive                    = true;
                                    Period                                        = 14;
                                    UpColor                                        = Brushes.LimeGreen;
                                    DnColor                                        = Brushes.Red;
                                    ColorSlope                                    = true;
                                    AddPlot(Brushes.Orange, "SMA_Slope_Color");
                                }
                    
                            }
                    
                            protected override void OnBarUpdate()
                            {
                                Value[0] = SMA(Period)[0];
                    
                    
                                if(IsRising(Value))
                                {
                                if(ColorSlope)
                                PlotBrushes[0][0] = UpColor;
                                }
                                if(IsFalling(Value))
                                {
                                if(ColorSlope)
                                PlotBrushes[0][0] = DnColor;
                                }            
                            }
                    
                            #region Properties
                            [NinjaScriptProperty]
                            [Range(1, int.MaxValue)]
                            [Display(Name="Period", Description="Number of bars to include in the calculation", Order=1, GroupName="Parameters")]
                            public int Period
                            { get; set; }
                    
                            [NinjaScriptProperty]
                            [XmlIgnore]
                            [Display(Name="Up Color", Description="Color for rising condition", Order=3, GroupName="Parameters")]
                            public Brush UpColor
                            { get; set; }
                    
                            [Browsable(false)]
                            public string UpColorSerializable
                            {
                                get { return Serialize.BrushToString(UpColor); }
                                set { UpColor = Serialize.StringToBrush(value); }
                            }            
                    
                            [NinjaScriptProperty]
                            [XmlIgnore]
                            [Display(Name="Down Color", Description="Color for falling condition", Order=4, GroupName="Parameters")]
                            public Brush DnColor
                            { get; set; }
                    
                            [Browsable(false)]
                            public string DnColorSerializable
                            {
                                get { return Serialize.BrushToString(DnColor); }
                                set { DnColor = Serialize.StringToBrush(value); }
                            }            
                    
                            [NinjaScriptProperty]
                            [Display(Name="Enable Slope Color?", Description="Color the plot?", Order=2, GroupName="Parameters")]
                            public bool ColorSlope
                            { get; set; }
                    
                            [Browsable(false)]
                            [XmlIgnore]
                            public Series<double> SMA_Slope_Color
                            {
                                get { return Values[0]; }
                            }
                            #endregion
                    
                        }
                    }
                    Make sure you remove the indicator from your chart and readd it once you've changed all the references to EMA to SMA for those changes to be applied.

                    Please let us know if we may be of further assistance to you.

                    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
                    573 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    575 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X