"alertcondition" 当条件来自安全功能时失败

"alertcondition" fails when the condition comes from a security function

我正在尝试根据安全功能派生的条件创建警报。

下面是相关的代码,here is the entire code.

s01 = input('BINANCE:BTCUSDT', type=input.symbol)
screenerFunc() => triggerA and triggerB
c01 = security(s01, res, screenerFunc())
alertcondition(condition=c01, title="Alert", message="Alert!")

但是最后一行出现以下错误:

Cannot use a mutable variable as an argument of the security function.

感谢帮助!

代码中有两个问题,第一,函数screenerFunc必须结合所有字符串来计算条件,第二,计算范围。字符串 带有绘图线的也被注释掉了,因为我不知道它们与哪个自动收报机相关。

//@version=4
//42quants.com
//@42piratas

study("Grid Bots Screening", overlay=true)

// INPUTS

res = input(type=input.resolution, defval="60", title="Resolution")
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
range = input(title="Upper & Lower Range %", type=input.integer, defval=25, minval=10)

screenList  = input(false, "═════════ Screening ════════")
s01 = input('BINANCE:BTCUSDT', type=input.symbol)
s02 = input('BINANCE:ETHBTC', type=input.symbol)
s03 = input('BINANCE:XRPBTC', type=input.symbol)
s04 = input('BINANCE:LTCBTC', type=input.symbol)
s05 = input('BINANCE:BCHBTC', type=input.symbol)

s06 = input('BINANCE:LINKBTC', type=input.symbol)
s07 = input('BINANCE:ADABTC', type=input.symbol)
s08 = input('BINANCE:DOTBTC', type=input.symbol)
s09 = input('BINANCE:BNBBTC', type=input.symbol)
s10 = input('BINANCE:XLMBTC', type=input.symbol)

s11 = input('BINANCE:SNXBTC', type=input.symbol)
s12 = input('BINANCE:XMRBTC', type=input.symbol)
s13 = input('BINANCE:EOSBTC', type=input.symbol)
s14 = input('BINANCE:XEMBTC', type=input.symbol)
s15 = input('BINANCE:WBTCBTC', type=input.symbol)

s16 = input('BINANCE:TRXBTC', type=input.symbol)
s17 = input('BINANCE:XTZBTC', type=input.symbol)
s18 = input('BINANCE:COMPBTC', type=input.symbol)
s19 = input('BINANCE:FILBTC', type=input.symbol)
s20 = input('BINANCE:MKRBTC', type=input.symbol)

// INDICATORS & VARIABLES

var upperLimitLine = line.new(na, na, na, na, color=color.red,  width= 3, extend=extend.none)
var lowerLimitLine = line.new(na, na, na, na, color=color.black,  width= 3, extend=extend.none)
var upperRangeLine = line.new(na, na, na, na, color=color.blue, width= 2, extend=extend.none)
var lowerRangeLine = line.new(na, na, na, na, color=color.green, width= 2, extend=extend.none)

var range_corr = 100/range // the error was here

screenerFunc() => 
    
    highestHigh = highest(high, lookBack)
    lowestLow = lowest(low, lookBack)
    
    xAxisStartsAt = bar_index[lookBack]
    xAxisFinishesAt = bar_index
    
    upperLimit = highestHigh
    lowerLimit = lowestLow
    
    upperRange = highestHigh - ((highestHigh - lowestLow)/range_corr) 
    lowerRange = ((highestHigh - lowestLow)/range_corr) + lowestLow
    
    HighAboveUpperRange = high > upperRange
    LowBelowLowerRange = low < lowerRange
    
    occurrencesAboveTotal   = sum(HighAboveUpperRange ? 1 : 0, lookBack)
    occurrencesAboveSecondHalf = sum(HighAboveUpperRange ? 1 : 0, lookBack/2)
    occurrencesAboveFirstHalf  = occurrencesAboveTotal - occurrencesAboveSecondHalf
    
    occurrencesBelowTotal   = sum(LowBelowLowerRange ? 1 : 0, lookBack)
    occurrencesBelowSecondHalf = sum(LowBelowLowerRange ? 1 : 0, lookBack/2)
    occurrencesBelowFirstHalf  = occurrencesBelowTotal - occurrencesBelowSecondHalf
    
    // SCREENING
    
    triggerA = occurrencesAboveFirstHalf >= 1 ? true : false
    triggerB = occurrencesAboveSecondHalf >= 1 ? true : false
    triggerC = occurrencesBelowFirstHalf >= 1 ? true : false
    triggerD = crossunder(low, lowerRange)
    
    triggerA and triggerB and triggerC and triggerD

c01 = security(s01, res, screenerFunc())
// c02 = security(s02, res, screenerFunc())
// c03 = security(s03, res, screenerFunc())
// c04 = security(s04, res, screenerFunc())
// c05 = security(s05, res, screenerFunc())

// c06 = security(s06, res, screenerFunc())
// c07 = security(s07, res, screenerFunc())
// c08 = security(s08, res, screenerFunc())
// c09 = security(s09, res, screenerFunc())
// c10 = security(s10, res, screenerFunc())

// c11 = security(s11, res, screenerFunc())
// c12 = security(s12, res, screenerFunc())
// c13 = security(s13, res, screenerFunc())
// c14 = security(s14, res, screenerFunc())
// c15 = security(s15, res, screenerFunc())

// c16 = security(s16, res, screenerFunc())
// c17 = security(s17, res, screenerFunc())
// c18 = security(s18, res, screenerFunc())
// c19 = security(s19, res, screenerFunc())
// c20 = security(s20, res, screenerFunc())

// PAINTBRUSH

// line.set_xy1(upperLimitLine, xAxisStartsAt, upperLimit)
// line.set_xy2(upperLimitLine, xAxisFinishesAt, upperLimit)

// line.set_xy1(lowerLimitLine, xAxisStartsAt, lowerLimit)
// line.set_xy2(lowerLimitLine, xAxisFinishesAt, lowerLimit)

// line.set_xy1(upperRangeLine, xAxisStartsAt, upperRange)
// line.set_xy2(upperRangeLine, xAxisFinishesAt, upperRange)

// line.set_xy1(lowerRangeLine, xAxisStartsAt, lowerRange)
// line.set_xy2(lowerRangeLine, xAxisFinishesAt, lowerRange)

plotchar(screenerFunc())

// ALERTS
alertcondition(c01, title="Alert", message="Alert!")