0

尝试将指标转换为筛选器时遇到以下错误。如果有人能给我一些如何解决这个问题的建议,我将不胜感激。在第一阶段,这个筛选器试图用预设的 40 只股票筛选带有“黄条”指标的股票。

谢谢你。

错误发生在这一行: n >= 0 ? math.round(x * mult) / mult : math.round(x / mult) * mult

**//@version=5
strategy('Custom Screener with Alerts [L3 Banker]', shorttitle='AlertsScreener[QN]', overlay=false)
////////////
// INPUTS //
xrf(values, length) =>
    r_val = float(na)
    if length >= 1
        for i = 0 to length by 1
            if na(r_val) or not na(values[i])
                r_val  :=  values[i]
                r_val
    r_val
xsa(src,len,wei) =>
    sumf = 0.0
    ma = 0.0
    out = 0.0
    sumf  :=  nz(sumf[1]) - nz(src[len]) + src
    ma  :=  na(src[len]) ? na : sumf/len
    out  :=  na(out[1]) ? ma : (src*wei+out[1]*(len-wei))/len
    out
    
//set up a simple model of banker fund flow trend   
fundtrend = ((3*xsa((close- ta.lowest(low,27))/(ta.highest(high,27)-ta.lowest(low,27))*100,5,1)-2*xsa(xsa((close-ta.lowest(low,27))/(ta.highest(high,27)-ta.lowest(low,27))*100,5,1),3,1)-50)*1.032+50)
//define typical price for banker fund
typ = (2*close+high+low+open)/5
//lowest low with mid term fib # 34
lol = ta.lowest(low,34)
//highest high with mid term fib # 34
hoh = ta.highest(high,34)
//define banker fund flow bull bear line
bullbearline = ta.ema((typ-lol)/(hoh-lol)*100,13)
//define banker entry signal
bankerentry = ta.crossover(fundtrend,bullbearline) and bullbearline<25
//banker fund entry with yellow candle
plotcandle(0,50,0,50,color=bankerentry ? color.new(color.yellow,0):na)
//banker increase position with green candle
plotcandle(fundtrend,bullbearline,fundtrend,bullbearline,color=fundtrend>bullbearline ? color.new(color.green,0):na)
//banker decrease position with white candle
plotcandle(fundtrend,bullbearline,fundtrend,bullbearline,color=fundtrend<(xrf(fundtrend*0.95,1)) ? color.new(color.white,0):na)
//banker fund exit/quit with red candle
plotcandle(fundtrend,bullbearline,fundtrend,bullbearline,color=fundtrend<bullbearline ? color.new(color.red,0):na)
//banker fund Weak rebound with blue candle
plotcandle(fundtrend,bullbearline,fundtrend,bullbearline,color=fundtrend<bullbearline and fundtrend>(xrf(fundtrend*0.95,1)) ? color.new(color.blue,0):na)
//overbought and oversold threshold lines
h1 = hline(80,color=color.red, linestyle=hline.style_dotted)
h2 = hline(20, color=color.yellow, linestyle=hline.style_dotted)
h3 = hline(10,color=color.lime, linestyle=hline.style_dotted)
h4 = hline(90, color=color.fuchsia, linestyle=hline.style_dotted)
fill(h2,h3,color=color.yellow,transp=70)
fill(h1,h4,color=color.fuchsia,transp=70)
alertcondition(bankerentry, title='Alert on Yellow Candle', message='Yellow Candle!')
alertcondition(fundtrend>bullbearline, title='Alert on Green Candle', message='Green Candle!')
alertcondition(fundtrend<(xrf(fundtrend*0.95,1)), title='Alert on White Candle', message='White Candle!')
alertcondition(fundtrend<bullbearline, title='Alert on Red Candle', message='Red Candle!')
alertcondition(fundtrend<bullbearline and fundtrend>(xrf(fundtrend*0.95,1)), title='Alert on Blue Candle', message='Blue Candle!')
// Symbols 
s01 = input.symbol('AAPL')
s02 = input.symbol('MSFT')
s03 = input.symbol('AMZN')
s04 = input.symbol('GOOGL')
s05 = input.symbol('BABA')
s06 = input.symbol('FB')
s07 = input.symbol('BRK.A')
s08 = input.symbol('V')
s09 = input.symbol('JNJ')
s10 = input.symbol('WMT')
s11 = input.symbol('TSM')
s12 = input.symbol('PG')
s13 = input.symbol('MA')
s14 = input.symbol('JPM')
s15 = input.symbol('TSLA')
s16 = input.symbol('UNH')
s17 = input.symbol('HD')
s18 = input.symbol('NVDA')
s19 = input.symbol('INTC')
s20 = input.symbol('NFLX')
s21 = input.symbol('VZ')
s22 = input.symbol('ADBE')
s23 = input.symbol('DIS')
s24 = input.symbol('T')
s25 = input.symbol('PYPL')
s26 = input.symbol('BAC')
s27 = input.symbol('NVS')
s28 = input.symbol('CSCO')
s29 = input.symbol('KO')
s30 = input.symbol('MRK')
s31 = input.symbol('PFE')
s32 = input.symbol('PEP')
s33 = input.symbol('CMCSA')
s34 = input.symbol('SAP')
s35 = input.symbol('XOM')
s36 = input.symbol('CRM')
s37 = input.symbol('ORCL')
s38 = input.symbol('TM')
s39 = input.symbol('ABBV')
s40 = input.symbol('ASML')
///////////////
// FUNCTIONS //
// Screener Function
screenerFunc() =>
    bankerentry = ta.crossover(fundtrend,bullbearline)
    cond = bullbearline < 25
    [bankerentry, cond]
// Rounding Function
roundn(x, n) =>
    mult = 1
    if n != 0
        for i = 1 to math.abs(n) by 1
            mult *= 10
            mult
    n >= 0 ? math.round(x * mult) / mult : math.round(x / mult) * mult
///////////////////////////////////////
// Running Functions for all sybmols //
[v01, c01] = request.security(s01, timeframe.period, screenerFunc())
[v02, c02] = request.security(s02, timeframe.period, screenerFunc())
[v03, c03] = request.security(s03, timeframe.period, screenerFunc())
[v04, c04] = request.security(s04, timeframe.period, screenerFunc())
[v05, c05] = request.security(s05, timeframe.period, screenerFunc())
[v06, c06] = request.security(s06, timeframe.period, screenerFunc())
[v07, c07] = request.security(s07, timeframe.period, screenerFunc())
[v08, c08] = request.security(s08, timeframe.period, screenerFunc())
[v09, c09] = request.security(s09, timeframe.period, screenerFunc())
[v10, c10] = request.security(s10, timeframe.period, screenerFunc())
[v11, c11] = request.security(s11, timeframe.period, screenerFunc())
[v12, c12] = request.security(s12, timeframe.period, screenerFunc())
[v13, c13] = request.security(s13, timeframe.period, screenerFunc())
[v14, c14] = request.security(s14, timeframe.period, screenerFunc())
[v15, c15] = request.security(s15, timeframe.period, screenerFunc())
[v16, c16] = request.security(s16, timeframe.period, screenerFunc())
[v17, c17] = request.security(s17, timeframe.period, screenerFunc())
[v18, c18] = request.security(s18, timeframe.period, screenerFunc())
[v19, c19] = request.security(s19, timeframe.period, screenerFunc())
[v20, c20] = request.security(s20, timeframe.period, screenerFunc())
[v21, c21] = request.security(s21, timeframe.period, screenerFunc())
[v22, c22] = request.security(s22, timeframe.period, screenerFunc())
[v23, c23] = request.security(s23, timeframe.period, screenerFunc())
[v24, c24] = request.security(s24, timeframe.period, screenerFunc())
[v25, c25] = request.security(s25, timeframe.period, screenerFunc())
[v26, c26] = request.security(s26, timeframe.period, screenerFunc())
[v27, c27] = request.security(s27, timeframe.period, screenerFunc())
[v28, c28] = request.security(s28, timeframe.period, screenerFunc())
[v29, c29] = request.security(s29, timeframe.period, screenerFunc())
[v30, c30] = request.security(s30, timeframe.period, screenerFunc())
[v31, c31] = request.security(s31, timeframe.period, screenerFunc())
[v32, c32] = request.security(s32, timeframe.period, screenerFunc())
[v33, c33] = request.security(s33, timeframe.period, screenerFunc())
[v34, c34] = request.security(s34, timeframe.period, screenerFunc())
[v35, c35] = request.security(s35, timeframe.period, screenerFunc())
[v36, c36] = request.security(s36, timeframe.period, screenerFunc())
[v37, c37] = request.security(s37, timeframe.period, screenerFunc())
[v38, c38] = request.security(s38, timeframe.period, screenerFunc())
[v39, c39] = request.security(s39, timeframe.period, screenerFunc())
[v40, c40] = request.security(s40, timeframe.period, screenerFunc())
////////////////////
// Screener label //
scr_label = 'Screener: \n##########\n'
scr_label := c01 ? scr_label + s01 + ' ' + str.tostring(roundn(v01, 3)) + '\n' : scr_label
scr_label := c02 ? scr_label + s02 + ' ' + str.tostring(roundn(v02, 3)) + '\n' : scr_label
scr_label := c03 ? scr_label + s03 + ' ' + str.tostring(roundn(v03, 3)) + '\n' : scr_label
scr_label := c04 ? scr_label + s04 + ' ' + str.tostring(roundn(v04, 3)) + '\n' : scr_label
scr_label := c05 ? scr_label + s05 + ' ' + str.tostring(roundn(v05, 3)) + '\n' : scr_label
scr_label := c06 ? scr_label + s06 + ' ' + str.tostring(roundn(v06, 3)) + '\n' : scr_label
scr_label := c07 ? scr_label + s07 + ' ' + str.tostring(roundn(v07, 3)) + '\n' : scr_label
scr_label := c08 ? scr_label + s08 + ' ' + str.tostring(roundn(v08, 3)) + '\n' : scr_label
scr_label := c09 ? scr_label + s09 + ' ' + str.tostring(roundn(v09, 3)) + '\n' : scr_label
scr_label := c10 ? scr_label + s10 + ' ' + str.tostring(roundn(v10, 3)) + '\n' : scr_label
scr_label := c11 ? scr_label + s11 + ' ' + str.tostring(roundn(v11, 3)) + '\n' : scr_label
scr_label := c12 ? scr_label + s12 + ' ' + str.tostring(roundn(v12, 3)) + '\n' : scr_label
scr_label := c13 ? scr_label + s13 + ' ' + str.tostring(roundn(v13, 3)) + '\n' : scr_label
scr_label := c14 ? scr_label + s14 + ' ' + str.tostring(roundn(v14, 3)) + '\n' : scr_label
scr_label := c15 ? scr_label + s15 + ' ' + str.tostring(roundn(v15, 3)) + '\n' : scr_label
scr_label := c16 ? scr_label + s16 + ' ' + str.tostring(roundn(v16, 3)) + '\n' : scr_label
scr_label := c17 ? scr_label + s17 + ' ' + str.tostring(roundn(v17, 3)) + '\n' : scr_label
scr_label := c18 ? scr_label + s18 + ' ' + str.tostring(roundn(v18, 3)) + '\n' : scr_label
scr_label := c19 ? scr_label + s19 + ' ' + str.tostring(roundn(v19, 3)) + '\n' : scr_label
scr_label := c20 ? scr_label + s20 + ' ' + str.tostring(roundn(v20, 3)) + '\n' : scr_label
scr_label := c21 ? scr_label + s21 + ' ' + str.tostring(roundn(v21, 3)) + '\n' : scr_label
scr_label := c22 ? scr_label + s22 + ' ' + str.tostring(roundn(v22, 3)) + '\n' : scr_label
scr_label := c23 ? scr_label + s23 + ' ' + str.tostring(roundn(v23, 3)) + '\n' : scr_label
scr_label := c24 ? scr_label + s24 + ' ' + str.tostring(roundn(v24, 3)) + '\n' : scr_label
scr_label := c25 ? scr_label + s25 + ' ' + str.tostring(roundn(v25, 3)) + '\n' : scr_label
scr_label := c26 ? scr_label + s26 + ' ' + str.tostring(roundn(v26, 3)) + '\n' : scr_label
scr_label := c27 ? scr_label + s27 + ' ' + str.tostring(roundn(v27, 3)) + '\n' : scr_label
scr_label := c28 ? scr_label + s28 + ' ' + str.tostring(roundn(v28, 3)) + '\n' : scr_label
scr_label := c29 ? scr_label + s29 + ' ' + str.tostring(roundn(v29, 3)) + '\n' : scr_label
scr_label := c30 ? scr_label + s30 + ' ' + str.tostring(roundn(v30, 3)) + '\n' : scr_label
scr_label := c31 ? scr_label + s31 + ' ' + str.tostring(roundn(v31, 3)) + '\n' : scr_label
scr_label := c32 ? scr_label + s32 + ' ' + str.tostring(roundn(v32, 3)) + '\n' : scr_label
scr_label := c33 ? scr_label + s33 + ' ' + str.tostring(roundn(v33, 3)) + '\n' : scr_label
scr_label := c34 ? scr_label + s34 + ' ' + str.tostring(roundn(v34, 3)) + '\n' : scr_label
scr_label := c35 ? scr_label + s35 + ' ' + str.tostring(roundn(v35, 3)) + '\n' : scr_label
scr_label := c36 ? scr_label + s36 + ' ' + str.tostring(roundn(v36, 3)) + '\n' : scr_label
scr_label := c37 ? scr_label + s37 + ' ' + str.tostring(roundn(v37, 3)) + '\n' : scr_label
scr_label := c38 ? scr_label + s38 + ' ' + str.tostring(roundn(v38, 3)) + '\n' : scr_label
scr_label := c39 ? scr_label + s39 + ' ' + str.tostring(roundn(v39, 3)) + '\n' : scr_label
scr_label := c40 ? scr_label + s40 + ' ' + str.tostring(roundn(v40, 3)) + '\n' : scr_label
// Adding #telegram hashtag for alertatron
scr_label += '\n #telegram'
// Plot Label
lab_l = label.new(bar_index, 0, scr_label, color=color.gray, textcolor=color.black, style=label.style_label_down, yloc=yloc.price)
label.delete(lab_l[1])
plot(0, transp=100)
////////////////////
// Dummy strategy //
if timeframe.isintraday and time >= timestamp(year(timenow), month(timenow), dayofmonth(timenow), 00, 00)
    strategy.entry('dummy_long', strategy.long, when=strategy.position_size[1] == 0 and barstate.isconfirmed, alert_message=scr_label)
    strategy.close('dummy_long', when=strategy.position_size[1] != 0 and barstate.isconfirmed, alert_message=scr_label)
if not timeframe.isintraday and time >= timenow - 30 * 1000 * 60 * 60 * 24
    strategy.entry('dummy_long', strategy.long, when=strategy.position_size[1] == 0 and barstate.isconfirmed, alert_message=scr_label)
    strategy.close('dummy_long', when=strategy.position_size[1] != 0 and barstate.isconfirmed, alert_message=scr_label)**
4

0 回答 0