• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


How to put in the strategy of go long above an SMA?

  • Filter
  • Time
  • Show
Clear All
new posts

    How to put in the strategy of go long above an SMA?

    hi Guys,
    Sorry this might be a super basic question but I am having a hard time just making a simple request.
    All I wanted to test out a strategy if it goes above 10 SMA, i wanted to go long, and if it goes below 10 SMA go short.
    so far i put this in on user

    define input i put in Name: FastSMA, Type: int, Default 10, Min, 1, description is 10 Simple moving Average.
    on Conditions and actions I put in
    When the following conditions are trure:
    MA-Parameters-Input series-defualty input-period-FastSMA(everything else is default.)
    on the center drop down menu i put in grater than.
    MA-Parameters-Input series-defualty input-period-FastSMA(everything else is default.)
    do the following
    I put in Enter long position.

    I dont get it?? Why doesnt it show on the chart what I wanted it to do?

    Thanks for the help guys.

    Hello grgic,

    When you mention you want "it" to go above the SMA with a period of 10, are you referring to the current Close price?

    For example:

    if (CrossAbove(Close, SMA(10), 1))


    if (Close[0] > SMA(10)[0])

    Are you using the Strategy Builder?
    Do you have a screenshot of your conditions to show what you have selected?
    Chelsea B.NinjaTrader Customer Service



      I am using the strategy builder and here are my two attachments.
      Attached Files


        I also tested what you gave me at the bottom and it didnt work.
        (Close[0] > SMA(10)[0])


          Hello grgic,

          In your screenshot it appears you have on the left SMA with a period of 10 crossing above on the right the same SMA with a period of 10. You've used the same values and you are asking when the SMA plot crosses above itself. A plot will never cross above itself because it is that plot..

          Try a different period for one of the SMAs. Or try a different indicator in place of one of the SMAs. Or try a prices series such as the Close series..

          Below I am providing a link to a video on using the Strategy Wizard.

          And a short video that demonstrates using the Close of the current bar above the SMA with a period of 10 does work and can trigger an action.

          Also, in the screenshot I can see you are using NinjaTrader 7. I have moved your thread from the NinjaTrader 8 section to the NinjaTrader 7 Strategy Development section of the forums.
          Last edited by NinjaTrader_ChelseaB; 02-08-2017, 09:23 AM.
          Chelsea B.NinjaTrader Customer Service


            Hello [email protected],

            The CrossAbove / CrossBelow uses a lookback period that would detect the cross within that many bars. If this were set to 2, it would not guarantee that the cross occurred on the previous bar.

            Instead you would want to code this logic explicitly.

            If the close price of 2 bars ago is less than the SMA of 2 bars ago and the close price of 1 bar ago is greater than the SMA of 1 bar ago and the low of 0 bars ago is greater than the sma.

            Attached is a screenshot to illustrate.
            Attached Files
            Chelsea B.NinjaTrader Customer Service


              Hello Chelsea ,

              Thanks for your reply!
              I understand you!



                Thank you so much for all ur help, now for the exit

                Good Afternoon Chelsea,

                THANK YOU SO MUCH FOR THE HELP. you have been amazing to respond back so fast.

                I got it to work on the candles to enter the position, now I am trying to get an exit position.
                I put in the parameters to exit position of it cross below SMA. And I put in a new position when it cross below to short, and the trades will keep going back and forth. buy and sell.

                but now its not showing on the back test. it always shows the exit position on the close of the day for some sort of reason. Is there a way I can get ride of that. and have it only when it goes above the same and below sma.

                because I need this to work 24/6 I will run the strategy all day and night.


                  Hello grgic,

                  This is the Exit on close option.
                  Uncheck this in the parameters and the position will not be exited overnight.
                  Chelsea B.NinjaTrader Customer Service


                    Almost there

                    Good Evening Chelsea,

                    Thank you a million for helping me out. I will own you a big one.
                    I clicked it off, switched it over the False on close. Its working

                    I got the entry position locked down but now I am working on an exiting the position.
                    is there a way i can put in a parameter if the SMA cross below 5 to exit long.

                    Thank you once again.
                    Attached Files


                      Hello grgic,

                      Are you asking how to detect when an SMA period crosses below an SMA with a different period?

                      This is demonstrated in the Strategy Wizard video.

                      In the Condition Builder, on the left select Indicator -> SMA, set the Period. On the right select Indicator -> SMA, set a different period. In the center select CrossBelow.
                      In the actions select ExitLong

                      In my previous post #5 I've linked the wrong video. I'ved edited that post with the correct video.
                      Chelsea B.NinjaTrader Customer Service



                        This is the latest error's I am getting.

                        i Put in the parmaters if sma 5 cross below sma 10 to exit long.
                        and these are the errors I am getting.
                        Attached Files


                          Hi grgic,

                          There are invalid calls to the SMA() indicator.

                          Calls allowed:
                          SMA(int period)
                          SMA(IDataSeries input, int period)

                          Invalid calls in the screenshot:

                          Add(SMA(0, FastSMA));

                          Is the 0 you are using here meant to represent a dataseries?

                          Try without the '0, '.
                          Chelsea B.NinjaTrader Customer Service


                          Latest Posts


                          Topics Statistics Last Post
                          Started by abfefmu, Today, 05:33 AM
                          0 responses
                          1 view
                          Last Post abfefmu
                          by abfefmu
                          Started by bbdjad, Today, 04:36 AM
                          0 responses
                          Last Post bbdjad
                          by bbdjad
                          Started by mittie3, Today, 03:33 AM
                          0 responses
                          Last Post mittie3
                          by mittie3
                          Started by Againmain1, Today, 03:04 AM
                          0 responses
                          Last Post Againmain1  
                          Started by tonytimpa, Today, 01:33 AM
                          0 responses
                          Last Post tonytimpa