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

Head and Shoulder Indicator

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

    Head and Shoulder Indicator

    The NInjatrader H&S indicator in April and May 2013 issues of TASC (Dr. Siligardos' article on logarithmically defining and identifying H&Ss) does a great job.

    Ryan M. of NT did a great job of writing the code, however, the indicator only defines and identifies the regular H&Ss and ignores the inverse H&S which are just as important.

    It would be nice if Ryan M. or some one else to provide the code for the Inverse H&Ss (where the head is the lowest low in the pattern and shoulders are higher).

    I know NT has its consultants to help writing the code for a fee, but this effort is only reversing the input from highs and lows to complement and complete this fine indicator.

    #2
    It would be helpful if you would upload the current script for a starting point.
    Thanks.

    Comment


      #3
      Hello alligator,

      Thank you for your post.

      The code for the May 2013 Head and Shoulders by RyanM is available at the following link: http://www.ninjatrader.com/support/f...d=4&linkid=574

      Unfortunately, we do not provide programming services. However, one of the Support Forum members may be willing to take on this task for you.

      Comment


        #4
        Originally posted by aligator View Post
        The NInjatrader H&S indicator in April and May 2013 issues of TASC (Dr. Siligardos' article on logarithmically defining and identifying H&Ss) does a great job.

        Ryan M. of NT did a great job of writing the code, however, the indicator only defines and identifies the regular H&Ss and ignores the inverse H&S which are just as important.

        It would be nice if Ryan M. or some one else to provide the code for the Inverse H&Ss (where the head is the lowest low in the pattern and shoulders are higher).

        I know NT has its consultants to help writing the code for a fee, but this effort is only reversing the input from highs and lows to complement and complete this fine indicator.
        Hi Aligator

        As Patrick implied, I'm sure any one of the Forum 'old hands' would be happy to do this.

        I've frequently done very similar things like this for myself (i.e. 'inverting' a coding situation). I would be fascinated to have a peek at this code - it may prove a very helpful indicator for many Forum users.

        As Enso said, please upload the script and I'm sure it'll be done in a flash.

        Happy trading.

        Added later: I missed Patrick's link, so I'll have a peek now.
        Last edited by arbuthnot; 11-16-2014, 01:57 PM.

        Comment


          #5
          Originally posted by EnsoTrader View Post
          It would be helpful if you would upload the current script for a starting point.
          Thanks.
          See the link above in downloads.

          Comment


            #6
            Originally posted by arbuthnot View Post
            Hi Aligator

            As Patrick implied, I'm sure any one of the Forum 'old hands' would be happy to do this.

            I've frequently done very similar things like this for myself (i.e. 'inverting' a coding situation). I would be fascinated to have a peek at this code - it may prove a very helpful indicator for many Forum users.

            As Enso said, please upload the script and I'm sure it'll be done in a flash.

            Happy trading.
            Thanks a bunch. Script from downloads is here:

            Comment


              #7
              Thanks, Aligator.

              It's very late here now (across the Pond) but I'll say that I downloaded the script and loaded the H&S indicator. It didn't seem to be hugely effective on my own charts but that's not helping you!

              Given the complexity of the code and that it isn't really in my 'area of competence', it would take at least a 4 or 5 hour slog - at least... There are some geniuses in this Forum and they might be able to do it (if they're motivated!) in a shorter time.

              But thinking about the problem, it might not be necessary to alter the code at all.

              I stand to be corrected, but I think the solution is to set up an inverse (or a 'flip') of the price chart in a second panel and get the ind to operate on that.

              In principle, this should be easy: you set up a loop over the whole input series and in the loop, create a data series with the close of each bar deducted from the highest close over the entire chart + any positive constant. This will give you a positive 'flipped' price series. I'm too tired to work out if this would only operate in realtime.

              I'll try to give this a think when I have a free moment...

              Comment


                #8
                Hi again Aligator

                I've got this to work. As I said, I've created an indicator which flips the original chart exactly, and getting H&S to work on this, you get the inverse head and shoulders!

                Please see image. The red bars in the second panel show the exact points (I hope!) where the inverse H&S end, but the blue boxes don't match (as yet) because of the flipping.

                What matters is to get an indication of when this happens (the red bars) not where, so we have the essential.

                So this works. To get the boxes to match is a bit of a headache as it'll mean fiddling with the original indicator, which is highly complex.

                The best I can do - I hope - is to 'delete' the blue boxes as they aren't essential.

                Anyway, I've essentially got it working by this roundabout technique. I'll upload the 'ChartFlip' indicator later as I'll have write out instructions as well.

                If I don't, please remind me!

                P.S. Can I just make the point that, to adapt the original would take a great deal of work and I doubt anyone would do it free - but you never know. This has taken me an hour, and I don't mind that.

                P.P.S. If anyone's interested, the essential code for my ChartFlip is this:

                Code:
                Plot0.Set(MAX(High, Count - 2)[0] - Close[0] + 1 + MIN(Low, Count - 2)[0]);
                Attached Files

                Comment


                  #9
                  In my image in the previous post, I made the 'flipped' chart transparent.

                  The new image here better illustrates what's going on. You'll see the flipped or inverse chart in red and it's now obvious that the boxes correspond exactly to where they should on the red line - but not the blue line, which is the original close line.
                  Attached Files

                  Comment


                    #10
                    Thank you arbuthnot, certainly a creative and out of the box approach.



                    Cheers!


                    Originally posted by arbuthnot View Post
                    Hi again Aligator

                    I've got this to work. As I said, I've created an indicator which flips the original chart exactly, and getting H&S to work on this, you get the inverse head and shoulders!

                    Please see image. The red bars in the second panel show the exact points (I hope!) where the inverse H&S end, but the blue boxes don't match (as yet) because of the flipping.

                    What matters is to get an indication of when this happens (the red bars) not where, so we have the essential.

                    So this works. To get the boxes to match is a bit of a headache as it'll mean fiddling with the original indicator, which is highly complex.

                    The best I can do - I hope - is to 'delete' the blue boxes as they aren't essential.

                    Anyway, I've essentially got it working by this roundabout technique. I'll upload the 'ChartFlip' indicator later as I'll have write out instructions as well.

                    If I don't, please remind me!

                    P.S. Can I just make the point that, to adapt the original would take a great deal of work and I doubt anyone would do it free - but you never know. This has taken me an hour, and I don't mind that.

                    P.P.S. If anyone's interested, the essential code for my ChartFlip is this:

                    Code:
                    Plot0.Set(MAX(High, Count - 2)[0] - Close[0] + 1 + MIN(Low, Count - 2)[0]);
                    Last edited by aligator; 03-27-2015, 01:21 PM.

                    Comment


                      #11
                      Thanks very much, Aligator, and I was very interested to read your post.

                      It's again getting late here so I'll keep it short for now.

                      I like your name "Flipper" for the indicator. It reminds of my days wasted playing Pinball and I've had Pinball Wizard (slightly different form the Ninja variety) running through my head.

                      RyanM last posted on the Forum 8 months ago...

                      The thing works for the Dow cash but imperfectly for Forex. It might be the small decimal values (even if I remove the constant from the formula or change it to 'TickSize').

                      You know, the way the two HSs are coded is far too complex. I'm sure the thing can be done with a fraction of the code and far more effectively with a different approach.

                      To be continued...

                      Comment


                        #12
                        Hi again Aligator

                        Sorry it's taken time to get back. This has been a very busy week working on my ATM strategies.

                        I'm attaching my Flipper indicator. You'll notice that the coding is effectively contained in a few lines - vastly less than in the the two H&S ones.

                        This is the main part:

                        Code:
                        int LookBacka = 0;
                                    
                                    LookBacka = Math.Min(LookBack, Count - 2);
                                        
                                    if (CurrentBar < Count - 2 - LookBacka)
                                        return;
                                     
                                    Plot0.Set(MAX(High, Count - 2 - LookBacka)[0] - Close[0] + MIN(Low, Count - 2 - LookBacka)[0]);
                                }
                        LookBack specifies over how many bars you wish to flip. (If this exceeds the bar count, then, as you'll see, that's accounted for.)

                        What I don't understand is why sometimes it works perfectly, sometimes some of the chart flips, sometimes there's no flipping at all. If this were my priority, I'd post in the Forum about why this is happening or, better still, spend an hour or two trying to work out why its behaviour is so fickle!

                        I had no idea about the MirrorBar Type but that seems to do the job, but not always perfectly.

                        I think there's much more mileage to be gained in trying to redesign an 'H&S Detector' then spending hours turning those H&Ss on their heads.

                        Once I've got my own autotrading going, I should have quite a bit of spare time to look at this on another PC.

                        Would such a project be of interest to you?

                        Hope your trading is going well.

                        Cheers.
                        Attached Files
                        Last edited by arbuthnot; 11-21-2014, 01:19 PM.

                        Comment


                          #13
                          Hello folks,

                          anyone still have an inverse H&S pattern indicator?

                          Comment


                            #14
                            Hello all,

                            Having just had a very similar inquiry from a customer I have gone ahead and attempted to figure this out.

                            Idea:
                            Instead of rewriting every indicator that we want to grab inverse calculations from, we flip/mirror the data series and run the original indicators

                            Implementation:
                            Use MirrorBars Bar Type to flip the data series and apply the regular indicators

                            Issue:
                            MirrorBars returns negative OHLC values which many indicators are not coded to work with properly. For example, HSIdentify will not plot at all.

                            Solution:
                            I have rewritten the MirrorBars Bar Type with an additional parameter called "Positify". You want to set Positify to a value that is higher than the highest traded price in the non-mirrored version of data series you are viewing (to make sure all the bars are above zero). The default value is 3000.

                            Caveat:
                            The actual prices are not going to mean anything because we added an arbitrary value to them. This will not work with a very specific kind of indicator (that relies on absolute price values rather than price relationships/changes in price). This should however work with 90% of all indicators that are out there including the HSIdentify and HSBasicDef.

                            I have attached the new bar type to my post. It replaces MirrorBars so you have to delete the original MirrorBars Bar Type.

                            If you want the same results you would get with the original MirrorBars Bar Type just set "Positify" to 0.

                            How to add this bar type:
                            1. Exit NinjaTrader

                            2. Navigate to Documents\NinjaTrader 7\bin\Custom\Type and delete MirrorBar.cs and replace it with the new PosMirrorBar.cs.

                            3. Go back one folder to Documents\NinjaTrader 7\bin\Custom and delete NinjaTrader.Custom.dll

                            4. Open NinjaTrader

                            5. Navigate to Tools -> Edit NinjaScript -> Indicator -> [select any indicator] -> When the code editor pops up, press F5 on your keyboard to recompile

                            6. Exit NinjaTrader

                            7. Open NinjaTrader

                            8. Create a new chart using the PosMirrorBars bar type

                            Please let me know if you have any questions.
                            Attached Files
                            Michael M.NinjaTrader Quality Assurance

                            Comment


                              #15
                              Thanks very much, Michael. Your post has made very interesting reading.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X