【发布时间】:2022-10-20 11:20:13
【问题描述】:
我正在尝试在循环平滑 RSI 上添加带有平滑线的 EMA。 EMA 是 pine-script 版本 5,循环平滑 RSI 是版本 4。但即使我将 EMA 降级到版本 4,我仍然遇到以下错误 -
语法错误:输入函数的参数必须是常量类型,或者 “源”内置变量。
我的代码如下 -
//@version=4 study(title="Smoothed Cyclic RSI with EMA", shorttitle="cRSI-EMA") src = close domcycle = input(20, minval=10, title="Dominant Cycle Length") crsi = 0.0 cyclelen = domcycle / 2 vibration = 10 leveling = 10.0 cyclicmemory = domcycle * 2 //set min/max ranges? h1 = hline(30, color=color.silver, linestyle=hline.style_dashed) h2 = hline(50, color=color.silver, linestyle=hline.style_dashed) h3 = hline(70, color=color.silver, linestyle=hline.style_dashed) torque = 2.0 / (vibration + 1) phasingLag = (vibration - 1) / 2.0 up = rma(max(change(src), 0), cyclelen) down = rma(-min(change(src), 0), cyclelen) rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down) csrsi = torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1]) lmax = -999999.0 lmin = 999999.0 for i = 0 to cyclicmemory - 1 by 1 if nz(csrsi[i], -999999.0) > lmax lmax := nz(csrsi[i]) lmax else if nz(csrsi[i], 999999.0) < lmin lmin := nz(csrsi[i]) lmin mstep = (lmax - lmin) / 100 aperc = leveling / 100 db = 0.0 for steps = 0 to 100 by 1 testvalue = lmin + mstep * steps above = 0 below = 0 for m = 0 to cyclicmemory - 1 by 1 below := below + iff(crsi[m] < testvalue, 1, 0) below ratio = below / cyclicmemory if ratio >= aperc db := testvalue break else continue ub = 0.0 for steps = 0 to 100 by 1 testvalue = lmax - mstep * steps above = 0 for m = 0 to cyclicmemory - 1 by 1 above := above + iff(csrsi[m] >= testvalue, 1, 0) above ratio = above / cyclicmemory if ratio >= aperc ub := testvalue break else continue fill(h1, h2, color=color.silver, transp=90) plot(csrsi, "CS-RSI", color.fuchsia) //EMA with Signal //Inputs len = input(9, minval=1, title="Length") esrc = input(csrsi, title="Source") smoothingLength = input(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing") offset = input(title="Offset", defval=0, minval=-500, maxval=500) //Calculation out = ema(esrc, len) smoothingLine = sma(out, smoothingLength) //Plotting plot(out, title="EMA", color=color.green, offset=offset) plot(smoothingLine, title="Smoothing Line", color=color.red, offset=offset, display=display.none)如果这里有人可以在 pine-script 版本 4 或 5 中修复此代码,我将不胜感激。 版本 5 中的错误是关于当夫()功能。错误如下 -
第 44 行:找不到函数或函数引用“iff”。
请帮我解决这个问题。谢谢你的时间。问候。
【问题讨论】:
标签: pine-script