Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy when SMA1[0] Crossbelow SMA1[1]

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

    Buy when SMA1[0] Crossbelow SMA1[1]

    Hello,

    I currently messing around with NinjaScript to get used to it and there a simple question popped up:
    I would like to program a very simple strategy.
    I have a SMA with the length of 10 and I would like to buy when the value of the SMA on the current bar falls below the value of the SMA of the previous bar. I have tried to code this with CrossBelow(), which of course did not work since CrossBelow needs a series as an argument. My next try was slope, but I got kind of stuck there. Can somebody please provide a simple code snippet here?

    Thank you very much in advance!

    #2
    Hello funtra513,

    The SMA does return a plot series which can be used for a CrossBelow/Above.

    However, it does not appear you want a cross, you want to know when the SMA(10) on the current bar is less than the SMA(10) of 1 bar ago.

    if (SMA(10)[0] < SMA(10)[1])

    Below I am providing a link to a forum post with helpful information about getting started with NinjaScript and C#. Please watch the video 'Automate Your Trading with NinjaTrader's Strategy Builder'.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the fast reply.

      Sorry I forogt to mention, that I am specifically looking for a crossover or the point when the slope of the SMA is changing from rising to falling or the other way around.

      Comment


        #4
        Hello funtra513,

        There is a Slope method available to give the slope between two points.


        There are also IsRising and IsFalling methods to know if a series is rising or falling.



        You can save these values to a variable, if you want to compare with the previous bar.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          IsRising and IsFalling is not really useful in this case, because I want the trade to open only when the slope turns and not as long as the slope is negative.
          One of my ideas would be to create a data series of the slope and then combine it with the CrossBelow and Above function, but to me this seems a little too much effort for such a simple trading idea. Is their no other way of indicating the point when the slope turns?

          Comment


            #6
            Hello funtra513,

            The Slope has a start bar and end bar parameter. Meaning you can compare the slope between any two bars with any other two bars.

            For example you could compare the slope from 1 bar ago to 0 bars ago with 2 bars ago to 1 bar ago.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            64 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            139 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X