Announcement

Collapse
No announcement yet.

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.

        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);
            }

            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);
                }

                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.

                    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);
                        }

                        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 Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          581 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          336 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          103 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          554 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          552 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X