我正在尝试获取警报消息以打印之前在脚本中定义的变量。这是我的代码的
alertcondition()
部分:
var bool alerttrigger = true
WaveTrend1val = wt1
strWaveTrend1val = tostring(WaveTrend1val)
alertcondition(alerttrigger, title="Test alert", message=strWaveTrend1val)
//plot(WaveTrend1val, "WaveTrend1val")
只需始终触发
True
以进行测试。 wt1
是在此函数中定义的值:
f_wavetrend(src, chlen, avg, malen, tf) =>
tfsrc = security(syminfo.tickerid, tf, src)
esa = ema(tfsrc, chlen)
de = ema(abs(tfsrc - esa), chlen)
ci = (tfsrc - esa) / (0.015 * de)
wt1 = security(syminfo.tickerid, tf, ema(ci, avg))
wt2 = security(syminfo.tickerid, tf, sma(wt1, malen))
wtVwap = wt1 - wt2
wtOversold = wt2 <= osLevel
wtOverbought = wt2 >= obLevel
wtCross = cross(wt1, wt2)
wtCrossUp = wt2 - wt1 <= 0
wtCrossDown = wt2 - wt1 >= 0
wtCrosslast = cross(wt1[2], wt2[2])
wtCrossUplast = wt2[2] - wt1[2] <= 0
wtCrossDownlast = wt2[2] - wt1[2] >= 0
[wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap]
然后使用以下代码将其绘制到我的图表中:
plot(wtShow ? wt1 : na, style = plot.style_area, title = 'WT Wave 1', color = macdWTColorsShow ? macdWT1Color : colorWT1, transp = 0)
我可以轻松地在第一个代码块的最后一行中获取
plot()
的值,但是当我尝试将浮点值转换为字符串并将其打印在警报消息中时,出现以下错误:wt1
我首先尝试在警报消息中使用
Cannot call 'alertcondition' with 'message'=series[string]. The argument should be of type: const string
打印值,但我认为这仅适用于内置占位符,例如
{{wt1}}
或 {{time}}
。看起来我正在将 {{close}}
的整个系列值转换为字符串,但我也尝试 wt1
只获取 tostring(wt1[0])
的最新值而不是整个系列,但我得到了完全相同的错误.