OPEN-SOURCE SCRIPT

Combined Indicator (sdtzym)

//version=5
indicator("Combined Indicator", "LuxAlgo Combined", overlay=true)

//-----------------------------------------------------------------------------//
// Inputs
//-----------------------------------------------------------------------------//
// Trendlines with Breaks Inputs
length = input.int(14, 'Swing Detection Lookback')
mult = input.float(1., 'Slope', minval = 0, step = .1)
calcMethod = input.string('Atr', 'Slope Calculation Method', options = ['Atr','Stdev','Linreg'])
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the past. Disable backpainting to see real-time information returned by the indicator.')
upCss = input.color(color.teal, 'Up Trendline Color', group = 'Style')
dnCss = input.color(color.red, 'Down Trendline Color', group = 'Style')
showExt = input(true, 'Show Extended Lines')

// TRAMA Inputs
trama_length = input.int(99, 'TRAMA Length')
trama_src = input(close, 'TRAMA Source')

// LinReg Candles Inputs
signal_length = input.int(11, title="Signal Smoothing")
sma_signal = input.bool(true, title="Simple MA (Signal Line)")
lin_reg = input.bool(true, title="Lin Reg")
linreg_length = input.int(11, title="Linear Regression Length")

//-----------------------------------------------------------------------------//
// Calculations for Trendlines with Breaks
//-----------------------------------------------------------------------------//
var upper = 0.
var lower = 0.
var slope_ph = 0.
var slope_pl = 0.
var offset = backpaint ? length : 0

n = bar_index
src = close

ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)

slope = switch calcMethod
'Atr' => ta.atr(length) / length * mult
'Stdev' => ta.stdev(src,length) / length * mult
'Linreg' => math.abs(ta.sma(src * n, length) - ta.sma(src, length) * ta.sma(n, length)) / ta.variance(n, length) / 2 * mult

slope_ph := ph ? slope : slope_ph
slope_pl := pl ? slope : slope_pl

upper := ph ? ph : upper - slope_ph
lower := pl ? pl : lower + slope_pl

var upos = 0
var dnos = 0
upos := ph ? 0 : close > upper - slope_ph * length ? 1 : upos
dnos := pl ? 0 : close < lower + slope_pl * length ? 1 : dnos

var uptl = line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend = extend.right)
var dntl = line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend = extend.right)

if ph and showExt
uptl.set_xy1(n-offset, backpaint ? ph : upper - slope_ph * length)
uptl.set_xy2(n-offset+1, backpaint ? ph - slope : upper - slope_ph * (length+1))

if pl and showExt
dntl.set_xy1(n-offset, backpaint ? pl : lower + slope_pl * length)
dntl.set_xy2(n-offset+1, backpaint ? pl + slope : lower + slope_pl * (length+1))

plot(backpaint ? upper : upper - slope_ph * length, 'Upper', color = ph ? na : upCss, offset = -offset)
plot(backpaint ? lower : lower + slope_pl * length, 'Lower', color = pl ? na : dnCss, offset = -offset)

plotshape(upos > upos[1] ? low : na, "Upper Break", shape.labelup, location.absolute, upCss, text = "B", textcolor = color.white, size = size.tiny)
plotshape(dnos > dnos[1] ? high : na, "Lower Break", shape.labeldown, location.absolute, dnCss, text = "B", textcolor = color.white, size = size.tiny)

//-----------------------------------------------------------------------------//
// Calculations for TRAMA
//-----------------------------------------------------------------------------//
trama_ama = 0.
hh = math.max(math.sign(ta.change(ta.highest(trama_length))), 0)
ll = math.max(math.sign(ta.change(ta.lowest(trama_length)) * -1), 0)
tc = math.pow(ta.sma(hh or ll ? 1 : 0, trama_length), 2)
trama_ama := na(trama_ama[1]) ? trama_src : trama_ama[1] + tc * (trama_src - trama_ama[1])
plot(trama_ama, "TRAMA", color=color.new(color.red, 0), linewidth=2)

//-----------------------------------------------------------------------------//
// Calculations for LinReg Candles
//-----------------------------------------------------------------------------//
bopen = lin_reg ? ta.linreg(open, linreg_length, 0) : open
bhigh = lin_reg ? ta.linreg(high, linreg_length, 0) : high
blow = lin_reg ? ta.linreg(low, linreg_length, 0) : low
bclose = lin_reg ? ta.linreg(close, linreg_length, 0) : close

r = bopen < bclose
signal = sma_signal ? ta.sma(bclose, signal_length) : ta.ema(bclose, signal_length)

plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow: na, r ? bclose : na, title="LinReg Candles", color=color.green, wickcolor=color.green, bordercolor=color.green)
plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose, title="LinReg Candles", color=color.red, wickcolor=color.red, bordercolor=color.red)

plot(signal, color=color.white)
regressionsTrend Analysis

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?

Declinazione di responsabilità