0

我正在用 2 个 ATR 编写这个简单的代码,并在蜡烛超过 ATR 的设定百分比时添加了黑色条形颜色,无论是高低还是收盘价。

如果它确实回撤,我现在尝试用黄色突出显示下面的蜡烛,但如果第二根蜡烛也超过 ATR 百分比,我希望它涂成黑色而不是黄色。

简而言之,我希望黑色条形颜色始终优先于黄色条形。

不幸的是,我做错了什么,代码只画了黑条,而不是黄条。希望你们中的一些人能够帮助我。

提前致谢

//@version=4

study("ATRs", shorttitle="ATRs", overlay=false, precision=5)

length=input(14, title="ATR Length")
vaexocco=input(150, title="OCCO Exceeding %", step=5)
vaexhl=input(200, title="HL Exceeding %", step=5)
brcl=input(true, title="Color Bars")
mult=input(0.7, title="Percentage Multiplier (for ex., 0.7 = 70%)", step=0.1, minval=0.1, maxval=2.0)

x=0.0
y=syminfo.pointvalue==0
w=y?atr(length):(syminfo.pointvalue * mult * atr(length))
x:=y?(nz(x[1])+0.7)%3.0:na
p1 = plot(rma(tr(true), length), color=#ff6d00, linewidth=1, transp=100, title="1xATR")
plot(y?na:w, color=color.blue, linewidth=1,transp=100, title="ATR")

//Bar Color

occo = close > open ? close - open : open - close
mtatr = high-low > vaexhl/100*atr(length)[1] or occo > vaexocco/100*atr(length)[1]
brclr = color.black

bar_dir = close[1] > open[1] ? 1 : open[1] > close[1] ? -1 : na
a = bar_dir == -1 ? (close > close[1]) : bar_dir == 1 ? (close < close[1]) : na
b = bar_index[1] == mtatr and bar_index == a
fnl = (mtatr and b ? color.black : mtatr ? color.black : b ? color.yellow : na)

wch_ = brcl ? fnl : na
barcolor(wch_)
4

1 回答 1

0

这有望使您更接近您的目标:

//@version=4

study("ATRs", shorttitle="ATRs", overlay=true, precision=5)

length=input(14, title="ATR Length")
vaexocco=input(150, title="OCCO Exceeding %", step=5)
vaexhl=input(200, title="HL Exceeding %", step=5)
brcl=input(true, title="Color Bars")
mult=input(0.7, title="Percentage Multiplier (for ex., 0.7 = 70%)", step=0.1, minval=0.1, maxval=2.0)

x=0.0
y=syminfo.pointvalue==0
w=y?atr(length):(syminfo.pointvalue * mult * atr(length))
x:=y?(nz(x[1])+0.7)%3.0:na
// p1 = plot(rma(tr(true), length), color=#ff6d00, linewidth=1, transp=100, title="1xATR")
// plot(y?na:w, color=color.blue, linewidth=1,transp=100, title="ATR")

//Bar Color
occo = abs(open - close)
mtatr = high-low > vaexhl/100*atr(length)[1] or occo > vaexocco/100*atr(length)[1]
barUp = close[1] > open[1]
barDn = open[1]  > close[1]
a = barDn ? (close > close[1]) : barUp ? (close < close[1]) : false
b = mtatr[1] and a
barcolor(mtatr ? color.black : b ? color.yellow : na)

在此处输入图像描述

于 2020-07-31T10:42:27.630 回答