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 sgordet, Today, 11:48 AM
            0 responses
            1 view
            0 likes
            Last Post sgordet
            by sgordet
             
            Started by Trader146, Today, 11:41 AM
            0 responses
            2 views
            0 likes
            Last Post Trader146  
            Started by jpapa, 04-23-2024, 07:22 AM
            2 responses
            16 views
            0 likes
            Last Post rene69851  
            Started by funk10101, Today, 11:35 AM
            0 responses
            1 view
            0 likes
            Last Post funk10101  
            Started by samish18, Today, 11:26 AM
            0 responses
            1 view
            0 likes
            Last Post samish18  
            Working...
            X