Donchian Standard Deviation | NickJoan

Nick_Joan · study · 41 行 · 点赞 6 · 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/
// © Nick_Joan
//@version=6
indicator(title='Donchian Standard Deviation | NickJoan', format = format.inherit, timeframe = '', timeframe_gaps = false, overlay = true)
 
// ─── Inputs ───────────────────────────────────────────────────────────────────
highLen             = input.int(34, title='Highs Length', minval=1, group='DONCHIAN SETTINGS')
lowLen              = input.int(3, title='Lows Length', minval=1, group='DONCHIAN SETTINGS')
stdevLen            = input.int(40,'Length', minval = 2, group = 'STANDARD DEVIATION')
upMultiplier        = input.float(1.06,'Upper multiplier', step = 0.01, group = 'STANDARD DEVIATION')
downMultiplier      = input.float(1.06,'Lower multiplier', step = 0.01, group = 'STANDARD DEVIATION')
 
// ─── Calculations ─────────────────────────────────────────────────────────────
upper       = ta.highest(high, highLen)
lower       = ta.lowest(low, lowLen)
middle      = (upper + lower) / 2
 
stdev       = ta.stdev(middle, stdevLen)
upperbound  = middle + stdev * upMultiplier
lowerbound  = middle - stdev * downMultiplier
 
 
// ─── Long/Short Conditions ─────────────────────────────────────────────────────────────
longCondition  = close > upperbound[1]
shortCondition = close < lowerbound[1]
 
var state = 0
state := longCondition ? 1 : shortCondition ? -1 : state
 
// ─── Plots and Colors ─────────────────────────────────────────────────────────────
stateColor = state == 1 ? color.aqua : state == -1 ? color.olive : color.gray
plotcandle(open , high, low, close, title = 'Color Bars', wickcolor = stateColor, bordercolor = stateColor, color = stateColor, display = display.pane)
plot(middle, title = 'Donchian Middle', color = color.white, linewidth = 2, offset = 1, display = display.none)
plot(upperbound, title = 'Upper Bound', color =color.new(color.white,70), offset = 1)
plot(lowerbound, title = 'Lower Bound', color = color.new(color.white,70), offset = 1)
 
// ─── Alerts ─────────────────────────────────────────────────────────────
longSignal  = state == 1  and state[1] != 1  and barstate.isconfirmed
shortSignal = state == -1 and state[1] != -1 and barstate.isconfirmed
alertcondition(longSignal, title='Long Signal', message='Donchian SD turned bullish')
alertcondition(shortSignal, title='Short Signal', message='Donchian SD turned bearish')

← 返回列表