松脚本循环

时间:2020-10-14 10:44:06

标签: loops pine-script tradingview-api

我正在尝试创建一个脚本,其中tradingview显示带有所有代码结果的标签。我真的很想一个循环,以获取代码来捕获多个行情自动收录器(heiken ashi图表)的所有数据。下面的代码无法正常工作。

因此,对于每个代码,循环都需要检查result = true,如果是,则需要将代码添加到标签:

s20ema = ema(close, 20)
s50sma = sma(close, 50)
s200sma = sma(close, 200)

scr_label = 'Screener: \n##########\n'

ticker_s1 = 'ADAUSDT'
ticker_s2 = 'ADXBTC'
ticker_s3 = 'AEBTC'
ticker_s4 = 'AGIBTC'
ticker_s5 = 'AIONBTC'

ha_period = "W" // Chart on which Master Direction is based
ha_open = security(heikinashi(ticker_s1), ha_period, open)
ha_close = security(heikinashi(ticker_s1), ha_period, close)

customFuncW() => (s20ema > s50sma) and (s50sma > s200sma) and (ha_close < ha_open)

s1  = security(ticker_s1,  'W', customFuncW())
s2  = security('ADXBTC',  'W', customFuncW())
s3  = security('AEBTC',  'W', customFuncW())
s4  = security('AGIBTC',  'W', customFuncW())
s5  = security('AIONBTC',  'W', customFuncW())

s = 1
for i = 0 to 5 
    s := s + 1
    scr_label := s[i] ? scr_label + ticker_s[i] + '\n' : scr_label  

lab_l = label.new(
    bar_index, -0.2, scr_label, 
    color=color.gray, 
    textcolor=color.black, 
    style =  label.style_labeldown,
    yloc = yloc.price)

label.delete(lab_l[1])

plot(0, transp = 100)

这段代码给了我一个'uneclarer标识符'ticker_s''(for循环中的那个)。有人有主意吗?谢谢!

1 个答案:

答案 0 :(得分:0)

变量 i=0 的 for 循环 starta 所以第一个得到 s[0]

并且没有声明 s0 我认为你应该从 I=1 开始