Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help Required: Applying LinRegSlope on the LinRegSlope of the Close Price

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

    Help Required: Applying LinRegSlope on the LinRegSlope of the Close Price

    Hi, I am experimenting with some numbers to indicate if the market is accelerating or decelerating. The way I am doing it is to apply the function LinRegSlope on the Close prices to obtain the regression slope and then apply the same function again the slopes computed to get the slope of the slopes. The slope of the close prices worked out fine as in they tally exactly when I independently verified them on an excel spreadsheet. But I run into problems with the with the regression slope of the slopes. The output I get is different. I am fairly new to ninja script and programming and I am attaching the codes below. Let me know if anyone spot any mistakes here. Much appreciated. Thanks.

    publicclass Acceleration : Indicator
    {
    #region Variables
    privateint period = 10;
    private DataSeries speedData;
    #endregion

    protectedoverridevoid Initialize()
    {
    period =
    10;
    speedData =
    new DataSeries(this, MaximumBarsLookBack.Infinite);
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    double acceleration;

    if (CurrentBar >= period)
    {
    speedData.Set(LinRegSlope(Close, period)[
    0]);
    Value.Set(LinRegSlope(speedData,period)[
    0]);
    }
    }

    #2
    lengguan, welcome to our forums - the code looks fine. I'm not sure though what you compare to exactly in Excel and how it would be internally calculated. Would you call a dedicated function there for slope of the slope, so in other words not feed the slope 1 result into it's own again?

    Comment


      #3
      Thanks Bertrand. You are right, the code is fine. After some digging, appears that there a few price data points on my excel were different from that used on ninjatrader. I should have checked on that earlier.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      580 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      335 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      102 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X