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

Why does this Condition not work? (MA Crossover)

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

    Why does this Condition not work? (MA Crossover)

    && HMA(200)[0] > HMA(200)[0] + 20 * TickSize)

    As part of my strategy I want to avoid downtrends in my testing, So I want to define that as the above formula. But adding it to my strategy it cancels out EVERY order, even the ones I can plainly see that the condition is true. I tried different Moving Averages and still no signals, I even tried this formula but even that didn't work :

    && HMA(200)[0] > HMA(200)[20]

    I know I'm probably missing something simple, can anyone please help!?

    #2
    Originally posted by B-Rex View Post
    && HMA(200)[0] > HMA(200)[0] + 20 * TickSize)

    As part of my strategy I want to avoid downtrends in my testing, So I want to define that as the above formula. But adding it to my strategy it cancels out EVERY order, even the ones I can plainly see that the condition is true. I tried different Moving Averages and still no signals, I even tried this formula but even that didn't work :

    && HMA(200)[0] > HMA(200)[20]

    I know I'm probably missing something simple, can anyone please help!?
    No quantity can be greater than itself, period.

    Comment


      #3
      But if that's true why does this work?

      HMA(ShortHMA)[0] > HMA(ShortHMA)[1]

      Comment


        #4
        Hello B-Rex,

        Thank you for your post.

        Here you are referencing the same value: HMA(200)[0] > HMA(200)[0] + 20 * TickSize
        And here you are referencing the current value (0) against the previous (1): HMA(ShortHMA)[0] > HMA(ShortHMA)[1]

        The indicators have bars just as the price data does, using 0 is the current bar and 1 would be the previous bar. Back to your initial inquiry, what are you trying to check for here?

        Comment


          #5
          I'm trying to define a downtrend and uptrend for my strategy. One of the simplest ways I saw to do this was to take a 200HMA and off set it by 20 Days. If the Offset version is above the current version then the price data is in a downtrend. I have attached an image for further clarification, the solid green line is the 200HMA the lighter dotted green line is the same HMA offset by 20 bars. See how they cross at the bottom of the trend?

          Comment


            #6
            Sorry the image didn't post correctly, here is the image.

            Comment


              #7
              Hello B-Rex,

              Thank you for your response.

              The following is an example of how to use slope to determine if the last 20 bars to the current bar are trending up or down:
              Code:
              if(Slope(HMA(200), 20, 0) > 0)
              Print("Up Trend");
              else if(Slope(HMA(200), 20, 0) < 0)
              Print("Down Trend");
              For information on Slope please visit the following link: http://www.ninjatrader.com/support/h.../nt7/slope.htm

              Comment


                #8
                Originally posted by B-Rex View Post
                But if that's true why does this work?

                HMA(ShortHMA)[0] > HMA(ShortHMA)[1]
                I am not sure what you are asking, but your two statements for comparison are NOT analogous.

                The first says: x > x + y
                the other says: a > b

                Look carefully at the statement of your original query. THAT is why I highlighted the offending parts of your original statement in blue.

                Comment


                  #9
                  So there is no way to offset a MA and have that as a condition like in the example chart?

                  Comment


                    #10
                    Originally posted by B-Rex View Post
                    So there is no way to offset a MA and have that as a condition like in the example chart?
                    You can do whatever you can code. You must code it correctly, is all. Your statement is impossible in an absolute mathematical sense. Write the correct statement and it will execute correctly.

                    What is the EXACT mathematical condition that you are trying to write? Not your intent, expressed in nebulous terms: the exact mathematical relationship, just described in words, instead of as a mathematical expression. If you can state that, I will write for you, the code that represents it. Or someone else will.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by StockTrader88, 03-06-2021, 08:58 AM
                    44 responses
                    3,967 views
                    3 likes
                    Last Post jhudas88  
                    Started by rbeckmann05, Today, 06:48 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post rbeckmann05  
                    Started by rhyminkevin, Today, 04:58 PM
                    4 responses
                    55 views
                    0 likes
                    Last Post dp8282
                    by dp8282
                     
                    Started by iceman2018, Today, 05:07 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post iceman2018  
                    Started by lightsun47, Today, 03:51 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post lightsun47  
                    Working...
                    X