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 ETFVoyageur, Today, 02:08 AM
        5 responses
        32 views
        0 likes
        Last Post ETFVoyageur  
        Started by Trader146, 03-29-2024, 01:22 PM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Started by Creamers, 04-27-2024, 05:32 AM
        7 responses
        47 views
        0 likes
        Last Post Creamers  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        176 responses
        2,396 views
        0 likes
        Last Post sidlercom80  
        Started by Felix Reichert, 04-26-2024, 02:12 PM
        3 responses
        33 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X