Announcement

Collapse
No announcement yet.

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:

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    77 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 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