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

Displaced MA Crossover

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

    Displaced MA Crossover

    How do I create a crossover strategy for a displaced MA? I do not see the 'displacement' variable when I use the strategy wizard.

    Thanks.

    #2
    Hi Kumar, after looking at the brief definition for displacement in the indicator window, I believe you can just use the BarsAgo property instead of Displacement.
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hello Austin,
      [I am writing this while watching the how the strategy works with market replay]

      Your solution seems to work, but here is the problem:

      I have a simple test strategy -

      If priceclose crossabove displaced ma, plot a dot

      I see dots being plotted all over the place regardless of whether the price closed above or below the displaced ma [fortunately a dot is not plotted for all the bars].

      Often a dot gets plotted when the entire bar is above or below the displaced MA.

      Interestingly, the dots are plotted only for green bars and often appear if the preceding bar is a red bar

      This clearly is not working.

      Thanks for the help.

      Comment


        #4
        kumar, please post the code / strategy you use so we can take a look, it seems like you need to rework the conditions you use for plotting.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks for the response.

          Attached is the code / strategy

          Thanks
          Attached Files

          Comment


            #6
            Kumar, please use something like this as condition, yours was not displaced by x bars (6 bar SMA displaced 6 bars in my example) -

            Code:
             
            if (CrossAbove(Close, SMA(6)[6] , 1))
            {
            DrawDiamond("My diamond" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
            Alert("MyAlert0", Priority.High, "", @"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav", 0, Color.White, Color.Black);
            }
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks Bertrand, that worked beautifully.

              While you have the piece of code, could you please tell me why the alert sounds only one time.

              Thanks so much.

              Comment


                #8
                Use a unique ID for Alert, too -

                Code:
                 
                if (CrossAbove(Close, SMA(6)[6] , 1))
                {
                DrawDiamond("My diamond" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
                Alert("MyAlert0" + CurrentBar, Priority.High, "", @"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav", 0, Color.White, Color.Black);
                }
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Thanks, but how do I do that? Not familiar with c#/Ninja script, though I can make simple changes to the code.

                  Thanks again.

                  Comment


                    #10
                    Just add the snippet I provided to your OnBarUpdate(), like you did before.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, but not there! Do you mean I should add:
                      if (CrossAbove(Close, SMA(6)[6] , 1))

                      again before the alert?

                      Comment


                        #12
                        No - please replace Condition1 in your OnBarUpdate() of the script you posted with this code -

                        Code:
                        if (CrossAbove(Close, SMA(6)[6] , 1))
                        {
                        DrawDiamond("My diamond" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
                        Alert("MyAlert0" + CurrentBar, Priority.High, "", @"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav", 0, Color.White, Color.Black);
                        }
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          I had missed the "CurrentBar" - not very clever of me.

                          Any, it all works now.

                          Thank you for your patience.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by judysamnt7, 03-13-2023, 09:11 AM
                          4 responses
                          55 views
                          0 likes
                          Last Post DynamicTest  
                          Started by ScottWalsh, Today, 06:52 PM
                          4 responses
                          35 views
                          0 likes
                          Last Post ScottWalsh  
                          Started by olisav57, Today, 07:39 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post olisav57  
                          Started by trilliantrader, Today, 03:01 PM
                          2 responses
                          19 views
                          0 likes
                          Last Post helpwanted  
                          Started by cre8able, Today, 07:24 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post cre8able  
                          Working...
                          X