No announcement yet.

Partner 728x90


Dynamic Support and Resistance lines using HMA

  • Filter
  • Time
  • Show
Clear All
new posts

    Dynamic Support and Resistance lines using HMA

    Hi all,

    Based on the swing hi/lo and TRO SR examples, how would I start coding a dynamic S&R based on a hull moving average. Using the example from SampleMulticolorPlot, I'm trying to draw horizontal lines to determine the swing highs and lows based on the color change conditions of a moving average of Hull moving average with a period of 21. I can change the sensitivity of the swing highs/lows by increasing or decreasing the period of the HMA.

    Example for upper line. When a HMA line turns RED, look for the highest swing high and start drawing the horizontal line until it reaches the next pivot swing.

    For lower line, when HMA turns green, then look for the lowest swing low and start drawing horizontal line until it reaches the next pivot swing.

    The horizontal line ends right before the HMA changes color.

    See my manually drawn screenshot below.

    Attached Files

    Hi qitrader,

    What you are trying to accomplish is very doable in NinjaTrader. Here are some pointers that should head you in the right direction.

    Take a look at my implementation of TRO Dynamic SR. In there you can see how the S and R lines are actually two plots. The plot style to acquire the effect shown is square.

    So you would start in the Initialize() method with
    Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Square, "Resistance"));
    and another one for the Support plot.

    You can then go into the OnBarUpdate() method and do something like
    if(HMA(21)[0] > HMA(21)[1])
    Now, the exact code wouldn't be that because that algorithm is wrong, but you get the idea of how to set your plot values. The proper algorithm would probably be something similar to the one used in TRO Dynamic SR. It persists the SR levels unless something redefines them and then it will continue to persist until it gets redefined again.

    Remember you will also need to define your plot. You can do so with something like this
    [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Resistance
        get { return Values[0]; }
    Hope this helps.
    Josh P.NinjaTrader Customer Service


      Thanks Josh,

      Some quick questions:

      1) what is the purpose of the following line and what does it do? It seems like when I remove this line, my indicator does not plot.


      if ( CurrentBar < 1 || (ToDay(Time[0]) == ToDay(Time[CurrentBar]))) return;

      2) I have attached my indicator but it doesn't seem to be picking the major swing highs/lows.

      Is there a more efficient algorithm to recognize the highest swing highs and lowest swing lows? Mine seems to be picking non swing high points such as the one attached below under SAM.

      3) How do i remove the label of the indicator with parameters on the top left corner of my chart?

      Attached Files
      Last edited by qitrader; 09-30-2007, 01:41 PM.


        1) The purpose of that line of code is to ensure you do not check bar indexes that do not exist. At the very beginning of your chart data there will not be any [1] or [2] index. Until you have more data it will add more indexes and then it will not cause problems when referencing that. You can read up more on this issue here.

        2) The algorithm you are using seems to be one designed for bar data rather than for moving averages. Your algorithm basically tries to find the top of the peaks and the bottom of the valleys. I don't know if using the same algorithm will be as effective on moving averages. Perhaps you can check out the algorithm involved in the Swing indicator provided by NinjaTrader.

        3) I am unaware of a way to do so yet, but it is on the list for future development.
        Josh P.NinjaTrader Customer Service


          Thanks again Josh.

          If I can find a way to integrate the swing indicator algorithm into my code, I think it would work. Any tips/hints on how I can put this together?



            In your earlier post, what is wrong with the points on the picture? You circled some of the bar's low values, but your indicator is just plotting according to if the HMA is rising or falling not based on whether the low is rising or falling. Your original algorithm in your DynamicSR.cs file should work just fine once you get the relationship you were hoping for correct.
            Josh P.NinjaTrader Customer Service


              Originally posted by qitrader View Post
              3) How do i remove the label of the indicator with parameters on the top left corner of my chart?
              Originally posted by Josh View Post
              3) I am unaware of a way to do so yet, but it is on the list for future development.
              You could try adding

              base.Name = "";

              to the Initialize() method. You have to remove and re-load your indicator if its already being displayed to get this to work.

              This does have the unfortunate side-effect of making the indicator name not display in the indicator list when the Indicators screen is being displayed.

              Best regards,



                How do I write the following code?

                if(Close[0]> X[0] && Close[1] < X[1]) where X is a displaced simple moving average of 5 bars to the right.

                I tried SMA (15,4)[0] (displaced 4 bars) but didn't work

                Any ideas...going to try a different algorithm


                  You do not need to use an input to displace an indicator. Just call SMA(15)[4]. That will displace it 4 spaces to the right. Make sure you have this in the beginning of OnBarUpdate() though.
                  if (CurrentBar < 4)
                  Josh P.NinjaTrader Customer Service



                    Your dynamic s/r levels indicator is great.

                    If you don't mind sharing - I have a question
                    for you?

                    How do you trade with this indicator?

                    I see the obvious "breakouts" and "breakdowns"
                    but what other indicators or method do you
                    attach to this to keep you out of the the trades
                    that go no where. Or what keeps you out of
                    as many of those types of trades as possible?

                    If you can explain that would be much appreciated,
                    if not I understand.



                      The general usage guidelines in this post is how I use TRO's Dynamic S/R. In real-time its much harder to discern how to act on new highs/lows, but that just comes with experience on watching particular instruments. The idea is for a quick scalp not major movements. Also it seems to work better on volatile stocks. Hope that helps.

                      I'm not sure how qitrader uses his implementation of the dynamic S/R, but I would love to hear about it too.
                      Last edited by NinjaTrader_JoshP; 10-06-2007, 09:51 PM.
                      Josh P.NinjaTrader Customer Service


                        Hi prostyle,

                        I basically use it as is and take small losses when it is not doing anything. This is a method that is somewhat similar to the Decisionbar strategy. The only conflict I'm currently having is that I'm not able to pick the exact swing highs/lows because my logic is flawed. I'm using highestbar and lowestbar of last x bars and I think there must be another way around this. If anyone care to give me a few tips on how to solve this, it would be great.




                          Maybe try
                          Swing(5).SwingHighBar(0, 1, CurrentBar)
                          Swing(5).SwingLowBar(0, 1, CurrentBar)
                          That will return which bar the last high/low were for the swing
                          Josh P.NinjaTrader Customer Service


                            Try this

                            Create a variable HH, to keep track of the highest high if the colorof HMA is Positive or the average is rising.
                            Create another variable, LL, to keep track of the lowest low if the color of HMA is negative or the average is falling.

                            Create two plots, Resistance and Support.

                            The values of these plots do not change unles the HMA condition is met.

                            // if the indicator is rising , keep track of the higest high;
                            IF HMA[0]>HMA[1] then

                            // if the indicator is falling keep track of the lowest low.
                            IF HMA[0]<HMA[1] then
                            LL=Math.Min(Low[0], LL);

                            // If the indicator turns down, reset LL and change Resistance to the highest high.
                            IF HMA[0] <HMA[1] and HMA[1]>HMA[2] then

                            // If the indicator turns up, reset HH to current High, and change Support to LL.
                            IF HMA[0]>HMA[1] and HMA[1]<HMA[2] then

                            Hope this helps

                            Last edited by APat1; 11-07-2007, 05:29 PM.


                              High Pobability trades

                              With this you will get high probability long trades when the low crosses above Resistance and short trades when the High crosses below Support.

                              Either case you set the stop loss to 5 pips below or above the SnR lines and bring them to breakeven asap.

                              Exit the long trade when the Resistance plot shootups or some kind of a trailing stoploss is hit. Similarly for the short trade.

                              The above would be relevant once a trend has been established, using, for example, RAMA.

                              Use a higher time frame, e.g 5 minutes to establish a setup and a lower time frame , 1 minute to time the trade.

                              Hope this helps.



                              Latest Posts


                              Topics Statistics Last Post
                              Started by AaronKoRn, Today, 07:57 PM
                              0 responses
                              1 view
                              Last Post AaronKoRn  
                              Started by fscabrera03, Today, 06:46 PM
                              0 responses
                              1 view
                              Last Post fscabrera03  
                              Started by NTPlayer, Today, 06:19 PM
                              0 responses
                              Last Post NTPlayer  
                              Started by MatthewLesko, Today, 05:43 PM
                              0 responses
                              Last Post MatthewLesko  
                              Started by PaulJC, Today, 03:17 PM
                              2 responses
                              Last Post PaulJC
                              by PaulJC