Error: More than 60 upvalues

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Error: More than 60 upvalues

Postby MrRiversideDude » Wed May 21, 2014 5:51 am

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!!
MrRiversideDude
 
Posts: 87
Joined: Fri Feb 21, 2014 7:50 am

Re: Error: More than 60 upvalues

Postby Valeria » Thu May 22, 2014 2:43 am

Hi MrRiversideDude,

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

Re: Error: More than 60 upvalues

Postby MrRiversideDude » Thu May 22, 2014 11:06 pm

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...
MrRiversideDude
 
Posts: 87
Joined: Fri Feb 21, 2014 7:50 am

Re: Error: More than 60 upvalues

Postby moomoofx » Fri May 23, 2014 8:52 pm

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
User avatar
moomoofx
FXCodeBase: Confirmed User
 
Posts: 193
Joined: Wed Oct 23, 2013 10:26 pm
Location: Okinawa, Japan. http://moomooforex.com


Return to Discussions

Who is online

Users browsing this forum: No registered users and 4 guests