我正在尝试创建一个可选择时间范围的指标。 一切正常,除了我无法在输入上选择第二个时间范围。 这是代码:
此代码的基础由 PasqualeAntonino 创建。 我只是修改了外观并添加了移动平均线。
//@version=5
indicator(title="DeMarker", shorttitle="DeM", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
len1 = input.int(14, title="Demarker Length")
len0 = input.int(14, title="Demarker Length2")
demax = high > high[1] ? high - high[1] : 0
demax1 = high > high[1] ? high - high[1] : 0
demin = low < low[1] ? low[1] - low : 0
demin1 = low < low[1] ? low[1] - low : 0
demax_av = ta.sma(demax, len1)
demax_av1 = ta.sma(demax1, len0)
demin_av = ta.sma(demin, len1)
demin_av1 = ta.sma(demin1, len0)
dmark = demax_av / (demax_av + demin_av)
dmark2 = demax_av1 / (demax_av1 + demin_av1)
len2 = input.int(21, title="Moving Average Length")
len3 = input.int(21, title="Moving Average Length2")
dma = ta.ema(dmark, len2)
dma2 = ta.ema(dmark, len3)
//Plots
h1 = hline(0.7, linestyle=hline.style_solid, color=color.new(#ef5350, 20), title="Upper Line")
h2 = hline(0.5, linestyle=hline.style_solid, color=color.new(#787b86, 50), title="Center Line")
h3 = hline(0.3, linestyle=hline.style_solid, color=color.new(#26a69a, 20), title="Lower Line")
fill(h1, h3, color=color.new(#787b86, 90), title="Background")
plot(dma, color=#787b86, linewidth=1, title="Moving Average 1")
plot(dma2, color=#787b86, linewidth=1, title="Moving Average 2")
plot(dmark, color=#2962ff, linewidth=2, title="Demarker")
plot(dmark2, color=#2962ff, linewidth=2, title="Demarker2")``
我应该添加什么才能在 inpts 上选择第二个时间范围?
这是您应该如何使用函数 f_secureSecurity 和移动平均值
的示例//@version=5
indicator('ma Htf', overlay = true)
i_ma = input.int (21, 'ma')
i_htf = input.timeframe ('','Select Higher Timeframe')
// @function To securely and simply call `security()` so that it never repaints and never looks ahead.
// @param _symbol (string) Symbol Ticker ID (syminfo.tickerid).
// @param _res (string) Higher timeframe used for security() calls.
// @param _src (string) Source used in security() calls.
// @returns Data Higher timeframe (No Repaint).
f_secureSecurity(_symbol, _res, _src) =>
request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
maHtf = f_secureSecurity(syminfo.tickerid, i_htf, ta.ema(close, i_ma))
plot(maHtf)
使用 PineCoders 库中的 f_secureSecurity
函数