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, 05-11-2026, 05:56 AM
    0 responses
    52 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    194 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    355 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    274 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X