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

How to calculate the value between two data points

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

    How to calculate the value between two data points

    I am used to using pinescript and we have a function called ta.change, which gives us the value of a piece of data between the current and past candle. For example if the ema is at 56, and on the previous candle it was 50, that means the ta.change is 6. I'm having a hardtime finding the similar function in the ninjascript language reference. I'm trying to make an indicator that measures the change of the LinRegSlope indicator. Thnaks in advance!

    #2
    Hello AdithBlack,

    Thanks for your post.

    The barsAgo value you use when calling LinRegSlope(int period)[int barsAgo] will determine the LinRegSlope() value you are accessing.

    To get the current value of the LinRegSlope(), you would use a barsAgo value of 0. 0 would be referring to the current bar. A value of 1 would be used the get the previous bar's LinRegSlope() value and so on.

    For example:
    Code:
    //Get the current bar LinRegSlope value.
     LinRegSlope(20)[0];
    
    //Get the previous bar LinRegSlope value
    LinRegSlope(20)[1];
    
    //Get the LinRegSlope value 2 bar ago
    LinRegSlope(20)[2];
    See this help guide page for more information about using LinRegSlope(): https://ninjatrader.com/support/help...sion_slope.htm

    Please let me know if you have further questions about this.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Awesome, how do I now make it plot the value so I can use it on a chart and in a strategy? I'm struggling to get it right, I want it to plot the value for "greenval".

      AddPlot(Brushes.Goldenrod, "Slopeline");

      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      val = LinRegSlope(Close, Length);
      }
      }

      protected override void OnBarUpdate()
      {
      double greenval = val[0] - val[1];
      }​

      Comment


        #4
        Hello AdithBlack,

        Thanks for your note.

        You must assign the value to the plot by using Value[0] = X, where 'X' is the value you are assigning to the plot.

        For example, the code might look something like this to assign greenval to the plot.

        Value[0] = greenval;.

        See this help guide page for more information about AddPlot and assigning values to a plot: https://ninjatrader.com/support/help...t8/addplot.htm

        Let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Perr0Grande, Yesterday, 08:16 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by f.saeidi, Yesterday, 08:12 AM
        3 responses
        24 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by algospoke, Yesterday, 06:40 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by quantismo, Yesterday, 05:13 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by The_Sec, 04-16-2024, 02:29 PM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Working...
        X