ADX Di+ Di- [Gu5]

gu5tavo71 · study · 84 行 · 点赞 5,532 · TradingView 原页

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

Pine Script

//@version=4
// Created by @gu5tavo71 09/2019
// Github repo https://github.com/gu5tavo/Tradingview
// Disclaimer: I am not a financial advisor. 
//             For purpose educate only
// If you have had a positive experience, you can buy me a beer ;)
// BTC: 1MbHMN63WnsFYEavsGK4nMWSUoEiuiScny
// Paypal: https://www.paypal.me/gu5tavo71
///////////////////////////////////////////////////////////////
study(title="ADX Di+ Di- [Gu5]", shorttitle = "ADX", format = format.price, precision = 2, overlay = false)
 
//Input
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
hladx = input(20, title="Level Range")
hladx2 = input(35, title="Level Trend")
showalert = input(defval = true, title="Show Cross Di")
 
//Setting
Color00 = #f57f17//Orange
Color02 = #f57f17ff//Orange 100%
Color10 = #006400//Green
Color11 = #00640080//Green 50%
Color12 = #006400ff//Green 100%
Color20 = #8B0000//Red
Color21 = #8B000080//Red 50%
Color22 = #8B0000ff//Red 100%
Color31 = #808080//Gray
 
dirmov(len) =>
	up = change(high)
	down = -change(low)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
	truerange = rma(tr, len)
	plus = fixnan(100 * rma(plusDM, len) / truerange)
	minus = fixnan(100 * rma(minusDM, len) / truerange)
	[plus, minus]
adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adxHigh(dilen, adxlen) => 
	[plus, minus] = dirmov(dilen)
	plus
adxLow(dilen, adxlen) => 
	[plus, minus] = dirmov(dilen)
	minus
 
sig = adx(dilen, adxlen)
diHigh = adxHigh(dilen, adxlen)
diLow = adxLow(dilen, adxlen)
adxup() => sig >= hladx
diup() => diHigh >= diLow
diups() => diHigh >= hladx2
didn() => diLow > diHigh
didns() => diLow > hladx2
 
coladx =
	 (not adxup()) ? Color00 :
	 (adxup() and (sig > sig[1]) and diup()) ? Color12 :
	 (adxup() and (sig <= sig[1]) and diup()) ? Color11 :
	 (adxup() and (sig > sig[1]) and didn()) ? Color22 :
	 (adxup() and (sig <= sig[1]) and didn()) ? Color21 :
	 na
 
coladxfill =
	 (not adxup()) ? Color00 :
	 (adxup() and diup() and diups()) ? Color11 :
	 (adxup() and diup() and not diups()) ? Color10 :
	 (adxup() and didn() and didns()) ? Color21 :
	 (adxup() and didn() and not didns()) ? Color20 :
	 na
 
crossdi = cross (diHigh, diLow) and adxup()
 
//Drawing
hline(hladx, color = Color31, linestyle = hline.style_dotted, linewidth = 1, title = "Level Range")
hline(hladx2, color = Color31, linestyle = hline.style_dotted, linewidth = 1, title = "Level Trend")
dih = plot(diHigh, color = Color10, title="+DI")
dil = plot(diLow, color = Color20, title="-DI")
fill(dih, dil, color = coladxfill, title="Fill ADX ")
plot(sig, color = coladx , linewidth = 3, title="ADX")
plot(showalert and crossdi ? sig : na, style = plot.style_cross, linewidth = 4, color = Color02, title = "Cross Di")

← 返回列表