OPEN-SOURCE SCRIPT
DKX & MADKX Indicator

//version=6
indicator("DKX & MADKX Indicator", "DKX", false)
// --- Constants ---
var int DKX_period = 15
var int MADKX_period = 7
// --- 1. 计算中间变量 MID ---
// (3 * close + low + open + high) / 6
mid = (3 * close + low + open + high) / 6
// --- 2. 计算 DKX 加权移动平均线 ---
// 注意:Pine Script的 ta.wma() 权重是 (1, 2, 3...),与通达信的反向加权 (20, 19, 18...) 不同。
// 因此,我们需要手动计算这个加权平均。
//
// 手动加权平均公式: Sum(weight * source) / Sum(weight)
// 权重: 20, 19, 18, 17, ..., 3, 2, 1
// 权重的总和: 20 + 19 + ... + 1 = 20 * (20 + 1) / 2 = 210
var float dkx_sum = 0.0
var float dkx_weights_sum = 0.0
dkx_sum := 0.0
dkx_weights_sum := 0.0
for i = 0 to DKX_period - 1
weight = DKX_period - i
dkx_sum += mid * weight
dkx_weights_sum += weight
dkx = dkx_sum / dkx_weights_sum
// --- 3. 计算 MADKX (DKX的简单移动平均) ---
madkx = ta.sma(dkx, MADKX_period)
// --- 4. 绘图 ---
plot(dkx, "DKX", color.red, linewidth=2)
plot(madkx, "MADKX", color.yellow, linewidth=2)
indicator("DKX & MADKX Indicator", "DKX", false)
// --- Constants ---
var int DKX_period = 15
var int MADKX_period = 7
// --- 1. 计算中间变量 MID ---
// (3 * close + low + open + high) / 6
mid = (3 * close + low + open + high) / 6
// --- 2. 计算 DKX 加权移动平均线 ---
// 注意:Pine Script的 ta.wma() 权重是 (1, 2, 3...),与通达信的反向加权 (20, 19, 18...) 不同。
// 因此,我们需要手动计算这个加权平均。
//
// 手动加权平均公式: Sum(weight * source) / Sum(weight)
// 权重: 20, 19, 18, 17, ..., 3, 2, 1
// 权重的总和: 20 + 19 + ... + 1 = 20 * (20 + 1) / 2 = 210
var float dkx_sum = 0.0
var float dkx_weights_sum = 0.0
dkx_sum := 0.0
dkx_weights_sum := 0.0
for i = 0 to DKX_period - 1
weight = DKX_period - i
dkx_sum += mid * weight
dkx_weights_sum += weight
dkx = dkx_sum / dkx_weights_sum
// --- 3. 计算 MADKX (DKX的简单移动平均) ---
madkx = ta.sma(dkx, MADKX_period)
// --- 4. 绘图 ---
plot(dkx, "DKX", color.red, linewidth=2)
plot(madkx, "MADKX", color.yellow, linewidth=2)
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.