Page 1 of 1

Error: More than 60 upvalues

PostPosted: Wed May 21, 2014 5:51 am
by MrRiversideDude
Hi,

I started getting this error message after I add the HA indicator. If I comment out the last two lines the error message goes away. HELP!!

Code snippet:
function ExtUpdate(id, source, period)
local Precision = source:getPrecision();

fast:update(core.UpdateLast);
slow:update(core.UpdateLast);
macd:update(core.UpdateLast);
HA:update(core.UpdateLast);

message = "";
messageFTR = "";
messageHDR = "";
messageFTRCnt = 0;
messageHDRCnt = 0;
messageTRDCnt = 0;
msg = "";
TradeSignal = nil;
trend = 0;

BuySignal = 0;
OpenTrade = false;
SellSignal = 0;

if (period >= source:first() + N) then
for i = 0, N - 1 do

CLOSE = source.close[period];
MA = fast.DATA[period];
SMA = slow.DATA[period];
MACD = macd.DATA[period];
SIGNAL = macd:getStream(1)[period];
HIST = macd:getStream(2)[period];

CLOSEPrev = source.close[period-1];
MAPrev = fast.DATA[period-1];
SMAPrev = slow.DATA[period-1];
MACDPrev = macd.DATA[period-1];
SIGNALPrev = macd:getStream(1)[period-1];
HISTPrev = macd:getStream(2)[period-1];

HAClose = HA.close[period];
HAClosePrev = HA.close[period-1];

Thanks in advance!!

Re: Error: More than 60 upvalues

PostPosted: Thu May 22, 2014 2:43 am
by Valeria
Hi MrRiversideDude,

Unfortunately, it is a Lua limitation. Probably you will find the solution on the Internet.

Re: Error: More than 60 upvalues

PostPosted: Thu May 22, 2014 11:06 pm
by MrRiversideDude
I found the answer:

http://stackoverflow.com/questions/1204 ... 0-upvalues

Maximum 60 upvalues, that is values from outer scopes that your closure is closed over, is one of internal Lua limits. Of course you can change it by recompiling Lua itself, but I'd advise against it. Pack your values in some table instead, with its layout dictated by logic of code. In your particular example you really should be using:

local a = {}
a[1] = 1
a[2] = 2
a[3] = 3
a[4] = 3
a[5] = 3
-- etc...

Re: Error: More than 60 upvalues

PostPosted: Fri May 23, 2014 8:52 pm
by moomoofx
MrRiversideDude,

Correct me if I'm wrong, but I think you can also break it up into multiple functions. So, move some code into a function like:

Code: Select all
function SetPrevValues(period)
    CLOSEPrev = source.close[period-1];
    MAPrev = fast.DATA[period-1];
    SMAPrev = slow.DATA[period-1];
    MACDPrev = macd.DATA[period-1];
    SIGNALPrev = macd:getStream(1)[period-1];
    HISTPrev = macd:getStream(2)[period-1];
end


and then call SetPrevValues(period) from the Update() function.

I'd hate to switch everything to a table.

Cheers,
MooMooFX