Skip to content

Instantly share code, notes, and snippets.

@jkintscher
Created December 14, 2017 03:52
Show Gist options
  • Select an option

  • Save jkintscher/e64891762c9f98c224a53e16c3b9414f to your computer and use it in GitHub Desktop.

Select an option

Save jkintscher/e64891762c9f98c224a53e16c3b9414f to your computer and use it in GitHub Desktop.
Log-space Ichimoku Indicator
// Just saved for posterity and as a backup. All credit goes to @fskrypt.
// Use right in Tradingview via https://www.tradingview.com/script/Vj0K8w14-Log-space-Ichimoku-Cloud/
//
//@version=3
study(title="Log Ichimoku Cloud", shorttitle="Log Ichimoku", overlay=true)
xlowest(src, len) =>
x = src
for i = 1 to len - 1
v = src[i]
if (na(v))
break
x := min(x, v)
x
xhighest(src, len) =>
x = src
for i = 1 to len - 1
v = src[i]
if (na(v))
break
x := max(x, v)
x
drop1st(src) =>
x = na
x := na(src[1]) ? na : src
conversionPeriods = input(9, minval=1, title="Conversion Line Periods"),
basePeriods = input(26, minval=1, title="Base Line Periods")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods"),
displacement = input(26, minval=1, title="Displacement")
showLagging = input(false, "Show Lagging Span")
loglows = log(drop1st(low))
loghighs = log(drop1st(high))
donchian(len) =>
avg(xlowest(loglows, len), xhighest(loghighs, len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(exp(conversionLine), color=#0496ff, title="Conversion Line")
plot(exp(baseLine), color=#991515, title="Base Line")
plot(showLagging ? close : na, offset = -displacement, color=#459915, title="Lagging Span")
p1 = plot(exp(leadLine1), offset = displacement, color=green, title="Lead 1")
p2 = plot(exp(leadLine2), offset = displacement, color=red, title="Lead 2")
fill(p1, p2, color = leadLine1 > leadLine2 ? green : red)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment