I'm trying to create a screener, but atm getting the error msg Cannot use a mutable variable as an argument of the security function
for one of the lines of the code above.
The line with error is: c01 = security(s01, timeframe.period, condition)
so I'm guessing my condition
is flawed, but I've seen similar code working and can't figure it out the issue.
And btw I did see this thread, but can't understand how this apply here.
Below is (hopefully) the relevant part of the code, and you can find the entire code here in case you'd like to see it and/or re-use it.
Appreciate your help!
lookBack = input(title="Lookback", type=input.integer, defval=24, minval=2)
range = input(title="Upper & Lower Range %", type=input.integer, defval=25, minval=10)
s01 = input('BINANCE:BTCUSDT', type=input.symbol)
highestHigh = highest(high, lookBack)
lowestLow = lowest(low, lookBack)
upperRange = highestHigh - ((highestHigh - lowestLow)/range)
lowerRange = ((highestHigh - lowestLow)/range) + lowestLow
HighAboveUpperRange = high > upperRange
LowBelowLowerRange = low < lowerRange
occurrencesAbove = sum(HighAboveUpperRange ? 1 : 0, lookBack)
triggerA = occurrencesAboveFirstHalf >= 1 ? true : false
triggerB = crossunder(low, lowerRange)
condition = triggerA and triggerB
c01 = security(s01, timeframe.period, condition)
scr_label := c01 ? scr_label + s01 + '
' : scr_label
lab_l = label.new(
bar_index, 0, scr_label,
color=color.gray,
textcolor=color.black,
style = label.style_labeldown,
yloc = yloc.price)
label.delete(lab_l[1])
plot(0, transp = 100)
UPDATE:
I have updated my condition to a function and my security function accordingly like so:
screenerFunc() => triggerA and triggerB and triggerC and triggerD
security(s01, res, screenerFunc())
The security function still returns the Cannot use a mutable variable as an argument of the security function
though.
I have also updated the entire code here.
question from:
https://stackoverflow.com/questions/65649108/security-functions-returing-cannot-use-a-mutable-variable-as-an-argument 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…