Reputation: 1
I get an error message when I try to run this function:
adopt(r,s) =>
request.security(syminfo.tickerid,r,s,lookahead=barmerge.lookahead_on)
[low1,high1,open1,close1]=adopt('W',[low[1],high[1],open[1],close[1]])
The error: Invalid assignment. Cannot assign a tuple to a variable.
If I remove lookahead=barmerge.lookahead_on
then it runs fine. It's important to me that it stays in the function.
If I try to receive only one value then it also works properly but then I have to run the command 4 times instead of once low1=adopt('W',low[1]),high1=adopt('W',high[1])...
Is there a way to run the function with "lookahead" and get 4 values in one command?
Upvotes: 0
Views: 600
Reputation: 1435
You can do something like this. One function that calculates all four values and then returns a tuple.
I left the label at the end for debugging as well.
adopt() =>
adoptLow = request.security(syminfo.tickerid,'D', low, lookahead = barmerge.lookahead_on)[1]
adoptHigh = request.security(syminfo.tickerid,'D', high, lookahead = barmerge.lookahead_on)[1]
adoptOpen = request.security(syminfo.tickerid,'D', open, lookahead = barmerge.lookahead_on)[1]
adoptClose = request.security(syminfo.tickerid,'D', close, lookahead = barmerge.lookahead_on)[1]
[adoptLow, adoptHigh, adoptOpen, adoptClose]
[low1, high1, open1, close1] = adopt()
if barstate.islast
label.new(bar_index, low, 'Prev Low: ' + str.tostring(low1, format.mintick) + '\n' +
'Prev High: ' + str.tostring(high1, format.mintick) + '\n' +
'Prev Open: ' + str.tostring(open1, format.mintick) + '\n'+
'Prev Close: ' + str.tostring(close1, format.mintick), textcolor = color.white, style = label.style_label_up)
Upvotes: 0