DC Mean Reversion Alerts

dysrupt · study · 72 行 · 点赞 492 · TradingView 原页

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

Pine Script

//Modified Donchonian Channel with separate adjustments for upper and lower levels
//Purpose is if you expect big move up, Use lower input example 3 or 4, and longer lower input, 40 - 100 and use lower input line as a stop out
//Opposite if you expect big move down
//Mid Line Rule in Long Example.  If lower line is below entry take partial profits at Mid Line and move stop to Break even.
//If Lower line moves above entry price before price retraces to midline use Lower line as Stop...Opposite if Shorting
//Created by user ChrisMoody 1-30-2014
 
//Updated 12-14-2014 by ChrisMoody, Added Alert Capability, Bars Change Colors Based on Breakouts.Arrows At Bottom Showing Entry
//Create Alert by selecting Indicator, then either Alert Breakout Upside or Downside, Select Greater Than, Select Value, for Value put .99 [fixed]
 
//Updated 7-11-2018 by Dysrupt, Revamped for mean reversion strategy
//Created midline alerts for strong upside buy signals and downside sell signals. ONLY for strong trending environments
//Added RSI Filtering
//Added Alerts
//Removed bar color change
 
study(title="DC Mean Reversion Alerts", shorttitle="DCMRA", overlay=true)
length1 = input(50, minval=1, title="Upper Channel")
length2 = input(50, minval=1, title="Lower Channel")
sml = input(true, title="Show Mid-Line?")
sa = input(true, title="Show Arrows?")
suta = input(true, title="Show Arrows On Midline?")
 
 
upper = highest(length1)
lower = lowest(length2)
basis = avg(upper, lower)
 
break_Above = close > upper[1] ? 1 : 0
break_Below = close < lower[1] ? 1 : 0
 
break_AboveHB() => close > upper[1] ? 1 : 0
break_BelowHB() => close < lower[1] ? 1 : 0
 
src = input(low)
ma = sma(src, 2)
utc = crossunder(ma, basis)
dtc = crossover(ma, basis)
 
RSIlength = input( 14 ,title="RSI Period Length")
RSIvaluehigh = input( 60 ,title="RSI High") 
RSIoverSoldhigh = 0 + RSIvaluehigh
RSIoverBoughthigh = 100 - RSIvaluehigh
 
RSIvaluelow = input( 30 ,title="RSI Low") 
RSIoverSoldlow = 0 + RSIvaluelow
RSIoverBoughtlow = 100 - RSIvaluelow
 
 
 
price = close
vrsi = rsi(price, RSIlength)
buy = vrsi<RSIvaluelow
sell = vrsi>RSIvaluehigh
 
 
plotshape(sell and sa and break_Above ? break_Above : na, title="Sell", style=shape.triangledown, location=location.abovebar, color=#ff0066, size=size.small)
plotshape(buy and sa and break_Below ? break_Below : na, title="Buy", style=shape.triangleup, location=location.belowbar, color=#00cc00, size=size.small)
plotshape(suta and utc, style=shape.triangleup, title="Uptrend Buy", location=location.belowbar, color = #00cc00, transp=50, size = size.tiny)
plotshape(suta and dtc, style=shape.triangledown, title="Downtrend Sell", location=location.abovebar, color = #ff0066, transp=50, size = size.tiny)
 
u = plot(upper, title="Upper DC Band", style=line, linewidth=2, color=#00cc00)
l = plot(lower, title="Lower DC Band", style=line, linewidth=2, color=#ff0066)
m = plot(sml and basis ? basis : na, title="Mid-Line", color=gray, style=line, linewidth=1)
 
fill(m, u, color=#00cc00, transp=90, title="High Fill")
fill(m, l, color=#ff0066, transp=90, title="Low Fill")
 
alertcondition(buy and break_Below, title='Buy', message='Low DC')
alertcondition(break_Above, title='Sell', message='High DC')
alertcondition(utc, title='Uptrend Buy', message='Uptrend Buy')
alertcondition(dtc, title='Downtrend Sell', message='Downtrend Sell')

← 返回列表