Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Weird Swing indicator behaviour?

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

    Weird Swing indicator behaviour?

    Hi NinjaTrader folks,

    I am a little puzzled with the results I got today coding a trading filter using the Swing indicator. This is the very simple code (now it only prints, since I tested so many things):

    Code:
    const int STRENGTH = 20;
    const int LOOPBACKBARS = 500;
    int swingBarAgo = 0;
    
    var loopbackBars = CurrentBar > LOOPBACKBARS ? LOOPBACKBARS : CurrentBar - 1;
    
    int n = 0;
    
    do
    {
    n++;
    swingBarAgo = Swing(STRENGTH).SwingHighBar(0, n, loopbackBars);
    
    if (swingBarAgo != -1)
    {
    Print(this, "OrderGenerator.FilterIfSwingUnviolated :: " + n + ": Swing at Bar " + (CurrentBar - swingBarAgo) + ". Price: " + High[swingBarAgo]);
    
        }
    } while (swingBarAgo != -1);
    It only gets right the first few (2,3 4) instances of swingHigh, from that point onwards all the swingHigh (bars) are wrong - not even close to what the chart Swing Indicator (same period/strength) shows.

    In this log example:
    Code:
    TradeSize: 27. Current StopLoss (ticks): 72.9607085548763
    In Substate SignalFound :: Condition evaluated :TradeConditionsMet
    OrderGenerator.FilterIfSwingUnviolated :: 1: Swing at Bar 10533. Price: 4584.75
    OrderGenerator.FilterIfSwingUnviolated :: 2: Swing at Bar 10495. Price: 4586
    OrderGenerator.FilterIfSwingUnviolated :: 3: Swing at Bar 10461. Price: 4589
    OrderGenerator.FilterIfSwingUnviolated :: 4: Swing at Bar 10424. Price: 4594.25
    OrderGenerator.FilterIfSwingUnviolated :: 5: Swing at Bar 10277. Price: 4559
    OrderGenerator.FilterIfSwingUnviolated :: 6: Swing at Bar 10239. Price: 4551.25
    OrderGenerator.FilterIfSwingUnviolated :: 7: Swing at Bar 10205. Price: 4548.5
    OrderGenerator.FilterIfSwingUnviolated :: 8: Swing at Bar 10168. Price: 4542.25
    ...
    It gets right till #4, from there onwards the rest are all wrong (bar numbers don't coincide with what I see in the screen).

    Am I using the indicator wrong, any declaration missing? Has something changed in this indicator or its code recently? I used it in the past with no issues.

    Thanks so much.

    #2
    Hi, thanks for posting.

    Please try just using Print(); on the Swing value and ignore this do while look you are using and draw a dot on each swing high and low. I also created this single dot swing indicator that only shows where the swing value originates:


    Kind regards,
    -ChrisL

    Comment


      #3
      Thanks for that ChrisL; your comment and your code made me realize a couple of mistakes I was making; and I also added the " MaximumBarsLookBack = MaximumBarsLookBack.Infinite;" statement in State.SetDefaults. Now it all works well.

      Cheers!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      65 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      41 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      23 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      26 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      52 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X