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

Get bar number of prior swing lows/highs

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

    Get bar number of prior swing lows/highs

    Hey guys -

    A simple question.. how can I get the bar number of prior swing lows/highs (i.e. most current and the one before that one)?

    Thanks!

    #2
    Hello PN720,

    Thanks for your post.

    The help guide for the swing indicator shows a method overload of:
    Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)

    In the case of the parameter "instance," you would set 1 for the latest occurrence and then 2 for the one before that, etc.

    Swing().SwingHighBar() returns the "bars ago" value, so to get the bar number you would use something like:

    int myBarNumber = CurrentBar[0] - (Swing(5).SwingHighBar(0, 1, 10); // 10 bar lookback

    Also, when working with Swing you have to account for the possibility that there was no prior swing in the lookback period in which case Swing returns a -1;

    Keep in mind as well that a swing is not confirmed until the strength parameter for bars is met, so if using 5, the swing high at best would have been 5 bars ago. As you develop your script you will want to use print statements to help you see what swing is working with.

    References:

    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by FishTrade, Yesterday, 11:11 PM
    3 responses
    11 views
    0 likes
    Last Post FishTrade  
    Started by Graci117, Today, 09:02 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by ETFVoyageur, Today, 07:55 PM
    0 responses
    8 views
    0 likes
    Last Post ETFVoyageur  
    Started by janio973, Today, 07:24 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by aligator, 01-06-2022, 12:14 PM
    4 responses
    248 views
    0 likes
    Last Post john_44573  
    Working...
    X