bsharpe

Peaks&Valleys

182 1 13
For Peaks:
marks bars whose high is higher than <input> bars on either side

For Valleys:
marks bars whose low is lower than <input> bars on either side

<input> defaults to 13
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study(title="Peaks&Valleys",shorttitle="P&V", overlay = true)
width = input(13)
p = 0
v = 0
for i = 0 to (width * 2)
    p := p + ((i == width) ? 0 : (high[i] < high[width] ? 1 : 0))
    v := v + ((i == width) ? 0 : (low[i] > low[width] ? 1 : 0))
plotshape((p == (width * 2)), offset = -width, style = shape.labeldown)
plotshape((v == (width * 2)), offset = -width, style = shape.labelup, location = location.belowbar )
Seal PRO
6 months ago
very interesting-does this study repaint? thanks
+2 Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out