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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X