本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ©Kocurek
// @version=4
//
// Shoutouts to @Siwan- and @Upland for the inspirations.
//
// Live a little, publish your scripts...be a John Elhers
//
study(title="obv-adx", shorttitle="obv-adx", format=format.price, precision=4)
len = input(22, minval=1, title="DI Length")
lensig = input(22, title="ADX Smoothing", minval=1, maxval=50)
showADX1 = input(title='ADX Line or Histogram', type=input.bool, defval=false)
showADX2 = input(title='Background Highlighting', type=input.bool, defval=false)
//================ADX=========================
up = change(obv)
down = -change(obv)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = rma(stdev(obv, len),len)
plus = fixnan(100 * ema(plusDM, len) / trur)
minus = fixnan(100 * ema(minusDM, len) / trur)
sum = plus + minus
adx = 100 * ema(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
diDiff = plus - minus
//================Ploting True - ADX DMI=========================
plot(showADX1 ? plus:na, color=color.blue, title="+DI")
plot(showADX1 ? minus:na, color=color.orange, title="-DI")
plot(showADX1 ? adx:na, color=color.red, title="ADX")
mygreen = plus >= 22 and minus <= 18 and adx >=22
myred = minus >= 22 and adx >= 22 and plus <= 18
bgcolor(mygreen ? #00796b : na, transp=showADX2 ? 70:100, title="MyGreen")
bgcolor(myred ? #880e4f : na, transp=showADX2 ? 70:100, title="MyRed")
plotshape(crossover(plus, minus) ? showADX1 ? (plus + minus)*0.5 :na:na, location=location.absolute, style=shape.circle, color=color.green, size=size.tiny, transp=30, offset=0)
plotshape(crossover(minus, plus) ? showADX1 ? (plus + minus)*0.5 :na:na, location=location.absolute, style=shape.circle, color=color.red, size=size.tiny, transp=30, offset=0)
//================Ploting Flase - Histogram=========================
diColor = plus - minus > 0 ? (diDiff > diDiff[1] ? #45f248 : #C6FBC7) : (diDiff < diDiff[1] ? #ff7878 : #FCCFCF)
plot(showADX1 ? na : diDiff + 50, style=plot.style_columns, color=diColor, histbase=50, transp=47, title='DI Difference')
// Plots divergences
plotshape(mygreen? showADX1 ? na : diDiff + 50 : na, location=location.absolute, style=shape.triangledown, color=color.red, size=size.tiny, transp=30, offset=0)
plotshape(myred? showADX1 ? na : diDiff + 50 :na, location=location.absolute, style=shape.triangleup, color=color.green, size=size.tiny, transp=30, offset=0)