Donchian Trend Signals

OmegaTools · study · 50 行 · 点赞 872 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OmegaTools
 
//@version=5
indicator("Donchian Trend Signals", "DTS", overlay = true)
 
lnt = input(21, "Length")
cmp = input.bool(false, "Complex mode", "Transform the average line into the average of multiple length average line, respectively of half the length you have chosen, the length, and double the length")
 
lnt05 = math.round(lnt / 2)
lnt1 = math.round(lnt * 2)
 
h0 = ta.highest(close, lnt)
l0 = ta.lowest(close, lnt)
m0 = math.avg(h0, l0)
 
h05 = ta.highest(close, lnt05)
l05 = ta.lowest(close, lnt05)
m05 = math.avg(h05, l05)
 
h1 = ta.highest(close, lnt1)
l1 = ta.lowest(close, lnt1)
m1 = math.avg(h1, l1)
 
m = cmp == false ? m0 : math.avg(m0, m05, m1)
h = cmp == false ? h0 : math.avg(h0, h05, h1)
l = cmp == false ? l0 : math.avg(l0, l05, l1)
 
trend = 0
trend := if m > m[1]
    trend := 1
else if m < m[1]
    trend := -1
else if m == m[1]
    trend := trend[1]
col = trend == 1 ? #2962ff : trend == -1 ? #e91e63 : color.gray
 
vol = volume > ta.sma(volume, 9)
sgrab = high > h and close < h and vol
bgrab = low < l and close > l and vol
rng = math.avg(high - low, math.abs(close-open))
enb = rng > rng[1] and close > open
ens = rng > rng[1] and close < open
 
plot(h, "Higher price", color.gray, 1, plot.style_linebr)
plot(l, "Lower price", color.gray, 1, plot.style_linebr)
plot(m, "Average price", col, 2)
barcolor(col, title = "Trend coloring")
plotshape(bgrab, "Liquidity buy", shape.diamond, location.belowbar, enb ? #2962ff : color.gray)
plotshape(sgrab, "Liquidity sell", shape.diamond, location.abovebar, ens ? #e91e63 : color.gray)

← 返回列表