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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        60 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X