SuperTrendRange by DGT

dgtrd · study · 54 行 · 点赞 2,945 · TradingView 原页

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

Pine Script

// © dgtrd
 
//@version=4
study(title="SuperTrendRange by DGT", shorttitle="STR by DGT", overlay=true)
source = input(close,    "Source", type=input.source)
length = input(13,       "Length")
trm    = input(1.,       "Volatility (ATR) Multiplier"  , step=.1, minval = 0)
sdm    = input(1.,       "Standard Deviation Multiplier", step=.1, minval = 0)
strs   = input("Source", "SuperTrendRange Basis Source" , options=["Source", "Moving Average"])
pll    = input(233,      "Plotting Length")
 
//------------------------------------------------------------------------------
// Calculations 
basis = ema(source, length)
dev   = strs == "Source" ? sdm * stdev(source, length) : sdm * stdev(basis, length)
atr   = trm * atr(length)
 
var a = true
 
support    = basis - dev - atr
support_1  = nz(support[1], support)
support   := basis > support_1 ? max(support, support_1) : support
    
resistance      = basis + dev + atr
resistance_1    = nz(resistance[1], resistance)
resistance     := basis < resistance_1 ? min(resistance, resistance_1) : resistance
    
str = if source > basis 
    if source > (basis + atr) and source > (basis + dev)
        support
    else if source < (basis + atr) or source < (basis + dev)
        if a
            a := false
            resistance
        else
            a := true
            support
                
else if source < basis 
    if source < (basis - atr) and source < (basis - dev)
        resistance
    else if source > (basis - atr) or source > (basis - dev)
        if a
            a := false
            resistance
        else
            a := true
            support
 
//------------------------------------------------------------------------------
// Plotting
 
plot(str  , "SuperTrendRange", color = str > basis ? color.red : color.green, style = plot.style_circles, show_last = pll)
plot(basis, "Exponential Moving Average", color=color.aqua, show_last = pll)

← 返回列表