Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to understand the Swing Indicator

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

    Trying to understand the Swing Indicator

    Please refer to the attached image. The settings for the swing indicator is just strength 5. All others are default settings.

    - I'm having a hard time understanding why (1) was a new swing high price? I thought in that price action area, the swing high would remain (3).
    - If (2) is a swing low, then shouldn't there be a swing low somewhere around (5)? The strength is 5 and we are looking back 5bars. There are many new higher lows in that (5) area.
    - Same as the above idea for (4). There are many higher lows in that area for our strength value of 5, but it's one line at 2730

    I tried reading the documentation, but there is very little to explain in detail how the mechanics of the indicator works.

    #2
    You have to consider what the definition of a "Swing" is -- and how it is intimately tied to the value of the "Strength" parameter.

    Consider Swing(5) which means Strength parameter is 5.

    Understanding "Strength" is absolutely critical.
    1. This is the number of bars that MUST be lower on the left and right of a swing high.
    2. This is the number of bars that MUST be higher on the left and right of a swing low.

    In your area labeled (1), this is a new Swing high because the 5 bars to the left and 5 bars to the right are all lower. It doesn't matter that the new Swing high is actually lower price than a previous swing high, what matters is how a "Swing" is defined. The new swing high at the start of your area labeled (1) matches the definition of a Swing high with Strength=5, case closed, that's all that is needed.

    The price action does not remain (3) because the new swing high takes over as the current swing high, so a dotted line continues to show current swing high price. You're right that that the swing high from (3) was not "taken out", so in the back of your mind, just recall that that swing high has yet to be penetrated -- the swing indicator does not show you this kind of thing, it only plots the current swing high and swing low.

    (5) There is no swing low here because Strength=5 means 5 bars to left and 5 bars to the right (with Strength=5 we're talking an 11-bar sequence, where the bar in the middle is the swing bar) were not all higher.

    As you said, yes, there are many new higher lows in that area, but none of them match the definition of a Swing low w/Strength=5.

    Take a look at your area labeled (4) -- very carefully count how many bars are above what you perceive should be the swing low, you will notice on the left of that swing low, there are only 4 bars higher, but you need 5 to make that a swing low. On the right there are 5 bars higher, but you also need 5 on the left.

    The way the Swing definition is defined, the indicator does not know a bar is a swing high or low until N bars have passed (where N is the Strength parameter) because we need all N bars to close to confirm that the candidate swing bar is, indeed, the higher than all N bars (or lower than all N bars) ...

    Comment


      #3
      Hi Boonfly8, Thanks for your post.

      bltdavid described the functionality perfectly. The code for this indicator is open source and available to view in a NinjaScript editor for further studying.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by bltdavid View Post
        You have to consider what the definition of a "Swing" is -- and how it is intimately tied to the value of the "Strength" parameter.

        Consider Swing(5) which means Strength parameter is 5.

        Understanding "Strength" is absolutely critical.
        1. This is the number of bars that MUST be lower on the left and right of a swing high.
        2. This is the number of bars that MUST be higher on the left and right of a swing low.

        In your area labeled (1), this is a new Swing high because the 5 bars to the left and 5 bars to the right are all lower. It doesn't matter that the new Swing high is actually lower price than a previous swing high, what matters is how a "Swing" is defined. The new swing high at the start of your area labeled (1) matches the definition of a Swing high with Strength=5, case closed, that's all that is needed.

        The price action does not remain (3) because the new swing high takes over as the current swing high, so a dotted line continues to show current swing high price. You're right that that the swing high from (3) was not "taken out", so in the back of your mind, just recall that that swing high has yet to be penetrated -- the swing indicator does not show you this kind of thing, it only plots the current swing high and swing low.

        (5) There is no swing low here because Strength=5 means 5 bars to left and 5 bars to the right (with Strength=5 we're talking an 11-bar sequence, where the bar in the middle is the swing bar) were not all higher.

        As you said, yes, there are many new higher lows in that area, but none of them match the definition of a Swing low w/Strength=5.

        Take a look at your area labeled (4) -- very carefully count how many bars are above what you perceive should be the swing low, you will notice on the left of that swing low, there are only 4 bars higher, but you need 5 to make that a swing low. On the right there are 5 bars higher, but you also need 5 on the left.

        The way the Swing definition is defined, the indicator does not know a bar is a swing high or low until N bars have passed (where N is the Strength parameter) because we need all N bars to close to confirm that the candidate swing bar is, indeed, the higher than all N bars (or lower than all N bars) ...
        hi bltdavid,

        Thank you for taking the time to explain this. I am getting a grasp of this and just want to ask a few more follow up questions for confirmation.

        1. When NT plots the swing line, it plots all the dots at once. It looks like the bar the dots start to plot is the swing low, and it is from this bar that the left and right must be 5 bars. There is a swing low for area labeled (1) and (1a), but not for 2, because although the right to the bar satisfies the strength, the left does not.

        2. As for a swing high, labeled (3), if the big green up bar circled was lower than the (circled red) doji , then it would have a new lower swing high because the doji to the left satisfies the requirement but to the right is not satisfied due to the big green up bar.

        So for NT code, on a new bar, the code looks back the numbers of bars indicated by the strength, and also keeps track of number of bars + strength forward (from bars that has yet to happen), and plots the dots all at once (essentially a line) if a condition satisfies both left and right.

        Please confirm my thoughts, a lot of it is just thinking out loud!


        Thanks again bltdavid

        P.S. on the OT attached pic, labeled (4) does not satisfy like you said but it looks like the low bar (1:52, chart is 2min) was equal to the center bar you are probably referring to.


        Click image for larger version  Name:	Swing2.jpg Views:	2 Size:	272.6 KB ID:	1057078Click image for larger version  Name:	Swing2.jpg Views:	2 Size:	272.6 KB ID:	1057079
        Last edited by Boonfly8; 05-12-2019, 02:16 PM.

        Comment


          #5
          Originally posted by Boonfly8 View Post
          Thank you for taking the time to explain this. I am getting a grasp of this and just want to ask a few more follow up questions for confirmation.
          You're welcome. The "Swing" indicator is unlike almost everything else, so it can take a while to grasp the concepts.

          Originally posted by Boonfly8 View Post
          1. When NT plots the swing line, it plots all the dots at once. It looks like the bar the dots start to plot is the swing low, and it is from this bar that the left and right must be 5 bars.
          Very observant! It doesn't plot all the dots at once, per se, just N+1 dots (where Strength=N, easier to type "N" than "Strength"). Each additional dot after that is plotted separately.

          This indicator phenomenon is called "repainting". For an indicator to repaint upon (aka, draw upon) past bars is generally frowned upon and typically an undesirable side-effect of an indicator. Most indicators draw their lines and dots and paint their colors only for the most recently closed bar -- to reach back and repaint across N previous bars is a last resort, but the Swing indicator has no choice but to do it this way.

          Why? Because of the definition of a "swing" means the indicator must wait for N additional bars to close to confirm the swing. Read that last sentence 10 times. That's right, there is no other way around it, the algorithm is forced to work this way because that's how a Swing is defined. The key word is confirm.

          For Strength=5, the indicator does not know a swing high has occurred until 5 bars have closed. Oh sure, it's very easy to test the 5 bars on the left to see if they're all lower, and so now we mark this candlestick as a "candidate", aka a potential swing high. Now the indicator waits for the next 5 bars to close, always checking if the current bar is lower than the current candidate, and when the indicator detects we've found the 5 immediate bars after the candidate all lower -- it goes into high gear and does a single mass painting of 5 dots at the price of the swing high (or, said another way, it plots 1 dot for the current closed bar, and repaints the previous 4 bars with a dot as well) for a total of 5 dots. Thereafter, 1 dot is plotted (or painted) for each additional bar, as long as the high is less than the swing high.

          [EDIT: Oops, it repaints previous 5 bars, not just 4. The 5th bar furthest back is the swing bar itself, then 4 bars to the right need a dot, as well as the current closed bar needs a dot The current closed bar is the 5th bar to the right but the 6th dot drawn, because the swing bar itself gets a dot, too.]

          Originally posted by Boonfly8 View Post
          There is a swing low for area labeled (1) and (1a), but not for 2, because although the right to the bar satisfies the strength, the left does not.
          Correct.

          For a deeper insight, consider this additional terminology.

          A "candidate" swing high is easy to find, all we need to do is check the 5 bars to the left of the current bar and if they're all lower, poof, we found a "candidate".

          A "confirmed" swing high is the end product of the indicator, these confirmed swings are the only things that are plotted, In fact, only the most recent confirmed swing high and most recent confirmed swing low are plotted -- plotting of a confirmed swing ceases when it is penetrated or a new confirmed swing is identified.

          Consider, for ex, for the area labeled as "2", that low was never even a swing low candidate -- because the left side never met the definition,

          Originally posted by Boonfly8 View Post
          2. As for a swing high, labeled (3), if the big green up bar circled was lower than the (circled red) doji , then it would have a new lower swing high because the doji to the left satisfies the requirement but to the right is not satisfied due to the big green up bar.
          Correct. The big green up bar at "3" denies the previously circled Doji from becoming a swing high. If the big green up bar had been lower than the circled Doji, then yes, you are correct, that circled Doji would have been a Swing high -- and dots would be repainted back to the high of the circled Doji bar.

          [EDIT: Consider this important detail: Realize if you change the Strength to 4, the circled Doji bar would be labeled a Swing high. That's why I said the definition of a Swing high and Swing low is intimately tied to the Strength parameter. And we're not talking just a passing romance here, when I say intimate, I mean extremely dependent, we're talking super deep here, like Romeo and Juliet, or peanut butter and jelly. To wit, smaller values of Strength reveal a lot more Swings. You must understand Strength to understand Swing.]

          Originally posted by Boonfly8 View Post
          So for NT code, on a new bar, the code looks back the numbers of bars indicated by the strength, and also keeps track of number of bars + strength forward (from bars that has yet to happen), and plots the dots all at once (essentially a line) if a condition satisfies both left and right.
          Correct. After the Swing is confirmed, N dots are immediately plotted (my programmer mind says it this way: N-1 dots are "repainted", only 1 dot is "plotted"). After that, another dot is plotted at each bar close, until that swing is penetrated or a new swing is confirmed.

          Originally posted by Boonfly8 View Post
          P.S. on the OT attached pic, labeled (4) does not satisfy like you said but it looks like the low bar (1:52, chart is 2min) was equal to the center bar you are probably referring to.
          Good point. You have observed another phenomena that is also easily explained.

          "Equal to" does not count.

          A swing low means it is "lower than" -- not "lower than or equal to" -- it absolutely must be lower. Period. Full stop.

          A swing high is analogous. It is not "greater than or equal to" but absolutely must be "greater than".

          Consider the definition for a Swing, where we say N bars lower on the left and right of a Swing high, well, "equal to" is not in this definition. In fact, consider that any bars (inside the swing window of N bars) to the left of the swing high are never equal to the swing high itself, because, well, that just doesn't happen. Why? Because since that left equal bar came first, it would have been recognized as the swing high first. Ok, now also consider this: Within N bars after the swing high, any bar could be equal to the swing high, and it doesn't affect the swing high. Why? Because like I said, "equal to" doesn't count, it must be truly higher to penetrate the swing high, a mere touch of the swing high is not a penetration. Only penetration (or a new swing high is confirmed, even at a lower price) takes out the current swing high.

          Look at your area label "1a". The 2nd bar after the swing low is equal to the swing low itself. Well, what does this mean? It means nothing, because "equal to" does not count, so this bar does not start another swing, it is simply ignored, because it was not lower than the current swing low, so a "new" low it is not.
          Last edited by bltdavid; 05-13-2019, 01:05 AM.

          Comment


            #6
            Originally posted by Boonfly8 View Post
            Please confirm my thoughts, a lot of it is just thinking out loud!
            This post might also help share some light...





            -=Edge=-
            NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Waxavi, Today, 02:00 AM
            0 responses
            1 view
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            3 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Started by samish18, Yesterday, 08:31 AM
            2 responses
            9 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            391 views
            0 likes
            Last Post z.franck  
            Working...
            X