Coppock Curve

AdonisWerther · study · 133 行 · 点赞 715 · TradingView 原页

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

Pine Script

//@version=5
indicator(title = "Coppock Curve", timeframe="", timeframe_gaps=true)
 
// oscillator
src = input(close, title='Source')
wmaLength = input(title="WMA Length", defval=10)
longRoCLength = input(title="Long RoC Length", defval=14)
shortRoCLength = input(title="Short RoC Length", defval=11)
pivR = input(title='Pivot Lookback Right', defval=1)
pivL = input(title='Pivot Lookback Left', defval=20)
 
 
curve = ta.wma(ta.roc(src, longRoCLength) + ta.roc(src, shortRoCLength), wmaLength)
 
// 2 - Compute ocillator
 
obvOsc = curve
 
obvColor = obvOsc > 0 ? color.new(color.aqua, 60) : color.new(color.orange, 60)
 
// Divergence
 
up = ta.rma(math.max(ta.change(src), 0), shortRoCLength)
down = ta.rma(-math.min(ta.change(src), 0), shortRoCLength)
lbR = input(title='Divergence Pivot Lookback Right', defval=1)
lbL = input(title='Divergence Pivot Lookback Left', defval=5)
rangeUpper = input(title='Max of Lookback Range', defval=100)
rangeLower = input(title='Min of Lookback Range', defval=2)
plotBull = input(title='Plot Bullish', defval=true)
plotHiddenBull = input(title='Plot Hidden Bullish', defval=true)
plotBear = input(title='Plot Bearish', defval=true)
plotHiddenBear = input(title='Plot Hidden Bearish', defval=true)
bearColor = color.new(color.red, 0)
bullColor = color.new(color.green, 0)
hiddenBullColor = color.new(color.aqua, 0)
hiddenBearColor = color.new(color.orange, 0)
textColor = color.new(color.white, 0)
noneColor = color.new(color.white, 100)
osc = curve
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper
 
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
 
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
 
// Price: Lower Low
 
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
 
plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=1, color=bullCond ? bullColor : noneColor, transp=0)
 
plotshape(bullCond ? osc[lbR] : na, offset=-lbR, title='Regular Bullish Label', style=shape.labelup, location=location.absolute, size=size.tiny, color=bullColor, textcolor=textColor, transp=0)
 
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
 
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
 
// Price: Higher Low
 
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
 
plot(plFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=1, color=hiddenBullCond ? hiddenBullColor : noneColor, transp=0)
 
plotshape(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish Label', style=shape.labelup, location=location.absolute, size=size.tiny, color=hiddenBullColor, textcolor=textColor, transp=0)
 
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
 
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
 
// Price: Higher High
 
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
 
bearCond = plotBear and priceHH and oscLH and phFound
 
plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=1, color=bearCond ? bearColor : noneColor, transp=0)
 
plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title='Regular Bearish Label', style=shape.labeldown, location=location.absolute, size=size.tiny, color=bearColor, textcolor=textColor, transp=0)
 
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
 
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
 
// Price: Lower High
 
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
 
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
 
plot(phFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=1, color=hiddenBearCond ? hiddenBearColor : noneColor, transp=0)
 
plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish Label', style=shape.labeldown, location=location.absolute, color=hiddenBearColor, size=size.tiny, textcolor=textColor, transp=0)
 
 
 
// Plots
plot(0, title='Zero Line', color=color.new(color.white, 40), style=plot.style_line, linewidth=1)
PHCond = obvOsc > 0 ? ta.pivothigh(obvOsc, pivL, pivR) : na
PLCond = obvOsc < 0 ? ta.pivotlow(obvOsc, pivL, pivR) : na
 
obvOsc2 = ta.sma(obvOsc, 3)
plot(obvOsc, color=obvColor, title='Coppock Oscillator', linewidth=3, style=plot.style_area)
plot(obvOsc, color=color.new(color.white, 10), title='OBV line', linewidth=1, style=plot.style_line)
plotshape(PHCond, title='Coppock Pivot High', location=location.absolute, style=shape.triangledown, size=size.auto, color=color.new(color.white, 00))
plotshape(PLCond, title='Coppock Pivot Low', location=location.absolute, style=shape.triangleup, size=size.auto, color=color.new(color.white, 00))
 
crossoverCond1 = ta.crossunder(obvOsc, 0)
crossoverCond2 = ta.crossover(obvOsc, 0)
 
//Alerts
 
alertcondition(PHCond, title='Pivot High', message='Pivot High {{ticker}}')
alertcondition(PLCond, title='Pivot Low', message='Pivot Low {{ticker}}')
alertcondition(crossoverCond1, title='Coppock Crossed Up', message='Coppock Cross Up {{ticker}}')
alertcondition(crossoverCond2, title='Coppock Crossed Down', message='Coppock Cross Down {{ticker}}')
alertcondition(bullCond, title='Bull Diversion', message='Coppock Regular Bull Div {{ticker}}')
alertcondition(bearCond, title='Bear Diversion', message='Coppock Regular Bear Div {{ticker}}')
alertcondition(hiddenBullCond, title='Hidden Bull Diversion', message='Coppock Hidden Bull Div {{ticker}}')
alertcondition(hiddenBearCond, title='Hidden Bear Diversion', message='Coppock Hidden Bear Div {{ticker}}')

← 返回列表