Skip to content

Instantly share code, notes, and snippets.

@badjano
Last active October 22, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badjano/3a56c5a8bc95e5f1755e6cda1c39794a to your computer and use it in GitHub Desktop.
Save badjano/3a56c5a8bc95e5f1755e6cda1c39794a to your computer and use it in GitHub Desktop.
//@version=4
study("Fibonacci MA rainbow", overlay=true)
period = input(title="MA period", type=input.integer, defval=100)
scale = input(title="Period Scale", type=input.integer, defval=1)
power = input(title="Fibonacci Scale", type=input.float, defval=1, step=0.1)
offset = input(title="Fibonacci Offset", type=input.float, defval=0, step=0.1)
smoothing = input(defval="WMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "LSMA"])
almaOffset = input(defval=0.85, minval=0, type=input.float, step=0.05)
almaSigma = input(defval=6, minval=0, type=input.float, step=0.5)
qma(smoothing, src, length) =>
if smoothing == "RMA"
rma(src, length)
else
if smoothing == "SMA"
sma(src, length)
else
if smoothing == "EMA"
ema(src, length)
else
if smoothing == "WMA"
wma(src, length)
else
if smoothing == "VWMA"
vwma(src, length)
else
if smoothing == "SMMA"
na(src[1]) ? sma(src, length) : (src[1] * (length - 1) + src) / length
else
if smoothing == "HullMA"
wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))
else
if smoothing == "LSMA"
alma(src, length, almaOffset, almaSigma)
else
src
chartResolution = timeframe.multiplier
if timeframe.isdaily
chartResolution := 24*60*timeframe.multiplier
if timeframe.isweekly
chartResolution := 24*60*7*timeframe.multiplier
if timeframe.ismonthly
chartResolution := 24*60*30*timeframe.multiplier
s = power*pow(chartResolution/(24*60),0.5)
float a = pow(0.5, s)
float b = pow(0.618, s)
float c = pow(0.786, s)
ma = qma(smoothing, close, period * scale) * (1+offset)
ma1 = ma*a
ma2 = ma*b
ma3 = ma*c
ma4 = ma
ma5 = ma/c
ma6 = ma/b
ma7 = ma/a
pl1 = plot(ma1, title="MA 1", color=color.fuchsia, linewidth=2)
pl2 = plot(ma2, title="MA 2", color=color.blue, linewidth=2)
pl3 = plot(ma3, title="MA 3", color=color.aqua, linewidth=2)
pl4 = plot(ma4, title="MA 4", color=color.lime, linewidth=2)
pl5 = plot(ma5, title="MA 5", color=color.yellow, linewidth=2)
pl6 = plot(ma6, title="MA 6", color=color.orange, linewidth=2)
pl7 = plot(ma7, title="MA 7", color=color.red, linewidth=2)
fill(pl1, pl2, color=color.fuchsia)
fill(pl2, pl3, color=color.blue)
fill(pl3, pl4, color=color.aqua)
fill(pl4, pl5, color=color.yellow)
fill(pl5, pl6, color=color.orange)
fill(pl6, pl7, color=color.red)
plotshape(crossover(high, ma7), title= "Overbought", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
plotshape(crossover(high, ma6), title= "Overbought", location=location.abovebar, color=color.orange, style=shape.triangledown, size=size.small)
plotshape(crossover(high, ma5), title= "Overbought", location=location.abovebar, color=color.yellow, style=shape.triangledown, size=size.small)
plotshape(crossunder(low, ma3), title= "Overbought", location=location.belowbar, color=color.aqua, style=shape.triangleup, size=size.small)
plotshape(crossunder(low, ma2), title= "Overbought", location=location.belowbar, color=color.blue, style=shape.triangleup, size=size.small)
plotshape(crossunder(low, ma1), title= "Overbought", location=location.belowbar, color=color.fuchsia, style=shape.triangleup, size=size.small)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment