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
    Chris L.NinjaTrader Customer Service

    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 alifarahani, Today, 09:40 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by RookieTrader, Today, 09:37 AM
      4 responses
      17 views
      0 likes
      Last Post RookieTrader  
      Started by PaulMohn, Today, 12:36 PM
      0 responses
      2 views
      0 likes
      Last Post PaulMohn  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      38 views
      0 likes
      Last Post love2code2trade  
      Started by junkone, Today, 11:37 AM
      3 responses
      22 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X