Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Last Swing Low Value

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

    Getting Last Swing Low Value

    Hi, I'm working on a strategy that uses swing values and the correct swing high value prints which was taken from https://ninjatrader.com/support/help...html?swing.htm however when converted to the swing low value it's different for just about every bar.

    Swing high - swinghigh0 = High[Math.Max(0, Swing1.SwingHighBar(0,1,100))];
    Swing Low - swinglow0 = Low[Math.Min(0, Swing1.SwingLowBar(0,1,100))];

    You can see from the picture that the swing low value appears to be constantly changing and I'm not sure what's wrong as the swing high values match the chart.
    Attached Files

    #2
    Hello itsthefriz,

    Thanks for your post.

    You need to change Math.Min to Math.Max in this line: Swing Low - swinglow0 = Low[Math.Min(0, Swing1.SwingLowBar(0,1,100))];

    What is happening is that Math.Min is choosing the Minimum of 0 or the bars ago, or if no swing found it would return a -1. A -1 would lead to a bar index error.

    Math.Max is used to return either 0 or the bars ago but would not let the -1 pass through and this would prevent an index error, so the correct usage here is:
    Swing Low - swinglow0 = Low[Math.Max(0, Swing1.SwingLowBar(0,1,100))];

    Comment


      #3
      Ah, okay, I think I've got it... Math.Min is constantly returning the 0 bar because it is minimum bar of the given index rather than the last swing value which is found using Math.Max which returns the number of bars ago the swing occurred, if that's right?

      Comment


        #4
        Hello itsthefriz,

        Thanks for your reply.

        Correct, except that could return -1 because the swing indicator will return -1 if no swing is found and in that case, you would generate a bar index error and your script would stop.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X