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

Detect when New Swing Occur with Swing Indicator

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

    Detect when New Swing Occur with Swing Indicator

    Hi, I'm using the Swing Indicator for my strategy, is there a way to detect when a new swing just formed which represents the line drawing. Did not get the line until the 5th bar here. My question is, how do I detect that the line just got drawn?


    #2
    Hello thaison316,

    Thanks for the post.

    The swing indicator is not set up to be used as a signal directly. This is due to how the logic works to re-write the plot value as new swings are located.

    For this to be used as a signal would require that you implement the existing swing logic in your strategy, based on how that works it could submit orders when a new swing is calculated instead of rewriting the plot data. From the strategy calling an indicator standpoint the re-written plot data would not be helpful at being a signal because the strategy wont see the current value being a swing at the time OnBarUpdate is called.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      The problem is the Swing indicator only documents confirmed swings.

      With Strength=5 that means we need 5 bars on both sides of a swing high
      to have lower highs -- well, rats ...

      ... that means we need 5 bars to actually close after the swing high in order
      to confirm the swing high candidate, was, in fact, a swing high.

      Ah, you want to know about swing candidates?

      That's what I call potential swing highs where the left half has been
      confirmed (left 5 bars have lower highs) and now we're waiting for 5
      more bars to close -- well, rats ...

      We don't know how the next 5 bars will close. Any one of them could
      close higher and invalidate the swing candidate we thought we found.

      So, you could certainly code a function to find half a swing (by looking
      at 'x' bars to the left) because the left side is easy to confirm, but in
      order to act on the candidate swing high before 5 next bars on the
      right have closed, you need a completely new algorithm, which
      require you to think in terms of the "left side strength" vs "right side
      strength".

      The "left strength" is simply the same Strength as you supply to the
      Swing indicator. This is the number of bars that must all have lower
      Highs (for a swing high) or all higher Lows (for a swing low) on the
      left side
      of our swing candidate.

      The "right strength" is the special part -- this is the number of confirmation
      bars that we require (minimum should be 1) that show us this candidate is
      soon going to become a confirmed swing (we hope).

      Think carefully -- RightStrength should always be < LeftStrength.

      If RightStrength == LeftStrength, well, heck, that's just the Swing indicator
      confirming 5 bars on left and 5 bars on right.

      You want to know earlier than that. You want to know when 5 bars on left
      but just 1 bar on right, or 2 bars on right, or 3 bars, etc -- so this partial
      situation of an almost confirmed swing is why I say "swing candidate".

      A function like,

      Code:
      private bool IsSwingHighCandidate(IDataSeries ds, int LeftStength, RightStrength)
      {
      ....
      }
      which you call like,

      Code:
      if (IsSwingHighCandidate(High, 5, 1))
          Print("Found Swing(5) candidate for SwingHigh 1 bars ago");
      
      if (IsSwingHighCandidate(High, 5, 2))
          Print("Found Swing(5) candidate for SwingHigh 2 bars ago");
      Is this what you're after?

      PS:
      Good reading here.
      Last edited by bltdavid; 03-18-2021, 12:18 PM.

      Comment


        #4
        Thank you, not what I was looking for but reading your post made it clearer what I can and need to do.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,607 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        16 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X