Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Zero Lag Smoothed TEMA

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

    Zero Lag Smoothed TEMA

    I am working on creating a zero lag TEMA smoothed with a zero lag technique and am running into problems. I am getting the error code, "Indicator 'ZeroLagSmoothedTEMA': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object." Attached below is the code, the commented out sections are some of the approaches I tried form referencing the help guides. However, I am still running into the same error so I figured I'd reach out. The code I am using as a reference for building this also attached.
    Attached Files

    #2
    Hello StoneMan78,

    Thanks for your post.

    There is a lot going on there.

    I would suggest adding print statements, in each section, to see which section the indicator stops at when the error occurs. You may need to continue adding print statements above each line to see which line it stops at and then check the line with the object reference error.

    For print statements, just use simple numbers or letters in the sequence. Print ('A") Print ("B"), etc.

    Make sure to open the new>Ninjascript output window and observe what letters or numbers you see, the last print indicates the error would be after that.

    Comment


      #3
      Thank you for the assistance PaulH, I was able to successfully finish the indicator. It's an interesting moving average, the behavior really changes a lot depending on the level of smoothing. At higher levels of smoothing it seems to perform similarly to a hull moving average. At lower levels it keeps the characteristics of the hyper sensitive zero lag TEMA. Will be fun to mess with. The code is pasted below.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class ZeroLagTEMAsmoothed : Indicator
      {
      private TEMA tEMA1;
      private TEMA tEMA2;

      private Series<double> ZeroTEMA;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"A zero lag TEMA with a zero lag smoothing algorithm applied to filter noise.";
      Name = "ZeroLagTEMAsmoothed";
      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;
      SmoothingFactor = 3;
      AddPlot(Brushes.Orange, "SmoothZLTEMA");
      }
      else if (State == State.Configure)
      {

      }
      else if (State == State.DataLoaded)
      {
      tEMA1 = TEMA(Inputs[0], Period);
      tEMA2 = TEMA(tEMA1, Period);

      ZeroTEMA = new Series<double>(BarsArray[0]);
      }
      }

      protected override void OnBarUpdate()
      {
      ZeroTEMA[0] = (tEMA1[0] * 2) - tEMA2[0];

      Print(string.Format("{0} | ZeroTEMA[0]: {1}",Time[0], ZeroTEMA[0]));

      SmoothZLTEMA[0] = 2 * WMA(ZeroTEMA, SmoothingFactor)[0] - WMA(WMA(ZeroTEMA, SmoothingFactor), SmoothingFactor)[0];

      Print(string.Format("{0} | SmoothZLTEMA[0]: {1}",Time[0], SmoothZLTEMA[0]));
      }

      #region Properties
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Period", Description="Number of bars used for calculations.", Order=1, GroupName="Parameters")]
      public int Period
      { get; set; }

      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="SmoothingFactor", Description="The amount of smoothing applied to the zero lag TEMA", Order=2, GroupName="Parameters")]
      public int SmoothingFactor
      { get; set; }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> SmoothZLTEMA
      {
      get { return Values[0]; }
      }
      #endregion

      }
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      68 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      151 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X