Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I include "flat" MA conditions in strategy?

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

    How can I include "flat" MA conditions in strategy?

    Hello -

    I am using the KAMA in one of my strategies (I use the Strategy Wizard BTW) and I would like it to do the following:

    - IF: middle parameter (say, "period 10") is flat, or doesn't move up or down by more than one tick within 5 bars

    - THEN: close long and/or close short position

    Does anyone know how to do this? I can't seem to find a way to include a flat condition.

    Thanks.

    #2
    If you mean that it has a range less than 1 tick you could do something like:

    if (MAX(KAMA(int fast,int period,int slow), 5)[0] - MIN(KAMA(int fast,int period,int slow), 5)[0] < TickSize)
    // Its flat
    RayNinjaTrader Customer Service

    Comment


      #3
      MA flat conditions using slope

      Hi,

      I'm reviving this thread!

      I too am having trouble coding an MA flat condition to avoid chop.

      My MA is the anaHoltEMA which has a period and trend setting that I use for long-term market trend. Originally I tried using this code to determine if an order should be placed or not using the wizard:

      like this:
      if (Slope(anaHoltEMA(Period, Trend).HoltEMA, 5, 0) > 20)

      or as part of another condition:
      && if Slope(anaHoltEMA(Period, Trend).HoltEMA, 5, 0) > 20

      Unfortunately none of these work and I've played with every numerical setting with no joy. It will either not do anything or take out all my long trades even when the slope is steep. As a thought, since I also have a working "rising/falling condition with the anaHoltEMA is it possible to simply add a slope value to that rather than adding an entire new condition?

      What do I need in order to set a certain slope value above which all trades must take place?

      Here's a screenshot of what I need to filter:

      http://postimage.org/image/6gv0w9myv/full/

      Thanks to anyone who can help me out.
      Last edited by Shadowshorter; 02-18-2013, 11:19 PM.

      Comment


        #4
        Shadowshorter, likely the value you check for in the slope is simply too steep, so it would never register any trades with that hard a slope being considered in the entry condition for your script. Keep in mind this is a rise over run slope calculation and not expressed in radians / angle. What I would suggest is creating an indicator or print to see which slope value you get in your 'chop zone' and then from there defining what rule to include to attempt better trade filtering for your scalper.

        Comment


          #5
          Hi Bertrand,

          So there isn't an easy way to tell ninja trader when the MA is neither rising or falling?
          I'm trying to get a fully automated system here and using an indicator which prints something for me to initiate a manual trade defeats the whole purpose.

          How can I bracket ma rising and falling conditions so that a value from X to Y means the ma should be considered rising or falling, leaving everything else as a no trade area.

          I'm not a programmer so if i have to write a complicated indicator its never going to happen.

          Thanks for your time Bertrand,

          Shadow

          Comment


            #6
            Shadowshorter, the idea to create the indicator was to better understand for which slopes you would then actually need to filter in your strategy condition, as the slope you used was just too hard a condition - there's per se no flat MA or slope, it would need to defined exactly what that would constitute in terms of a condition, as in the real world the MA will not be 100% flat, but just meander for example with a very low slope, even-though your eye might say : it's flat.

            Comment


              #7
              Hi Bertrand,

              My understanding is that a slope of 100 is a vertical line or should it be a value of 0?

              If I set an ma slope value of 10 and say that I can only go long or short if the slope value is higher than 10 I should be filtering all the price action below an ma slope of 10 correct? Or should it be the other way round with a slope of 90 instead of 10?

              Thanks

              Comment


                #8
                This understanding is unfortunately not correct - the slope you access uses a rise over runs calculation and therefore does not represent an angle.

                Comment


                  #9
                  Thanks for your reply.

                  My problem is that when I add the slope function i was using before without the rising/falling condition, no matter what numeric value I use for the slope, 1 or 100 or 20 or 80 or whatever, it either takes out all my long trades or none of them.

                  What am I doing wrong here:

                  if (ZeroLagTEMA(40).ZeroTEMA[0] > ZeroLagHATEMA(40).ZeroHATEMA[0]
                  && Position.MarketPosition == MarketPosition.Flat
                  && Slope(anaHoltEMA(80, 20).HoltEMA, 10, 0) > 5
                  && Close[0] > ZeroLagHATEMA(40).ZeroHATEMA[0])
                  {
                  EnterLong(1, "Long1");

                  Comment


                    #10
                    Correct, that's what I understood and my recommendation still stands - print or plot the slope value you work so that you can actually visualize the condition you're setting up, this filter here is too hard to let any trades comes through, in other words - try a lower #, as this steep of a slope filter everything out.

                    && Slope(anaHoltEMA(80, 20).HoltEMA, 10, 0) > 5

                    Comment


                      #11
                      I've input this:

                      protected override void OnBarUpdate()
                      {


                      // Condition set 1
                      if (Slope(anaHoltEMA(80, 20).HoltEMA, 10, 0) < #)
                      {
                      BarColor = Color.Black;
                      }
                      }

                      Okay, I'm getting some results. But I had no idea I would be using slope values of 0.0002.
                      When I go further the Wizard turns these values to 1E-05. How do I interpret that?

                      Looks like I'm going to have to create 2 conditions to bracket the flat ma status (one + value, one - value).
                      Last edited by Shadowshorter; 02-19-2013, 10:47 AM.

                      Comment


                        #12
                        Glad to hear, yes at this point if you go further to lower slopes it would switch to scientific notation format - http://chemlabs.uoregon.edu/GeneralR..._notation.html

                        Comment


                          #13
                          Okay, got it. One more question. What do I need to add to this condition in order for the strategy to not take any trades when the ma slope is defined as flat without closing any already opened positions:

                          // Condition set 2
                          if (Slope(anaHoltEMA(80, 20).HoltEMA, 5, 0) < 0.00091
                          && Slope(anaHoltEMA(80, 20).HoltEMA, 2, 0) > -0.003)
                          {
                          BarColor = Color.Fuchsia;
                          }

                          I can't seem to do it in the wizard.

                          Thanks
                          Last edited by Shadowshorter; 02-19-2013, 04:17 PM.

                          Comment


                            #14
                            Shadowshorter, if you have those slope condition with your entry sets, it should not influence the exits at all, so even those your flat conditions for non entry are triggered the current open trade would be held until other means take it out.

                            Comment


                              #15
                              Hi Bertrand,

                              Thanks for your time. But what do i need to add to tell my strategy to NOT take trades during this ma flat condition?
                              The only thing I can get it to do is paint the bars concerned.but I have no idea what the right command is to say: IF ma is flat then take no trades.

                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X