Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA crossovers

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

    SMA crossovers

    I would like to knwo how to do a simple strategy with two identical sma's with one having a displacement and the other regular. I cannot find how to name and value the displaced one so the analyzer thinks I am comparing a 9 to a 9 as an example. If anyone can help please advise as I am very new at this. From taking the first webinar in the wizard this is a simple crossover but won't work. Thank you

    #2
    Hello traderdan68,

    I suggest to take a look at the following link, which will provide information and instructions upon using an offset in the condition builder of the Strategy Wizard.
    JasonNinjaTrader Customer Service

    Comment


      #3
      This is exactly what I want to do but the example link does not show
      how to put displacement. It shows how to offset by
      percentage, price or ticks. Not how much amount of displacement.
      Please advise us how to do this two identical moving average crossover,
      one without displacement and one with displacement value.

      Thanks.

      Comment


        #4
        badasan and traderdan68,

        The way I'll do it is to create a new indicator.

        Go to Tools -> New NinjaScript -> Indicator. Give a name eg SMAdisp and then Next until you reach the editor. Then, Tools -> Edit NinjaScript -> Indicator and open SMA -> Select all and copy.

        Back to the SMAdisp select all delete and then paste.
        Then, change public class SMA : Indicator to
        public class SMAdisp : Indicator

        Add the following line of code under Initialize()

        Displacement = x; (x is the displacement value you wish ie 9 or -12 etc and compile.

        Now you will have two SMA indicators and from the strategy wizard you select the cross above etc..

        I don't know if there is a quicker way to do it but the above will work.

        astra

        Comment


          #5
          In the Wiizard when using the Cross operators, you can't compare two indicator values (one with a displacement) since the internal cross methods don't support that.

          You would have to create custom conditions that check for the cross yourself and on one of the indicators, set the bars ago value back 1 to get your displacement.

          Something like

          value 1 of 1 bar ago is less than value 2 of 2 basr ago and
          valalue 1 of current abr is greater than value 2 of 1 bar ago
          RayNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Ray View Post
            In the Wiizard when using the Cross operators, you can't compare two indicator values (one with a displacement) since the internal cross methods don't support that.

            You would have to create custom conditions that check for the cross yourself and on one of the indicators, set the bars ago value back 1 to get your displacement.

            Something like

            value 1 of 1 bar ago is less than value 2 of 2 basr ago and
            valalue 1 of current abr is greater than value 2 of 1 bar ago
            Ray, thanks for the tip - I didn't know that cross operators with dispacement are not supported.

            Anyway, since a long time I always use custom conditions in my strategies like your example as I had some issues with cross operators. I don't remember now what was exactly the issue but I think had to do with rising / falling values + cross operators combinations and I was getting funny results. I also prefer to use custom conditions instead of rising/falling operators as I have more control of what I am doing.

            astra

            Comment


              #7
              Thanks Astra for your suggestion.

              I created SMAdisp and it compiles fine. When I put SMA and SMAdisp on the chart, they look good. However, when I use strategy to generate buy
              or sell signal looking at crossover of SMA and SMAdisp, no order is generated.

              Ray,

              Would you be able to put strategy code here
              that will create long and short signal
              when SMA(10) and SMAdisp(10) crosses above and below? (hope this is very simple for you)

              I am new to the programming and your exlplanation below is not
              enough for me to create strategy.

              Thanks in advance

              Comment


                #8
                Originally posted by badasan View Post
                Thanks Astra for your suggestion.

                I created SMAdisp and it compiles fine. When I put SMA and SMAdisp on the chart, they look good. However, when I use strategy to generate buy
                or sell signal looking at crossover of SMA and SMAdisp, no order is generated.

                Ray,

                Would you be able to put strategy code here
                that will create long and short signal
                when SMA(10) and SMAdisp(10) crosses above and below? (hope this is very simple for you)

                I am new to the programming and your exlplanation below is not
                enough for me to create strategy.

                Thanks in advance
                badasan,

                What Ray says is that the cross conditions are not supported for dispaced indicators. So, instead you have to do the following:

                Say, you buy when SMA crosses above SMAdisp.

                Under Conditions and Actions in the Strategy wizard you click add, then indicators->select SMA. Under Parameters -> BarsAgo you place =1. Condition "<". On the right hand side select SMAdisp, BarsAgo=2, OK.

                Again as above, Add, SMA -> BarsAgo=0, Condition ">", SMAdisp -> BarsAgo=1, OK.

                Under Do the Following : select Enter Long

                For the Short you click Set2 and you proceed as above

                Hope it helps

                astra

                Comment


                  #9
                  Thanks a lot astra. It works now.

                  Comment


                    #10
                    astra,

                    One quick question.
                    Do I have to select SMA on the left and SMAdisp on the right side
                    or can I forget about SMAdisp and just do with SMA on both side?

                    Thanks in advance

                    Comment


                      #11
                      astra,

                      Just for your information, the following two resulted in same thing.

                      case1.

                      if (SMA(14)[1] < SMAdisp(14)[2]
                      && SMA(14)[0] > SMAdisp(14)[1])
                      {
                      EnterLong(DefaultQuantity, "");
                      }

                      case 2.

                      if (SMA(14)[1] < SMA(14)[2]
                      && SMA(14)[0] > SMA(14)[1])
                      {
                      EnterLong(DefaultQuantity, "");
                      }

                      Comment


                        #12
                        Originally posted by badasan View Post
                        astra,

                        Just for your information, the following two resulted in same thing.

                        case1.

                        if (SMA(14)[1] < SMAdisp(14)[2]
                        && SMA(14)[0] > SMAdisp(14)[1])
                        {
                        EnterLong(DefaultQuantity, "");
                        }

                        case 2.

                        if (SMA(14)[1] < SMA(14)[2]
                        && SMA(14)[0] > SMA(14)[1])
                        {
                        EnterLong(DefaultQuantity, "");
                        }
                        Strange.. We've done exactly what Ray suggested as an alternative to cross conditions that are not supported. Perhaps even this is not supported. I'll tested it and come back to you

                        Comment


                          #13
                          You are right basadan, even the second method will not work. "Displacement" is useless for using it in strategies. It seems it only serves the purpose to visually represent the displaced values in a chart. As there is no information about this in the help files, once again we 've learnt it the hard way...

                          Anyway, below I have created an SMA indicator that displaces its values (with user selectable displacement - usefull for optimization) and it should work with strategies.
                          Attached Files
                          Last edited by astra; 06-07-2009, 08:38 PM.

                          Comment


                            #14
                            Below an "always-in-the-market" simple strategy of SMA and SMAdisp crossovers that works (eventually!). Have a nice day.

                            astra
                            Last edited by astra; 12-08-2009, 09:59 AM.

                            Comment


                              #15
                              Thank you so much astra,

                              I have one more question.
                              How would you change the code if strategy only trigger once
                              whether it is long or short whichever comes first and after that it won't
                              trigger any more trade even if there is a cross.

                              I know I can just shutdown the strategy right after first trigger but
                              just would like to pick your brain how to do it with programming.

                              Thanks a lot in advance

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gentlebenthebear, Today, 01:30 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by Kaledus, Today, 01:29 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              13 responses
                              45 views
                              0 likes
                              Last Post frankthearm  
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              56 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Working...
                              X