Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamic Support and Resistance lines using HMA

Collapse
X
 
  • 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.

    Thanks
    Attached Files

    #2
    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
    Code:
    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
    Code:
    if(HMA(21)[0] > HMA(21)[1])
         Resistance.Set(Close[0]);
    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
    Code:
    [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

    Comment


      #3
      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.

      Code:

      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?

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

      Comment


        #4
        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

        Comment


          #5
          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?

          Comment


            #6
            qitrader,

            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

            Comment


              #7
              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,

              KBJ

              Comment


                #8
                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

                Comment


                  #9
                  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.
                  Code:
                  if (CurrentBar < 4)
                       return;
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    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.

                    ~C

                    Comment


                      #11
                      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, 08:51 PM.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        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.

                        thanks

                        Qi

                        Comment


                          #13
                          Maybe try
                          Code:
                          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

                          Comment


                            #14
                            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
                            HH=Math.Max(High[0],HH);
                            Resistance.Set(Resistance[1]);

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

                            // 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
                            Resistance.Set(HH);
                            LL=Low[0];

                            // 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
                            Support.Set(LL);
                            HH=High[0];


                            Hope this helps

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

                            Comment


                              #15
                              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.

                              Pat

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pdennis, Today, 07:43 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by NinjaTrader_Brandon, Today, 07:49 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post NinjaTrader_Brandon  
                              Started by b16_aln, Today, 05:15 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Negustrader, Today, 01:01 AM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by soon123, Yesterday, 10:50 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Working...
                              X