Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating Breakouts

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

    Calculating Breakouts

    I would like to build an indicator/strategy that will calculate the distance from one swing to the next.

    Unlike standard swing indicators that are based on how many bars have passed to determine strength this would need to be based upon tick distance like the PriceActionSwing.

    I would like to have the number of ticks that one swing is from the other based upon the starting point being the break of the previous swing and not the low or high bar.

    In other words, if the trend is up and following a standard HL to HH pattern - instead of measuring from HL to HH I want to measure (in ticks) from the previous HH to the new HH. So from say the top of wave 1 to the top of wave 3.

    How do I do this?

    I attached a screen shot to hopefully illustrate what I mean.

    All help is greatly appreciated.
    Attached Files

    #2
    Originally posted by fibbee View Post
    I would like to build an indicator/strategy that will calculate the distance from one swing to the next.

    Unlike standard swing indicators that are based on how many bars have passed to determine strength this would need to be based upon tick distance like the PriceActionSwing.

    I would like to have the number of ticks that one swing is from the other based upon the starting point being the break of the previous swing and not the low or high bar.

    In other words, if the trend is up and following a standard HL to HH pattern - instead of measuring from HL to HH I want to measure (in ticks) from the previous HH to the new HH. So from say the top of wave 1 to the top of wave 3.

    How do I do this?

    I attached a screen shot to hopefully illustrate what I mean.

    All help is greatly appreciated.
    Use the Swing() class, and measure from previous SwingHigh to current SwingHigh. You will have to determine on which bars they occurred, using instances 1 and 2. Once you have the bars, the rest is just a matter of using the bar properties (in this case Highs).

    ref: http://www.ninjatrader.com/support/h...html?swing.htm
    Last edited by koganam; 10-12-2013, 12:12 PM. Reason: Corrected spelling.

    Comment


      #3
      Hello fibbee,

      Also, keep in mind the Swing indicator can have the plot points recalculated as incoming data is updated, thus making it challenging to use in a strategy via programmatic calls. They are first and foremost mean to be used as visual trading tools

      With that said you can still use the indicators for your calculations but would need to understand what price points can be accessed at which time programmatically, since those can be different from the historically plotted ones.

      Happy to be of further assistance.
      JCNinjaTrader Customer Service

      Comment


        #4
        JC, you guys must have a FAQ database that you pull responses from because I'm coding the exact same indicator Fibee is working on and when I asked a question about Swing(), I received the exact same response...almost verbatim.

        I haven't written a line of code in years, so I'm struggling, here, too.
        I'll address my problem and debugging in 3 steps.

        Problem
        I noticed that the SwingHighBar( ) function was always returning either -1 or data from the very first bar displayed on my chart.

        STEP 1

        The following is the SwingHighBar( ) function copied directly from the Swing indicator
        and presented here for orientation.


        Code:
        public int SwingHighBar(int barsAgo, int instance, int lookBackPeriod) 
                {
                    if (instance < 1)
                        throw new Exception(GetType().Name + ".SwingHighBar: instance must be greater/equal 1 but was " + instance);
                    else if (barsAgo < 0)
                        throw new Exception(GetType().Name + ".SwingHighBar: barsAgo must be greater/equal 0 but was " + barsAgo);
                    else if (barsAgo >= Count)
                        throw new Exception(GetType().Name + ".SwingHighBar: barsAgo out of valid range 0 through " + (Count - 1) + ", was " + barsAgo + ".");
        
                    Update();
        
                    for (int idx=CurrentBar - barsAgo - strength; idx >= CurrentBar - barsAgo - strength - lookBackPeriod; idx--)
                    {
                        if (idx < 0)
                            return -1;
                        if (idx >= swingHighSwings.Count)
                            continue;                
        
                        if (swingHighSwings.Get(idx).Equals(0.0))            
                            continue;
        
                        if (instance <= 1) // 1-based, < to be save
                            return CurrentBar - idx;    
        
                        instance--;
                    }
        
            
                    return -1;
                }
        STEP 2

        The following is my code used for debugging.

        Code:
        protected override void OnBarUpdate()
        {[INDENT]//Check value of CurrentBar
        Print("CurrentBar value is " + CurrentBar.ToString());
        
        //
        int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2013, 10, 10, 16, 5, 0));
        
        
        // Print out the user-defined session open (10 OCT 2013 at 4pm)  bar closing price and bar I.D.
        Print("The close price at 1605 on bar " + Bars.GetBar(new DateTime(2013, 10, 10, 16, 5, 0)).ToString() + " was: " + Close[barsAgo].ToString());
        barsAgo = CurrentBar - Bars.GetBar(new DateTime(2013, 10, 11, 15, 0, 0));
        
        // Print out the user-defined session close (11 OCT 2013 at 3pm) bar closing price and bar I.D.
        Print("The close price at 1500 on bar " + Bars.GetBar(new DateTime(2013, 10, 11, 15, 0, 0)).ToString() + " was: " + Close[barsAgo].ToString());
                        
        //Check the returned value of SwingHighBar( ) as coded in the NinjaScript API example
        Print(High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 10))].ToString());
        [/INDENT]}
        STEP 3

        The following information includes Output Window results and my observations.

        Code:
        CurrentBar value is 0
        The close price at 1605 on bar 1151 was: 1.59649
        The close price at 1500 on bar 1426 was: 1.59565
        1.60214
        This seems to be a simple array indexing problem.
        If CurrentBar always starts at the very first bar on the chart at its '0' index and
        SwingHighBar( ) makes a first comparison based on a value of '0', then SwingHighBar( ) will never return anything other than '-1'. The only reason it returns '1.60214' in my Output Window is because the High[Math.Max(0, 0)] is just getting the high of CurrentBar, which is in the '0' array position or the first bar displayed on the chart.
        Unless the SwingHighBar( ) function or CurrentBar is modified, I don't see how this interface can ever work.



        Don't mean to hijack your thread, but since we're working on the same thing, I'm open to monitoring this thread more closely and working through these things together.

        Comment


          #5
          I completely failed to understand how CurrentBar works...even WITH the API.

          CurrentBar is only updated my OnBarUpdate( ). Nothing past the very first bar in a chart can be accessed by logic processed in Initialize( ) because OnBarUpdate( ) hasn't executed at that point, so CurrentBar will still be '0'.

          Once I threw this code into OnBarUpdate( ) by itself, the swing highs were returned:
          Code:
          Print(High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 10))].ToString());
          To be able to store and index this data, my assumption is one needs a new DataSeries object and Set( ) each returned Swing( ) value to the local custom DataSeries as OnBarUpdate( ) executes and increments CurrentBar.

          Comment


            #6
            Originally posted by leestockz View Post
            I completely failed to understand how CurrentBar works...even WITH the API.

            CurrentBar is only updated my OnBarUpdate( ). Nothing past the very first bar in a chart can be accessed by logic processed in Initialize( ) because OnBarUpdate( ) hasn't executed at that point, so CurrentBar will still be '0'.

            Once I threw this code into OnBarUpdate( ) by itself, the swing highs were returned:
            Code:
            Print(High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 10))].ToString());
            To be able to store and index this data, my assumption is one needs a new DataSeries object and Set( ) each returned Swing( ) value to the local custom DataSeries as OnBarUpdate( ) executes and increments CurrentBar.
            You can store data in any object that you wish to use. What will be most efficient will depend on what you want to do. DataSeries is unlikely to be the most efficient, as, in this particular instance, there will be many repeated values. (i.e., until there is a new Swing point, there will be no change in the value of the "Last Swing").

            Any of the List<> constructs may be a better choice: ArrayList, SortedList, Generic List.

            Comment


              #7
              Good point. I noticed the inefficiency of that plan after reviewing the most recent data from my debugging output window:

              Code:
              10/6/2013 5:20:00 PM : Bar 15 : SwingHighBar: -1 : Value: 1.60343
              10/6/2013 5:25:00 PM : Bar 16 : SwingHighBar: -1 : Value: 1.60348
              10/6/2013 5:30:00 PM : Bar 17 : SwingHighBar: -1 : Value: 1.60415
              10/6/2013 5:35:00 PM : Bar 18 : SwingHighBar: -1 : Value: 1.60413
              10/6/2013 5:40:00 PM : Bar 19 : SwingHighBar: -1 : Value: 1.60416
              10/6/2013 5:45:00 PM : Bar 20 : SwingHighBar: -1 : Value: 1.60417
              10/6/2013 5:50:00 PM : Bar 21 : SwingHighBar: -1 : Value: 1.60407
              10/6/2013 5:55:00 PM : Bar 22 : SwingHighBar: -1 : Value: 1.60403
              10/6/2013 6:00:00 PM : Bar 23 : SwingHighBar: -1 : Value: 1.60385
              10/6/2013 6:05:00 PM : Bar 24 : SwingHighBar: -1 : Value: 1.60388
              10/6/2013 6:10:00 PM : Bar 25 : SwingHighBar: 5 : Value: 1.60417
              10/6/2013 6:15:00 PM : Bar 26 : SwingHighBar: 6 : Value: 1.60417
              10/6/2013 6:20:00 PM : Bar 27 : SwingHighBar: 7 : Value: 1.60417
              10/6/2013 6:25:00 PM : Bar 28 : SwingHighBar: 8 : Value: 1.60417
              10/6/2013 6:30:00 PM : Bar 29 : SwingHighBar: 9 : Value: 1.60417
              10/6/2013 6:35:00 PM : Bar 30 : SwingHighBar: 10 : Value: 1.60417
              10/6/2013 6:40:00 PM : Bar 31 : SwingHighBar: 11 : Value: 1.60417
              10/6/2013 6:45:00 PM : Bar 32 : SwingHighBar: 12 : Value: 1.60417
              10/6/2013 6:50:00 PM : Bar 33 : SwingHighBar: 13 : Value: 1.60417
              10/6/2013 6:55:00 PM : Bar 34 : SwingHighBar: 14 : Value: 1.60417
              10/6/2013 7:00:00 PM : Bar 35 : SwingHighBar: 15 : Value: 1.60417
              10/6/2013 7:05:00 PM : Bar 36 : SwingHighBar: -1 : Value: 1.60412
              I'll do as you suggested and go with an array. I'll probably include a Time[ ] stamp with each corresponding entry so I can locate Bar data for the swing values based on a specified time.

              Like the other guy, Fibee, I'll be measuring the distance between the swing highs and swing lows and further filtering the data based on a pip/tick threshold.

              Comment


                #8
                I know I am little behind on picking up this thread but I am wondering, were you able to work this out? Do you have a working code?

                Dolfan

                Comment


                  #9
                  Buy a copy of Bloodhound.

                  Comment


                    #10
                    Measuring the delta between swings is something Bloodhound does?

                    Comment


                      #11
                      Originally posted by Dolfan View Post
                      Measuring the delta between swings is something Bloodhound does?
                      Or maybe you could just get something that does it directly and gives you a readout, where you can specify what percentage of the time a swing exceeds an output value. eg., show me the length of a swing that has been exceeded 70% pf the time.

                      ref: http://ninjatrader.com/support/forum...289#post441289

                      Comment


                        #12
                        Interesting indicator with obviously a lot work put into it. I'll examine this for possibilities. Thanks!

                        Best regards,

                        Dolfan

                        Comment


                          #13
                          I had trouble trying to configure it in the offline trading mode. I don't know if it gets any better after you buy it but not willing to spend money on it yet to find out. Thanks anyway.

                          Best regards,

                          Dolfan

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          576 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          334 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          553 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          551 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X