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 cre8able, Yesterday, 01:16 PM
      3 responses
      11 views
      0 likes
      Last Post cre8able  
      Started by ChartTourist, Today, 08:22 AM
      0 responses
      6 views
      0 likes
      Last Post ChartTourist  
      Started by LiamTwine, Today, 08:10 AM
      0 responses
      2 views
      0 likes
      Last Post LiamTwine  
      Started by Balage0922, Today, 07:38 AM
      0 responses
      5 views
      0 likes
      Last Post Balage0922  
      Started by JoMoon2024, Today, 06:56 AM
      0 responses
      6 views
      0 likes
      Last Post JoMoon2024  
      Working...
      X