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 put in the strategy of go long above an SMA?

Collapse
X
 
  • 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

    1.
    define input i put in Name: FastSMA, Type: int, Default 10, Min, 1, description is 10 Simple moving Average.
    2.
    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.

    #2
    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))
    {
    EnterLong();
    }

    or

    if (Close[0] > SMA(10)[0])
    {
    EnterLong();
    }

    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

    Comment


      #3
      f

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

      Comment


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

        Comment


          #5
          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..

          (edited)
          Below I am providing a link to a video on using the Strategy Wizard.
          Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Wizard.3:23 Strategy Wizard Overview7:...


          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.
          Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.



          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

          Comment


            #6
            Hello alex@n,

            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

            Comment


              #7
              Hello Chelsea ,

              Thanks for your reply!
              I understand you!

              Sincerely,

              Comment


                #8
                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.

                Comment


                  #9
                  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

                  Comment


                    #10
                    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

                    Comment


                      #11
                      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.
                      Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Wizard.3:23 Strategy Wizard Overview7:...


                      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

                      Comment


                        #12
                        Error

                        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

                        Comment


                          #13
                          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, '.
                          Add(SMA(FastSMA));
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by adeelshahzad, Today, 03:54 AM
                          5 responses
                          31 views
                          0 likes
                          Last Post NinjaTrader_BrandonH  
                          Started by stafe, 04-15-2024, 08:34 PM
                          7 responses
                          31 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by merzo, 06-25-2023, 02:19 AM
                          10 responses
                          823 views
                          1 like
                          Last Post NinjaTrader_ChristopherJ  
                          Started by frankthearm, Today, 09:08 AM
                          5 responses
                          18 views
                          0 likes
                          Last Post NinjaTrader_Clayton  
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          43 views
                          0 likes
                          Last Post jeronymite  
                          Working...
                          X