如何解决当条件来自安全功能时,“警报条件”失败
我正在尝试根据源自安全功能的条件创建警报。
下面是相关的代码段和 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 %",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,color=color.red,width= 3,extend=extend.none)
var lowerLimitLine = line.new(na,color=color.black,extend=extend.none)
var upperRangeLine = line.new(na,color=color.blue,width= 2,extend=extend.none)
var lowerRangeLine = line.new(na,color=color.green,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,screenerFunc())
// c03 = security(s03,screenerFunc())
// c04 = security(s04,screenerFunc())
// c05 = security(s05,screenerFunc())
// c06 = security(s06,screenerFunc())
// c07 = security(s07,screenerFunc())
// c08 = security(s08,screenerFunc())
// c09 = security(s09,screenerFunc())
// c10 = security(s10,screenerFunc())
// c11 = security(s11,screenerFunc())
// c12 = security(s12,screenerFunc())
// c13 = security(s13,screenerFunc())
// c14 = security(s14,screenerFunc())
// c15 = security(s15,screenerFunc())
// c16 = security(s16,screenerFunc())
// c17 = security(s17,screenerFunc())
// c18 = security(s18,screenerFunc())
// c19 = security(s19,screenerFunc())
// c20 = security(s20,screenerFunc())
// PAINTBRUSH
// line.set_xy1(upperLimitLine,xAxisStartsAt,upperLimit)
// line.set_xy2(upperLimitLine,xAxisFinishesAt,upperLimit)
// line.set_xy1(lowerLimitLine,lowerLimit)
// line.set_xy2(lowerLimitLine,lowerLimit)
// line.set_xy1(upperRangeLine,upperRange)
// line.set_xy2(upperRangeLine,upperRange)
// line.set_xy1(lowerRangeLine,lowerRange)
// line.set_xy2(lowerRangeLine,lowerRange)
plotchar(screenerFunc())
// ALERTS
alertcondition(c01,title="Alert",message="Alert!")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。