PHP Code:
//@version=6
// Copyright (c) 2020-present, Alex Orekhov (everget)
// Vortex Bands script may be freely distributed under the terms of the GPL-3.0 license.
indicator('Vortex Bands', shorttitle = '..', overlay = true, max_bars_back=5000)
length = input(title = 'Length', defval = 14)
mult = input.float(title = 'Multiplier', step = 0.1, defval = 2)
src = input(title = 'Source', defval = hlc3)
barColoringType = input.string(title = 'Bar Coloring', defval = 'Upper > Lower', options = ['None', 'Upper > Lower', 'Close Above/Below Basis', 'Close Inside Cloud', 'Wicks Inside Cloud'])
_ema(src, alpha) =>
out = src
out := alpha * out + (1 - alpha) * nz(out[1], out)
out
_mnma(src, length) =>
alpha = 2 / (length + 1)
ema1 = _ema(src, alpha)
ema2 = _ema(ema1, alpha)
out = ((2 - alpha) * ema1 - ema2) / (1 - alpha)
out
basis = _mnma(src, length)
dev = mult * _mnma(src - basis, length)
upper = basis + dev
lower = basis - dev
plot(basis, title = 'V', color = color.new(color.maroon, 0))
upperBandPlot = plot(upper, title = 'V+', linewidth = 2, color = color.new(color.white, 0))
lowerBandPlot = plot(lower, title = 'V-', linewidth = 2, color = color.new(color.yellow, 0))
//fill(upperBandPlot, lowerBandPlot, title = 'Background', color = color.new(color.fuchsia, 0))
barColor = barColoringType == 'Upper > Lower' ? upper > lower ? color.lime : color.red : barColoringType == 'Close Above/Below Basis' ? close > basis ? color.lime : color.red : barColoringType == 'Close Inside Cloud' ? math.min(upper, lower) < close and close < math.max(upper, lower) ? color.lime : color.red : barColoringType == 'Wicks Inside Cloud' ? math.min(upper, lower) < low and high < math.max(upper, lower) ? color.lime : color.red : na
barcolor(barColor, title = 'Bar Color')
//@version=6
i_showAtr = input.bool(true, title = 'Show ATR Bands', group = 'general band settings', inline = '11')
i_src = input.source(close, 'Source', group = 'general band settings', inline = '11')
i_repaints = input.bool(true, title = 'Repaints?', group = 'general band settings', inline = '12')
i_showLabels = input.bool(true, 'Show labels', group = 'general band settings', inline = '12')
i_extendLines = input.bool(true, 'Extend lines', group = 'general band settings', inline = '12')
i_lineThickness = input.int(2, 'Line thickness', minval = 1, group = 'general band settings', inline = '13')
i_lineStyle = input.string(line.style_dotted, 'Line style', options = [line.style_dotted, line.style_solid, line.style_dashed], group = 'general band settings', inline = '13')
i_fixedTargets = input.bool(true, title = 'Fixed targets')
i_trackingSlLength = input.int(2, title = 'Trailing Stop loss length', minval = 0)
i_firstMult = input.float(1.5, title = 'First atr band mult.', group = 'first band settings')
i_firstAtrLength = input.int(14, title = 'First atr band length', group = 'first band settings')
i_firstColor = input.color(color.blue, title = 'First color', group = 'first band settings')
i_secondMult = input.float(3.0, title = 'Second band mult.', group = 'second band settings')
i_secondAtrLength = input.int(14, title = 'Second atr band length', group = 'second band settings')
i_secondColor = input.color(color.orange, title = 'Second color', group = 'second band settings')
i_viPeriod = input.int(14, title = 'Length', minval = 2, group = 'vortex indicator settings')
i_applyTema = input.bool(true, title = 'Apply TEMA smoothing', group = 'vortex indicator settings')
arraySize = i_fixedTargets ? 3 : 2
index = i_repaints ? 0 : 1
var lineArray = array.new_line()
var labelArray = array.new_label()
f_tema(_source, _lenght) =>
ema01 = ta.ema(_source, _lenght)
ema02 = ta.ema(ema01, _lenght)
ema03 = ta.ema(ema02, _lenght)
output = 3 * (ema01 - ema02) + ema03
output
f_drawLine(_x1, _x2, _yValue, _lineColor, _lineThickness, _lineStyle) =>
line.new(x1 = _x1, y1 = _yValue, x2 = _x2, y2 = _yValue, color = _lineColor, style = _lineStyle, width = _lineThickness)
f_drawLabel(_x, _y, _textColor) =>
label.new(_x, _y, '         ' + str.tostring(_y), xloc.bar_index, yloc.price, #00000000, label.style_none, _textColor)
f_extendArray(_lineArray, _labelArray, _extendLines) =>
if array.size(_lineArray) > 0
for _i = array.size(_lineArray) - 1 to 0 by 1
lineId = array.get(_lineArray, _i)
x2 = line.get_x2(lineId)
x1 = line.get_x1(lineId)
yValue = line.get_y1(lineId)
if _extendLines or bar_index - 1 == x2 and not(high > yValue and low < yValue)
if i_showLabels
label.set_x(array.get(_labelArray, _i), bar_index)
line.set_x2(lineId, bar_index)
f_drawLineAndLabel(_x1, _x2, _yValue, _colorLine, _lineThickness, _lineStyle, _array, _labelArray) =>
line l = f_drawLine(_x1, _x2, _yValue, _colorLine, _lineThickness, _lineStyle)
if i_showLabels
label lab = f_drawLabel(_x2, math.round(_yValue, 2), _colorLine)
if array.size(_labelArray) == arraySize
label.delete(array.shift(_labelArray))
array.push(_labelArray, lab)
if array.size(_array) == arraySize
line.delete(array.shift(_array))
array.push(_array, l)
// Vortex indicator
vmp = math.sum(math.abs(high - low[1]), i_viPeriod)
vmm = math.sum(math.abs(low - high[1]), i_viPeriod)
str = math.sum(ta.atr(1), i_viPeriod)
vip = i_applyTema ? f_tema(vmp / str, i_viPeriod) : vmp / str
vim = i_applyTema ? f_tema(vmm / str, i_viPeriod) : vmm / str
viShort = ta.crossunder(vip, vim)
viLong = ta.crossover(vip, vim)
longBarSince = ta.barssince(viLong)
shortBarSince = ta.barssince(viShort)
viLongBarsSince = longBarSince == 0 ? 0 : longBarSince - index
viShortBarsSince = shortBarSince == 0 ? 0 : shortBarSince - index
// ATR bands
firstAtr = ta.atr(i_firstAtrLength)
secondAtr = ta.atr(i_secondAtrLength)
firstUpBand = i_src + firstAtr * i_firstMult
firstDownBand = i_src - firstAtr * i_firstMult
secondUpBand = i_src + secondAtr * i_secondMult
secondDownBand = i_src - secondAtr * i_secondMult
// Stop loss tracking
isLong = viLongBarsSince > viShortBarsSince
yValueTracking = isLong ? firstUpBand : firstDownBand
viBarsSince = isLong ? viShortBarsSince : viLongBarsSince
// ATR plots
plot(i_showAtr ? firstUpBand : na, '1+', linewidth = 1, color = color.new(i_firstColor, 100))
plot(i_showAtr ? firstDownBand : na, '1-', linewidth = 1, color = color.new(i_firstColor, 100))
plot(i_showAtr ? secondUpBand : na, '2+', linewidth = 1, color = color.new(i_secondColor, 100))
plot(i_showAtr ? secondDownBand : na, '2-', linewidth = 1, color = color.new(i_secondColor, 100))
Yer İmleri