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

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?
    BertrandNinjaTrader Customer Service

    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 guillembm, Yesterday, 11:25 AM
      2 responses
      9 views
      0 likes
      Last Post guillembm  
      Started by junkone, 04-21-2024, 07:17 AM
      9 responses
      68 views
      0 likes
      Last Post jeronymite  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      4 responses
      18 views
      0 likes
      Last Post trilliantrader  
      Started by mgco4you, Yesterday, 09:46 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by wzgy0920, Yesterday, 09:53 PM
      0 responses
      10 views
      0 likes
      Last Post wzgy0920  
      Working...
      X