“警报条件"当条件来自安全功能时失败 [英] "alertcondition" fails when the condition comes from a security function

查看:52
本文介绍了“警报条件"当条件来自安全功能时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据源自安全功能的条件创建警报.

I'm trying to create alerts based on conditions that derive from security functions.

下面是代码的相关部分,这里是完整代码.

Below, the relevant piece of the code, and 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!")

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

But I'm getting the following error for the last line:

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

感谢您的帮助!

推荐答案

代码中存在两个问题,第一,函数screenerFunc必须将所有字符串组合起来计算条件,第二, 在计算范围.字符串画线也被注释掉了,因为我不知道它们与哪个股票相关.

There were two problems in the code, the first, the function screenerFunc must combine all the strings to calculate the condition, the second, in calculating the range. Strings with drawing lines are also commented out, since I don't know for which ticker they are relevant.

//@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!")

这篇关于“警报条件"当条件来自安全功能时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆