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 of a Moving Average

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

    Slope of a Moving Average

    Hello,

    I developed an indicator in NT 7 that would draw an up arrow under a bar if it crossed a moving average with a slope greater than 0.
    The code looked like this:
    if Slope(SMA(50)[0] > 0) && ) then...

    I read various posts on how to do it in NT 8 (including in the strategy builder), but I'm a bit lost on the correct syntax.

    Any pointer would be much appreciated.

    Thanks

    EDIT: With the strategy builder I get this, but I'd like to call the Slope of the SMA directly (instead of through a variable like SMA1), like in the above example.

    {
    SMA1 = SMA(Close, 50);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 0)
    return;

    // Set 1
    if (Slope(SMA1, 0, 0) > 0)
    {
    }​
    Last edited by laocoon; 02-23-2024, 03:32 AM.

    #2
    Hello laocoon,

    What you have will do what you are asking however you need to configure the parameters of the Slope, right now you are using 0 and 0 for its parameters. The way the builder works it uses variables for indicators so that would be correct.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse I understand that. I thought that the code as it is says that "if the Slope of the 50SMA is >0, then do something"

      Comment


        #4
        Originally posted by NinjaTrader_Jesse View Post
        Hello laocoon,

        What you have will do what you are asking however you need to configure the parameters of the Slope, right now you are using 0 and 0 for its parameters. The way the builder works it uses variables for indicators so that would be correct.

        Thanks Jesse. This is another difference between NT7 & NT8 NinjaScript I don't understand.
        In NT7, this would work: if Slope(SMA(50)[0] > 0) && ) then...
        ​You're saying that I need to "configure the parameters of the Slope", but what parameters would that be?
        I just want the indicator to draw something when the Slope of the SMA50 is greater than zero.

        The Strategy Builder creates the following code: if (Slope(SMA1, 0, 0) > 0)
        But what do the two zeroes (especially the second one) after SMA1 stand for?

        Thanks
        Last edited by laocoon; 02-26-2024, 08:31 AM.

        Comment


          #5
          Hello laocoon,

          There is no difference from NT7 here, the slope still has the same parameters from NT7. You need to configure the range of bars you want to know the slope of using a start bars ago and end bars ago. The strategy builder asks for those two inputs in the user interface when you click on Slope.




          JesseNinjaTrader Customer Service

          Comment


            #6
            Got it, thanks Jesse

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,788 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X