Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sidlercom80, 10-28-2023, 08:49 AM
    171 responses
    2,276 views
    0 likes
    Last Post QuantKey_Bruce  
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    17 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post adeelshahzad  
    Started by CortexZenUSA, Today, 12:53 AM
    0 responses
    3 views
    0 likes
    Last Post CortexZenUSA  
    Started by CortexZenUSA, Today, 12:46 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Working...
    X