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

Slope() code/calculations

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

    Slope() code/calculations

    Hi NinjaTrader team,

    Could you please paste the code or calculations of the Slope() indicator? It is not accessible within the indicators.

    Slope(IDataSeries series, int startBarsAgo, int endBarsAgo)

    Thank you,
    whotookmynickname

    #2
    Hello whotookmynickname,

    The Slope will return the following value.

    return (series[endBarsAgo] - series[startBarsAgo]) / (startBarsAgo - endBarsAgo)
    Last edited by NinjaTrader_JC; 06-02-2013, 07:35 AM.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi,

      Is this calculation of slope meaningful? When a calculation of slope is carried out on points in geometric space, the distances in the X and Y directions are of the same increment and thus the calculation of slope is consistent. However when we try to calculate slopes for price changes over time we have the problem that it all depends on the scale of the chart you are viewing which is not accounted for in the calculation of slope. That is to say, if I scrunch up the chart to view more of the available price range then the line that the slope is calculated from would appear to flatten but this does not change the calculation of slope.

      How are people applying the value they calculate as the slope using Slope() and how are people creating a value of slope which is bounded by [1,-1]?

      Cheers,
      darmbk.
      Last edited by darmbk; 07-24-2013, 07:53 AM.

      Comment


        #4
        Originally posted by darmbk View Post
        Hi,

        Is this calculation of slope meaningful? When a calculation of slope is carried out on points in geometric space, the distances in the X and Y directions are of the same increment and thus the calculation of slope is consistent. However when we try to calculate slopes for price changes over time we have the problem that it all depends on the scale of the chart you are viewing which is not accounted for in the calculation of slope. That is to say, if I scrunch up the chart to view more of the available price range then the line that the slope is calculated from would appear to flatten but this does not change the calculation of slope.

        How are people applying the value they calculate as the slope using Slope() and how are people creating a value of slope which is bounded by [1,-1]?

        Cheers,
        darmbk.
        Slope has been used as a visualization for momentum, when charts were printed. As you noticed the concept of geometrical slope only makes sense, when the both the scales of the y-axis and the scale of the x-axis remain unchanged.

        This means that you need to eliminate the axis scales from any concept that is to replace slope. The formula given below by NinjaTrader_JC is a pretty simple version of slope, as it shows momentum divided by the momentum period.You may consider that as an average momentum per bar.

        A better definition of the slope of N data points would be based on a linear regression. This indicator is available for NinjaTrader as a default indicator and is called LinRegSlope. It is also called rise over run, where rise stands for the price change (momentum) and run for the number of bars.

        A shortcoming of this concept of slopes is that it does not adjust to different instruments, volatility and timeframes. Therefore it would not pass the consistency test (C'test) developed by William Eckhardt.

        To further enhance the concept and make it fit for use with different timeframes, the best approach is to divide slope by a measure of volatility, such as the standard deviation or the average true range, where the lookback period for the volatility should be a multiple of the momentum lookback period.

        Comment


          #5
          Hi Harry,

          Thanks for that explanation. I had been exploring the use of ATR as a volatility measure but had not thought of using std dev.

          Cheers,
          Dar.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mjairg, 07-20-2023, 11:57 PM
          3 responses
          213 views
          1 like
          Last Post PaulMohn  
          Started by TheWhiteDragon, 01-21-2019, 12:44 PM
          4 responses
          544 views
          0 likes
          Last Post PaulMohn  
          Started by GLFX005, Today, 03:23 AM
          0 responses
          3 views
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          12 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          7 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X