by mexican » Sun Oct 16, 2022 11:58 pm
Wanting a pine indicator converted to Mt4 please if possible.
- Code: Select all
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
//@version=5
indicator('Zigzag Cloud', shorttitle='ZigZag Cloud', overlay=true, max_bars_back=500, max_lines_count=500, max_labels_count=500)
MALength = input.int(20, step=20)
Mult = input.float(2, step=0.5)
showZigZag = input(false)
zigzagLength = input.int(5, step=5, minval=2)
zigzagColor = input(color.teal)
zigzagWidth = 1
zigzagStyle = line.style_solid
cloudTransparency = input.int(90, step=5, maxval=100, minval=0)
max_array_size = MALength + 10
var zigzagpivots = array.new_float(0)
var zigzagpivotbars = array.new_int(0)
var zigzagpivotdirs = array.new_int(0)
var zigzaglines = array.new_line(0)
pivots(length) =>
float phigh = ta.highestbars(high, length) == 0 ? high : na
float plow = ta.lowestbars(low, length) == 0 ? low : na
dir = 0
iff_1 = plow and na(phigh) ? -1 : dir[1]
dir := phigh and na(plow) ? 1 : iff_1
[dir, phigh, plow, bar_index, bar_index]
zigzagcore(dir, phigh, plow, phighbar, plowbar, zigzagpivots, zigzagpivotbars, zigzagpivotdirs) =>
dirchanged = ta.change(dir)
newZG = false
if phigh or plow
value = dir == 1 ? phigh : plow
bar = phigh ? phighbar : plowbar
newDir = dir
if not dirchanged and array.size(zigzagpivots) >= 1
pivot = array.shift(zigzagpivots)
pivotbar = array.shift(zigzagpivotbars)
pivotdir = array.shift(zigzagpivotdirs)
useNewValues = value * pivotdir < pivot * pivotdir
value := useNewValues ? pivot : value
bar := useNewValues ? pivotbar : bar
bar
if array.size(zigzagpivots) >= 2
LastPoint = array.get(zigzagpivots, 1)
newDir := dir * value > dir * LastPoint ? dir * 2 : dir
newDir
array.unshift(zigzagpivots, value=value)
array.unshift(zigzagpivotbars, bar)
array.unshift(zigzagpivotdirs, newDir)
newZG := true
if array.size(zigzagpivots) > max_array_size
array.pop(zigzagpivots)
array.pop(zigzagpivotbars)
array.pop(zigzagpivotdirs)
newZG
zigzag(length, zigzagpivots, zigzagpivotbars, zigzagpivotdirs) =>
[dir, phigh, plow, phighbar, plowbar] = pivots(length)
zigzagcore(dir, phigh, plow, phighbar, plowbar, zigzagpivots, zigzagpivotbars, zigzagpivotdirs)
draw_zigzag(zigzaglines, zigzagpivots, zigzagpivotbars, zigzagcolor, zigzagwidth, zigzagstyle, showZigZag) =>
if array.size(zigzagpivots) >= 2 and showZigZag
y1 = array.get(zigzagpivots, 0)
y2 = array.get(zigzagpivots, 1)
x1 = array.get(zigzagpivotbars, 0)
x2 = array.get(zigzagpivotbars, 1)
zline = line.new(x1=x1, y1=y1, x2=x2, y2=y2, color=zigzagcolor, width=zigzagwidth, style=zigzagstyle)
if array.size(zigzaglines) >= 1
lastLine = array.get(zigzaglines, 0)
if x2 == line.get_x2(lastLine) and y2 == line.get_y2(lastLine)
line.delete(lastLine)
array.unshift(zigzaglines, zline)
std_dev(zigzagpivots, ma, Length) =>
devsq = 0.0
if Length != 0
for i = 0 to Length - 1 by 1
pivot = array.get(zigzagpivots, i)
devsq := devsq + (pivot - ma) * (pivot - ma)
devsq
math.sqrt(devsq / Length)
get_zigzag_ma(zigzagpivots, zigzagpivotdirs, MALength) =>
Length = math.min(MALength, array.size(zigzagpivots))
maHigh = 0.0
maLow = 0.0
ma = 0.0
if Length != 0
for i = 0 to Length - 1 by 1
pivot = array.get(zigzagpivots, i)
dir = array.get(zigzagpivotdirs, i)
ma := ma + pivot
maHigh := maHigh + (dir > 0 ? pivot : 0)
maLow := maLow + (dir < 0 ? pivot : 0)
maLow
maHigh := maHigh * 2 / Length
maLow := maLow * 2 / Length
ma := ma / Length
stddev = std_dev(zigzagpivots, ma, Length)
[ma, maHigh, maLow, stddev]
ZG = zigzag(zigzagLength, zigzagpivots, zigzagpivotbars, zigzagpivotdirs)
if ZG
draw_zigzag(zigzaglines, zigzagpivots, zigzagpivotbars, zigzagColor, zigzagWidth, zigzagStyle, showZigZag)
[ma, maHigh, maLow, stddev] = get_zigzag_ma(zigzagpivots, zigzagpivotdirs, MALength)
MA = plot(ma, title='ZigzagMA', color=color.new(color.blue, cloudTransparency))
HighMA = plot(maHigh, title='ZigzagHighMA', color=color.new(color.lime, cloudTransparency))
BBUMa = plot(ma + stddev * Mult, title='BBUpperMa', color=color.new(color.green, cloudTransparency))
BBUHigh = plot(maHigh + stddev * Mult, title='BBUpperHighMa', color=color.new(color.teal, cloudTransparency))
LowMA = plot(maLow, title='ZigzagLowMA', color=color.new(color.orange, cloudTransparency))
BBLMa = plot(ma - stddev * Mult, title='BBLowerMa', color=color.new(color.red, cloudTransparency))
BBLLow = plot(maLow - stddev * Mult, title='BBLowerLowMa', color=color.new(color.maroon, cloudTransparency))
fill(MA, HighMA, title='UpperRange1', color=color.new(color.lime, cloudTransparency))
fill(HighMA, BBUMa, title='UpperRange2', color=color.new(color.green, cloudTransparency))
fill(BBUMa, BBUHigh, title='UpperRange3', color=color.new(color.teal, cloudTransparency))
fill(MA, LowMA, title='LowerRange1', color=color.new(color.orange, cloudTransparency))
fill(LowMA, BBLMa, title='LowerRange2', color=color.new(color.red, cloudTransparency))
fill(BBLMa, BBLLow, title='LowerRange3', color=color.new(color.maroon, cloudTransparency))