DEMA Z-Score [NJ]

CryptoNejc · study · 74 行 · 点赞 52 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CryptoNejc
 
//@version=6
indicator("DEMA Z-Score [NJ]", "DZS", overlay = false, behind_chart = false)
 
// ✧═════════════════✧
// ║      INPUTS      ║
// ✧═════════════════✧
 
const string g1 = "✧ DISPLAY ✧"
colorMode   = input.string("Colored", "Color mode", options = ["Colored", "Neutral"], group = g1)
dispCandles = input.bool(true, "Color candles", group = g1)
 
const string g2 = "✧ CALCULATION ✧"
src      = input.source(low, "Source", group = g2)
srcLen   = input.int(26, "Source length", group = g2)
zsLen    = input.int(32, "Z-Score length", group = g2)
longThr  = input.float(0, "Long threshold", step = 0.1, group = g2)
shortThr = input.float(-0.2, "Short threshold", step = 0.1, group = g2)
 
// ✧══════════════════════✧
// ║      CALCULATION      ║
// ✧══════════════════════✧
 
// Source (dema)
ema1   = ta.ema(src, srcLen)
ema2   = ta.ema(ema1, srcLen)
source = 2 * ema1 - ema2
 
// Mean
mean = ta.sma(source, zsLen)
 
// Standard deviation
stDev = ta.stdev(source, zsLen)
 
// Z-Score
zScore = (source - mean) / stDev
 
// ✧═══════════════════════✧
// ║      FINAL SIGNAL      ║
// ✧═══════════════════════✧
 
var int NJ = 0
 
if zScore > longThr
    NJ := 1
if zScore < shortThr
    NJ := -1
 
// ✧════════════════✧
// ║      PLOTS      ║
// ✧════════════════✧
 
// Colors
longCol  = colorMode == "Colored" ? color.rgb(0, 136, 100) : colorMode == "Neutral" ? color.rgb(179, 179, 179) : na
shortCol = colorMode == "Colored" ? color.rgb(120, 0, 32) : colorMode == "Neutral" ? color.rgb(60, 60, 60) : na
sigCol = NJ == 1 ? longCol : NJ == -1 ? shortCol : na
 
// Color candles
plotcandle(
     open, high, low, close,
     "Colored candles", 
     dispCandles ? sigCol : na,
     dispCandles ? sigCol : na,
     bordercolor = dispCandles ? sigCol : na,
     display = display.all - display.status_line - display.price_scale,
     force_overlay = true)
 
// Display capped Z-Score
zsCapped = math.max(shortThr - 1, math.min(longThr + 1, zScore))
plot(zsCapped, "Z-Score", sigCol, 2)
hline(longThr, "Long threshold", longCol)
hline(shortThr, "Short threshold", shortCol)

← 返回列表