Skip to content

Instantly share code, notes, and snippets.

@sherwind
Last active December 6, 2022 06:41
Show Gist options
  • Save sherwind/42e2313a5d0a3685f0d24cf8dc4734fa to your computer and use it in GitHub Desktop.
Save sherwind/42e2313a5d0a3685f0d24cf8dc4734fa to your computer and use it in GitHub Desktop.
ZigZag HiLo
//@version=3
//
// Based on http://traders.com/documentation/feedbk_docs/2013/07/traderstips.html
//
//
// -----------------------------------------------------------------------------
// Copyright 2018 sherwind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License can be found here
// <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//
study("ZigZag HiLo", overlay=true)
ZZPercent = input(0.5, title="Minimum % Change", type=float)
trend = 0
trend := na(trend[1]) ? 1 : trend[1]
LL = 0.0
LL := na(LL[1]) ? low : LL[1]
HH = 0.0
HH := na(HH[1]) ? high : HH[1]
PivotChg = ZZPercent * 0.01
zigzag = na
if (trend > 0) // trend is up, look for new swing low
if (high >= HH) // new higher high detected
HH := high
else
if (low < HH * (1 - PivotChg))
zigzag := high[1]
trend := -1
LL := low
else // trend is down, look for new swing high
if (low <= LL) // new lower low detected
LL := low
else
if (high > LL * (1 + PivotChg))
zigzag := low[1]
trend := 1
HH := high
plot(zigzag, linewidth=2, offset=-1)
@Hanhan1989
Copy link

thanks , but , I get this error:

Processing script...
line 40: mismatched input 'HH' expecting 'end of line without line continuation'

can you solve it? Thanks

@sherwind
Copy link
Author

sherwind commented Jun 18, 2019 via email

@merolaika
Copy link

Hello sir, how we can add this pine code to timeframe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment