Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Swing Lows/Highs in an array

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

    Swing Lows/Highs in an array

    Hey guys,

    I'm not sure how to do this so I'm seeking your help. I want to store the session Swing Lows and Highs in separate arrays as they are created during the session. On each bar update, I want to search that array to find Max, median or min swings and do something. Can you provide the basic syntax?

    Thanks!

    #2
    Hello PN720,

    Thanks for your post.

    Arrays are not a ninjascript item so we recommend searching the internet for assistance with arrays. You may want to consider using List<> which provide the benefit of not needing to be size defined. Here is a good site for both Arrays and Lists: https://www.dotnetperls.com/

    Another approach to consider would be creating a custom series. The advantage of this is that it will create a "slot" for every bar of the charts data series and you can save the swing value when it changes as well as use other ninjascript methods such as MAX(), MIN() and bars ago. Reference: https://ninjatrader.com/support/help...s/?seriest.htm

    In terms of Swing, it will return a -1 until the first swing is found and then would return the SwingHigh or SwingLow depending on the method overload you are using. You can compare from one bar to the next if the returned swing High is greater (or lower) than the previous bar (perhaps Not Equal may work here) and this would indicate that the swingHigh has changed allowing you to save the value.

    Keep in mind that the location (bars ago) of the swing high will be the strength number of bars back from where the indicator returns the new swing value in case you need to also save when the swing occurred.
    Reference: https://ninjatrader.com/support/help...-us/?swing.htm

    You can use Bars.IsFirstBarOfSession as the beginning point for your processing. reference: https://ninjatrader.com/support/help...rofsession.htm

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X