TDI - Traders Dynamic Index + RSI Divergences + Buy/Sell Signals

ZyadaCharts · study · 223 行 · 点赞 5,585 · TradingView 原页

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

Pine Script

//@version=4
// Credits to LazyBear and JustUncleL.. more features added by ZyadaCharts
 
 
study("TDI - Traders Dynamic Index + RSI Divergences + Buy/Sell Signals", shorttitle="TDI + RSI Div")
 
rsiPeriod = input(14, minval = 1, title = "RSI Period")
bandLength = input(34, minval = 1, title = "Band Length")
lengthrsipl = input(7, minval = 0, title = "Fast MA on RSI")
lengthtradesl = input(2, minval = 1, title = "Slow MA on RSI")
 
src1 = close                                                             // Source of Calculations (Close of Bar)
r = rsi(src1, rsiPeriod)                                                 // RSI of Close
ma = sma(r, bandLength)                                                 // Moving Average of RSI [current]
offs = (1.6185 * stdev(r, bandLength))                                  // Offset
up = ma + offs                                                          // Upper Bands
dn = ma - offs                                                          // Lower Bands
mid = (up + dn) / 2                                                     // Average of Upper and Lower Bands
mbb = sma(r, lengthrsipl)                                            // Moving Average of RSI 2 bars back
mab = sma(r, lengthtradesl)                                          // Moving Average of RSI 7 bars back
 
 
hline(30, color=color.red, linewidth=1, linestyle=hline.style_dotted)
hline(50, color=color.orange, linewidth=1, linestyle=hline.style_dotted)
hline(70, color=color.green, linewidth=1, linestyle=hline.style_dotted)
 
// Plot the TDI
upl=plot(up, color=#12bcc9, transp=60, title="VB Channel High",linewidth=2)
dnl=plot(dn, color=#12bcc9, transp=60, title="VB Channel Low",linewidth=2)
midl=plot(mid, color=color.orange, transp=40, linewidth=2, title="MBL")
mabl=plot(mab, color=color.lime, transp=30, linewidth=2, title="RSI PL")
mbbl=plot(mbb, color=color.red, transp=60, linewidth=2, title="TSL Signal")
 
//
//create RSI TSL cloud to indicate trend direction.
fill(mabl,mbbl, color=mab>mbb?color.green:color.red,transp=80)
// fill(upl, midl, color.green, transp=95)                                   
// fill(midl, dnl, color.red, transp=95)        
 
 
//long/short labels
 
long1= crossover(mab, mbb) and mbb > mid and mbb > 50
short1= crossunder(mab, mbb) and mbb < mid and mbb < 50
 
plotshape(long1, style=shape.labelup, location=location.bottom, color=color.lime, size=size.tiny, editable=true)
plotshape(short1, style=shape.labeldown, location=location.top, color=color.red, size=size.tiny, editable=true)
 
alertcondition(long1, title='Long', message='Crossover')
alertcondition(short1, title='Short', message='Crossunder')
 
best_setup = crossover(mab, mid) 
alertcondition(best_setup, title="RSI Crosses Yellow", message="rsi crosses mid")
 
scalp= mab > mid 
bgcolor(scalp ? color.lime : na, transp=95)
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 
// Divergences //
 
 
len = input(title="RSI Period", minval=1, defval=14)
src = input(title="RSI Source", defval=close)
lbR = input(title="Pivot Lookback Right", defval=5)
lbL = input(title="Pivot Lookback Left", defval=5)
rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=false)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = rsi(src, len)
 
// // plot(osc, title="RSI", linewidth=2, color=#8D1699)
// hline(50, title="Middle Line", linewidth=2, linestyle=hline.style_dotted)
// obLevel = hline(70, title="Overbought", linewidth=2, linestyle=hline.style_dotted)
// osLevel = hline(30, title="Oversold", linewidth=2, linestyle=hline.style_dotted)
 
plFound = na(pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
	bars = barssince(cond == true)
	rangeLower <= bars and bars <= rangeUpper
 
 
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
 
oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
 
// Price: Lower Low
 
priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
 
plot(
     plFound ? osc[lbR] : na,
     offset=-lbR,
     title="Regular Bullish",
     linewidth=2,
     color=(bullCond ? bullColor : noneColor),
     transp=0
     )
 
plotshape(
	 bullCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Regular Bullish Label",
	 text=" Bull ",
	 style=shape.labelup,
	 location=location.absolute,
	 color=bullColor,
	 textcolor=textColor,
	 transp=0
	 )
 
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
 
oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
 
// Price: Higher Low
 
priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
 
plot(
	 plFound ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bullish",
	 linewidth=2,
	 color=(hiddenBullCond ? hiddenBullColor : noneColor),
	 transp=0
	 )
 
plotshape(
	 hiddenBullCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bullish Label",
	 text=" H Bull ",
	 style=shape.labelup,
	 location=location.absolute,
	 color=bullColor,
	 textcolor=textColor,
	 transp=0
	 )
 
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
 
oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
 
// Price: Higher High
 
priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)
 
bearCond = plotBear and priceHH and oscLH and phFound
 
plot(
	 phFound ? osc[lbR] : na,
	 offset=-lbR,
	 title="Regular Bearish",
	 linewidth=2,
	 color=(bearCond ? bearColor : noneColor),
	 transp=0
	 )
 
plotshape(
	 bearCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Regular Bearish Label",
	 text=" Bear ",
	 style=shape.labeldown,
	 location=location.absolute,
	 color=bearColor,
	 textcolor=textColor,
	 transp=0
	 )
 
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
 
oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
 
// Price: Lower High
 
priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)
 
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
 
plot(
	 phFound ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bearish",
	 linewidth=2,
	 color=(hiddenBearCond ? hiddenBearColor : noneColor),
	 transp=0
	 )
 
plotshape(
	 hiddenBearCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bearish Label",
	 text=" H Bear ",
	 style=shape.labeldown,
	 location=location.absolute,
	 color=bearColor,
	 textcolor=textColor,
	 transp=0
	 )

← 返回列表