Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Signal Line to TSI

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

    Adding Signal Line to TSI

    Hello Support,

    If this is not the correct place to ask please let me know. I am trying to add a signal line to the built in TSI indicator. Instead of converting the one from this thread, I made a copy of the built in TSI and then added the bolded changes below to the code. The problem I'm having is that only the TSI line is plotted and not the signal line. (Sorry about the bold messing up the formatting) It worked once where the signal line was displayed but not the TSI. I changed one thing and after compiling it only shows the TSI line now. Not sure why both plots are not showing. Thanks for any help you may be able to provide.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        /// <summary>
        /// The TSI (True Strength Index) is a momentum-based indicator, developed by William Blau.
        /// Designed to determine both trend and overbought/oversold conditions, the TSI is
        /// applicable to intraday time frames as well as long term trading.
        /// </summary>
        public class TSISignal : Indicator
        {
            private double                constant1;
            private    double                constant2;
            private double                constant3;
            private double                constant4;
            private Series<double>        fastEma;
            private Series<double>        fastAbsEma;
            private Series<double>        slowEma;
            private Series<double>        slowAbsEma;
    [B]private Series<double>         signalEma;[/B]
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                             = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionTSI;
                    Name                                     = "TSI Signal";
                    Fast                                        = 9;
                    IsSuspendedWhileInactive    = true;
                    Slow                                       = 14;
    [B]signalEmaLength                   = 2; [/B]
    
    [B]AddPlot(Brushes.Gray, "signalEma");[/B]
                    AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameTSI);
                    AddLine(Brushes.White, 1, "ZeroLine");
                }
                else if (State == State.Configure)
                {
                    constant1    = (2.0 / (1 + Slow));
                    constant2    = (1 - (2.0 / (1 + Slow)));
                    constant3    = (2.0 / (1 + Fast));
                    constant4    = (1 - (2.0 / (1 + Fast)));
                }
                else if (State == State.DataLoaded)
                {
                    fastAbsEma    = new Series<double>(this);
                    fastEma        = new Series<double>(this);
                    slowAbsEma    = new Series<double>(this);
                    slowEma        = new Series<double>(this);
    [B]signalEma     = new Series<double>(this);[/B]
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar == 0)
                {
                    fastAbsEma[0]    = 0;
                    fastEma[0]        = 0;
                    slowAbsEma[0]    = 0;
                    slowEma[0]        = 0;
                    Value[0]        = 0;
    [B]signalEma[0]     = 0;[/B]
                }
                else
                {
                    double momentum    = Input[0] - Input[1];
                    slowEma[0]        = momentum * constant1 + constant2 * slowEma[1];
                    fastEma[0]        = slowEma[0] * constant3 + constant4 * fastEma[1];
                    slowAbsEma[0]    = Math.Abs(momentum) * constant1 + constant2 * slowAbsEma[1];
                    fastAbsEma[0]    = slowAbsEma[0] * constant3 + constant4 * fastAbsEma[1];
                    Value[0]        = fastAbsEma[0] == 0 ? 0 : 100 * fastEma[0] / fastAbsEma[0];
    [B]signalEma[0]     = EMA(Value, signalEmaLength)[0];[/B]
                }
            }
    
            #region Properties
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof (Custom.Resource), Name = "Fast", GroupName = "NinjaScriptParameters", Order = 0)]
            public int Fast
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptParameters", Order = 1)]
            public int Slow
            { get; set; }
    
    [B]        [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "SignalEMALength", GroupName = "NinjaScriptParameters", Order = 2)]
            public int signalEmaLength
            { get; set; }[/B]

    #2
    Hello Tenfold,

    The code you have provided only shows only plot added with AddPlot().

    Are you trying to add an additional plot so there are two calls to AddPlot()?

    Have you set the Values[plot index][bar index] for that plot?

    Below are public links to the help guide.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you I finally figured it out

      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