Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Highest or lowest swings

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

    Highest or lowest swings

    I am trying to write a code that will able to find the lowest of the last X swing lows and the highest of the X swing lows by using the Swing indicator in Ninjatrader.

    This is how I did it

    MIN(Swing(BarsArray[1], 1).SwingLow, X)[0];

    MAX(Swing(BarsArray[1], 1).SwingHigh, X)[0];

    For some reason it does seem to be working. My impression is these functions find the highest swing high of the the last X days and not the highest of the last X swing highs (which may be useful too but it is not what I am looking for).

    Can anybody help please?

    #2
    luitom, I would unfortunately not have a code snippet here handy for this use, but your understanding is correct, the MIN / MAX methods would lookback for the amount bars (X) specified and would not use the last x swing highs and lows, it would just use this data as it's input series but the lookback is still specified in bars. One way would be custom tracking the last x instances of Swing Highs and Swing Lows seen in a list / queue and then looping through this to find the values desired.

    Comment


      #3
      Originally posted by luitom View Post
      I am trying to write a code that will able to find the lowest of the last X swing lows and the highest of the X swing lows by using the Swing indicator in Ninjatrader.

      This is how I did it

      MIN(Swing(BarsArray[1], 1).SwingLow, X)[0];

      MAX(Swing(BarsArray[1], 1).SwingHigh, X)[0];

      For some reason it does seem to be working. My impression is these functions find the highest swing high of the the last X days and not the highest of the last X swing highs (which may be useful too but it is not what I am looking for).

      Can anybody help please?
      1. Put the SwingHigh in an ArrayList as they occur. Do the same for the Swing Lows. Populate them to the number of Swings that you are looking for.
      2. Copy the ArrayLists, then sort them to get the lowest and highest as you wish. (Or you can always create a new ArrayList directly as the output of the sort on the original list, which is effectively the same thing. It is just a matter of style preference).

      Comment


        #4
        Arrays

        Thanks for the advice. Unfortunately, creating arrays goes beyond my programming skills. I would have no idea how to go about it. Do I need to create a IDataSeries object?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        657 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        373 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X