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

Swing Strategy Builder Indicator

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

    Swing Strategy Builder Indicator

    Hello, I downloaded ninjatrader few weeks ago and I was testing the Swing indicator but I couldn't get the result I want.

    What I want to do is to take a long position when the swing low dots symbol appears the quickest and the same thing when the swing high become visible.

    I couldn't find any relevant info on the forum, so I decided to create this new topic.

    I'm only using the strategy build so I have zero skills at reading and writing C#, so I would like to have a layman answer please. I dont understand how the Swing indicator work.

    Thanks!

    #2
    Before you get too far you should think about the definition of what a "swing" is and how it is identified.

    The stock Swing indicator only deals with the concept of "confirmed" swings.

    What is a "confirmed" swing high or swing low?
    Well, that's what the "Strength" parameter is for.

    Let's consider swing highs ...

    The idea is the "Strength" parameter tells you how many bars before the swing high and how many
    bars after the swing high must all be lower than the swing high itself.

    For ex, using a Strength of 5 means: 5 bars on the left and 5 bars on the right must all be lower than
    the bar designated as a "swing high".

    Internally, the Swing indicator maintains a "sliding window" of High values of the last 11 bars, and the
    middle bar in this window must be the highest High of all 11 bars -- and only then does the indicator
    know it has found a "confirmed swing high". Why 11 bars? Well, that's determined by the Strength,
    the size of the window is calculated as (Strength * 2) + 1.

    [EDIT: For swing highs, saying 'all lower' is a critical detail. Why? Consider two adjacent bars
    with exactly equal High values -- neither one of these bars can ever be considered a swing high.
    The reason is simple: neither of these twin High bars qualify under the "5 bars on left & right are
    all lower" rule. Think carefully, this is critical -- all bars must be lower, equal bars don't qualify.
    So, no matter how visually strong an area on the chart looks like it should have a swing high, two
    adjacent equal High bars does not meet the criteria of the Swing indicator logic. This understanding
    is very subtle: the Swing algorithm is not designed to 'share', there can only be one 'king' within any
    11 bar window. Remember algebra? The algorithm is using the '<' operator for those 10 bars
    surrounding the swing high, not the '<=' operator.]

    Unfortunately, the Swing indicator is only able to tell you it found a confirmed swing high 5 bars after
    a swing high has actually happened. Why is that? Well, how else do you know you have a "confirmed
    swing high" until the following 5 bars all close with lower highs?

    The Swing indicator must wait for those 5 following bars to close.

    Only after the swing high is confirmed does the indicator start painting the dots for that swing high.

    Watch the chart carefully and you'll notice the indicator "fudge" the visual chart history. How so?
    After the swing high is confirmed (on the close of the 5th bar after where the swing high happened)
    the indicator paints all 5 dots for the last 5 bars all at once -- this is a general coding technique
    commonly known as "repainting".

    Indicators that "repaint" over past historical bars are generally frowned upon because, well, by definition,
    the technique alters the visual history of the chart. But some technical indicators require repainting,
    otherwise their algorithms simply would not work -- the stock Swing indicator is one of those indicators.

    The problem is -- when using an indicator that repaints inside a strategy, such as the Swing indicator,
    you are relying upon a piece of information that actually happened 'x' bars ago -- in the case of the
    Swing indicator, the value 'x' is the Strength parameter.

    So, now, knowing all that, you can better judge the effectiveness of using the Swing indicator to
    take positions in an automated strategy 'x' number of bars after the swing high/low is confirmed.

    PS:
    Is using Swing in an automated strategy a bad thing?
    Answer: No, not at all, but it really depends on the strategy.
    Moral of the story: Be aware of the limitations of the Swing indicator.
    Last edited by bltdavid; 05-18-2020, 01:28 PM. Reason: Updated section that explains huge impact of algorithm choice of '<' vs '<=' operator.

    Comment


      #3
      Hi bltdavid,
      A wonderful post. I'd like to see it pinned longterm for the benefit of the more junior community.
      NT-Roland

      Comment


        #4
        Thanks, glad you enjoyed it!

        Hit that 'Thumbs Up' button a few times, let's get it to a million!

        Lol, I know that will never happen -- this ain't YouTube.

        Comment


          #5
          Thanks bltdavid it was well describe! Now I understand how this indicator work but could you give us a example of a strategy that would use a swing indicator? I would also like to know if the dot line created are purely visual or can I use them to trigger something when like a EMA cross those dots?

          Comment


            #6
            Hi hellzer, thanks for your questions. Thanks also to bltdavid for your detailed explination.

            I made this script in the past that singles out where exactly a swing level is:


            This will help identify where new swing lows/highs are created. Also make sure to fully utilize the Swing methods documented in our help guide:



            Please let me know if I can assist any further.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thanks ChrisL,
              it's more clear now on the chart. I would still love to see an example on how to use swing for a trade.

              Comment


                #8
                Originally posted by bltdavid View Post
                Before you get too far you should think about the definition of what a "swing" is and how it is identified.

                The stock Swing indicator only deals with the concept of "confirmed" swings.

                What is a "confirmed" swing high or swing low?
                Well, that's what the "Strength" parameter is for.

                Let's consider swing highs ...

                The idea is the "Strength" parameter tells you how many bars before the swing high and how many
                bars after the swing high must all be lower than the swing high itself.

                For ex, using a Strength of 5 means: 5 bars on left and 5 bars on the right must all be lower than
                the bar designated as a "swing high".

                Internally, the Swing indicator maintains a "sliding window" of high values of the last 11 bars, and the
                middle bar in this window must be the highest high of all 11 bars -- and only then does the indicator
                know it has found a "confirmed swing high". Why 11 bars? Well, that's determined by the Strength,
                the size of the window is calculated as (Strength * 2) + 1.

                Unfortunately, the Swing indicator is only able to tell you it found a confirmed swing high 5 bars after
                a swing high has happened. Why is that? Well, how else do you know you have a "confirmed swing
                high" until the following 5 bars all close with lower highs?

                The Swing indicator must wait for those 5 following bars to close.

                Only after the swing high is confirmed does the indicator start painting the dots for that swing high.

                Watch the chart carefully and you'll notice the indicator "fudge" the visual chart history. How so?
                After the swing high is confirmed (on the close of the 5th bar after where the swing high happened)
                the indicator paints all 5 dots for the last 5 bars all at once -- this is a general coding technique
                commonly known as "repainting".

                Indicators that "repaint" over past historical bars are generally frowned upon because, well, by definition,
                the technique alters the visual history of the chart. But some technical indicators require repainting,
                otherwise their algorithms simply would not work -- the stock Swing indicator is one of those indicators.

                The problem is -- when using an indicator that repaints inside a strategy, such as the Swing indicator,
                you are relying upon a piece of information that actually happened 'x' bars ago -- in the case of the
                Swing indicator, the value 'x' is the Strength parameter. kohi click test

                So, now, knowing all that, you can better judge the effectiveness of using the Swing indicator to
                take positions in an automated strategy 'x' number of bars after the swing high/low is confirmed.

                PS:
                Is using Swing in an automated strategy a bad thing?
                Answer: No, not at all, but it really depends on the strategy.
                Moral of the story: Be aware of the limitations of the Swing indicator.
                Thank you for the post!
                Last edited by KarenGates; 05-16-2020, 09:49 AM.

                Comment


                  #9
                  You're welcome! I'm glad you found it helpful.

                  I just edited that post to explain the critical implications of what it means to say "all lower than".

                  What's the importance of this edit?
                  An expert understanding emerges when you can visually 'see' the differences on a chart due to
                  the logic rule "all lower than" vs "all lower than or equal to". The edit works hard to surface this
                  subtle distinction, because of the critical role it plays in developing your deeper knowledge.

                  Deeper how?
                  The omission of the "equal to" logic can have a huge impact on your charts -- you may even
                  find disappointment in why Swing does not mark certain areas with a swing high or swing low.

                  That is, when you see an area of bars on the chart that 'visually' suggest a swing high, but
                  the Swing indicator does not plot a swing high there, it may mean two or more bars had the
                  exact same High value (within the same sliding window), effectively defeating the Swing
                  algorithm's "all lower than" logic.

                  [EDIT: It may also mean Strength is too large, allowing visually strong areas of highs and
                  lows to slip past the algorithm undetected.]

                  As you can probably surmise, tightly confined precise double tops and precise double
                  bottoms can wreck havoc on the Swing algorithm.

                  Thus, a corollary to the moral of the story is: Remember, "equal to" doesn't count.

                  In light of this new EDIT section, please consider reading it again!

                  (And please click that 'Thumbs up' button! We still gotta get to a million! )
                  Last edited by bltdavid; 05-17-2020, 08:53 AM. Reason: Add comment about Strength being too large

                  Comment


                    #10
                    Some additional detail was added here.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by AaronKoRn, Today, 09:49 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post AaronKoRn  
                    Started by carnitron, Today, 08:42 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post carnitron  
                    Started by strategist007, Today, 07:51 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post strategist007  
                    Started by StockTrader88, 03-06-2021, 08:58 AM
                    44 responses
                    3,976 views
                    3 likes
                    Last Post jhudas88  
                    Started by rbeckmann05, Today, 06:48 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post rbeckmann05  
                    Working...
                    X