【发布时间】:2020-09-05 07:40:45
【问题描述】:
我想同时编码 RSI ADX 和 ATR。
RSI 和 ADX 是带状振荡器 (0-100),而 ATR 不是。如果 ATR 明显高于 100,那么整个地块就会被挤压。我想在相同的代码中添加 ATR,但只想将左轴用于 ATR。
我在情节代码上添加了scale=scale.left,但这似乎不起作用,并且出现以下错误:-
Add to Chart operation failed, reason:
-line 79: Unknown argument 'scale' of type 'const integer';
-line 79: Cannot call 'plot' with arguments (type_unknown, title=literal string, color=literal color, transp=literal integer, scale=const integer); available overloads: plot(series[float], const string, series[color], input integer, input integer, input bool, input integer, input float, series[integer], input bool, series[float], const bool, input integer, const integer, string) => plot; plot(fun_arg__<arg_series_type>, const string, fun_arg__<arg_color_type>, input integer, input integer, input bool, input integer, input float, series[integer], input bool, series[float], const bool, input integer, const integer, string) => plot
我写了以下代码:-
// RSI //
len = input(14, minval=1, title="RSI Length")
rsisrc = input(close, "RSI Source", type = input.source)
up = rma(max(change(rsisrc), 0), len)
down = rma(-min(change(rsisrc), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#ffa726)
band1 = hline(60, "RSI Upper Band", color=#C0C0C0)
band2 = hline(50, "RSI Middle Band", color=#C0C0C0)
band0 = hline(40, "RSI Lower Band", color=#C0C0C0)
fill(band1, band0, color=#ffa726, transp=92, title="RSI Background")
// ADX //
adxlen = input(8, title="ADX Smoothing")
dilen = input(13, title="DI Length")
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)
sig = adx(dilen, adxlen)
plot(sig, color=#e57373, title="ADX")
band3 = hline(25, "ADX Line", color=#C0C0C0)
// ATR //
length = input(title="Length", defval=14, minval=1)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
ma_function(source, length) =>
if smoothing == "RMA"
rma(source, length)
else
if smoothing == "SMA"
sma(source, length)
else
if smoothing == "EMA"
ema(source, length)
else
wma(source, length)
plot(ma_function(tr(true), length), title = "ATR", color=#991515, transp=0, scale=scale.left)
请帮助我并告诉我该怎么做。
【问题讨论】:
标签: pine-script