tradingview:indicadores:donchian_channel
Donchian Channel
// © SchillerApp
//@version=4
study(title="Canal de Donchian", shorttitle="ScApp_DC", overlay=true)
//// Passo 1. Configurações do Script
// Configurações do Canal
dcPeriodo = input(title="Período", type=input.integer, defval=20, minval=2, group="Configurações do Canal")
// Configurações Visuais
mostrarCentral = input(title="Mostrar Linha Central?", type=input.bool, defval=false, group="Configurações do Canal")
corFundoCanalS = input(title="Preenchimento Canal Superior", type=input.color, defval=color.green, group="Config do Canal")
corFundoCanalI = input(title="Preenchimento Canal Inferior", type=input.color, defval=color.red, group="Config do Canal")
// Configurações de Rompimento
filtroRompimento = input(title="Filtro de Rompimento (Ticks)", type=input.integer, defval=0, minval=0, group="Config de Rompimento") * syminfo.mintick
mostrarRompimento = input(title="Mostrar Rompimento?", type=input.bool, defval=true, group="Config de Rompimento")
//// Passo 2. Calcular os valores do Indicador
linhaSup = highest(high, dcPeriodo)[1]
linhaInf = lowest(low, dcPeriodo)[1]
linhaCen = (linhaSup + linhaInf) / 2
//// Passo 3. Determinar os sinais de rompimento
// Verificar se o preço cruzou acima ou abaixo das extremidades do Canal
rompSup = barstate.isconfirmed and crossover(close, linhaSup + filtroRompimento)
rompInf = barstate.isconfirmed and crossunder(close, linhaInf - filtroRompimento)
//// Passo 4. Resultado do Indicador
// Plotar Canal de Donchian
ls = plot(series=linhaSup, color=color.green, title="DoCh LS") // Linha Superior
li = plot(series=linhaInf, color=color.red, title="DoCh LI") // Linha Inferior
lc = plot(series=linhaCen, color=mostrarCentral ? color.orange : na, title="DoCh LC") // Linha Inferior
// Preencher o fundo do canal de Donchian
fill(plot1=ls, plot2=lc, color=corFundoCanalS)
fill(plot1=lc, plot2=li, color=corFundoCanalI)
// Destacar os rompimentos
highlightColour = not mostrarRompimento ? na : rompSup ? color.green : rompInf ? color.red : na
bgcolor(highlightColour)
// Passo 5. Criar Alertas
if rompSup or rompInf
banda = rompSup ? "Superior" : "Inferior"
alert("Cruzamento da Banda " + banda + " do Canal de Donchian") // Padrão : freq=once_per_bar
corLinhaCentral = input(title="Cor Linha Central", type=input.color, defval=color.orange, group="Configurações do Canal")
plotchar(rompSup, "Rompimento Superior", "▲", location.abovebar, color.lime, size=size.tiny)
plotchar(rompInf, "Rompimento Inferior", "▼", location.belowbar, color.red, size=size.tiny)
destacCor = na
if not mostrarRompimento
destacCor := na
else
if rompSup
destacCor := color.green
else if rompInf
destacCor := color.red
else
destacCor:= na
tradingview/indicadores/donchian_channel.txt · Última modificação: 30/01/2022 01:39 por schillerapp