Bug in the EL core compiler/interpreter

Questions about MultiCharts and user contributed studies.
User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Bug in the EL core compiler/interpreter

Postby c0ntango » 03 Jan 2021

Hey everyone,

It seems like I may have found a bug in the way EL gets interpreted and translated into C++. I have confirmed this bug in MC12, MC14 and also the most recent version of TS - which means I'm either doing something wrong, or it's been like that since the start, and the problem itself might be at the core of the language itself.

In short: if we create an array, and based on a loop the array's contents are varied, and then we are calling a function with the contents of this array, and we are saving the return value to another array, indexed by the same loop - the results array will have incorrect results.

I have attached a piece of code - including a function and a signal that calls it. Could I ask some experienced people to take a look at this, look through the comments and either confirm the bug or let me know if I'm doing something wrong?

-Ben
Attachments
el_bug.pla
(7.24 KiB) Downloaded 93 times

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Bug in the EL core compiler/interpreter

Postby TJ » 03 Jan 2021

I don't install codes in my computer. You have to post the text file.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Bug in the EL core compiler/interpreter

Postby TJ » 03 Jan 2021

Not sure if this is the problem:

Check your counting . . .

Some counting start with ZERO,
Some counting start with ONE . . .

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby c0ntango » 03 Jan 2021

No TJ, that's not the problem. This is an actual bug in EL, I believe, however unlikely that sounds :)

Sounds like you opened it up anyway. Do you still want me to post the text files?

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby rrams » 03 Jan 2021

Hi c0ntango,
Hope you don't mind my opinion: I wouldn't technically call this a bug. This does give unexpected behavior, but a true software bug is if there is no way of producing an intended functionality. (Although in an academic setting there would be marks off for this design.)
So the question becomes how do you correctly write a function that sums negative integers in an array? Well you just have to implicitly inform the compiler to typecast the variable as a signed long integer instead of just an unsigned integer. In the function don't use variable1, use:

Code: Select all

inputs: Trades[size](NumericArray); vars: loop(0), negnum(-1); negnum=0; loop=0; while loop<=array_getmaxindex(Trades) begin negnum+=Trades[loop]; loop+=1; end;
Does this accomplish what you want? You can submit this as a bug if you wish, but they have plenty of other things to work on.

wegi
Posts: 124
Joined: 02 Jun 2009
Has thanked: 5 times
Been thanked: 13 times

Re: Bug in the EL core compiler/interpreter

Postby wegi » 04 Jan 2021

Interesting.

When you manually init your value1 in your function then it works.
Just add this line in your function: elbug_func

Code: Select all

loop = 0; //Add, this line value1 = 0;
the question is why this variable is not initialized with 0 on every function call?

Here is the whole function:

Code: Select all

inputs: Trades[size] (NumericArray); vars: loop (00), CurrentEquity (00), EquityHigh (00), CurrentDrawDown (00), MaxDrawdown (00), val(0) ; loop = 0; //Why has this variable to be resetted? //Function is with function storage: simple value1 = 0; while loop <= array_getmaxindex(Trades) begin value1 = value1 + Trades[loop]; { Uncommenting the line below - strangely - seemingly goes around the bug somehow and returns correct results. } // if Trades[loop] < 0 then value1 = Trades[loop]; loop += 1; end; elbug_funct = value1 ;

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby c0ntango » 04 Jan 2021

Wow. I asked for the support of extremely senior developers - and I got it. :)

I appreciate both of you guy's help, time and advice.

Thank you!

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby c0ntango » 04 Jan 2021

Hey Everyone,

Just an update here:

- I would definitely say this is a bug,
- The "factory defined" value1 variable has no impact on this, it happens with any variable,
- rrams solution actually didn't solve it, but wegi's solution does make the code behave as expected.

Anyway - I don't know if it's high enough priority to put in the project management system, I know MC team is busy fixing the unexpected behaviors of v14 and have plenty to work on in general. So we're all just better off initializing the variables at the starts of functions I guess.

-Ben

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby c0ntango » 04 Jan 2021

Hey Everyone,

A second update. I don't think this has anything to do with arrays anymore. It is due to what is probably a design flaw in the interpreter itself, and what it looks like is when you call a function multiple times with different parameters in the same piece of code on the same bar, the variables in it will not be reset automatically. The easiest way to see it is if you take an input parameter and you add it to the variable's existing value with += or similar. I seriously doubt this is intentional and under certain circumstances it can have serious and far reaching consequences. Please check your code if you operate under such conditions.

-Ben

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Bug in the EL core compiler/interpreter

Postby TJ » 04 Jan 2021

See post #5
5. Stop Banging Your Head Against the Wall and Open Your Eyes.
viewtopic.php?t=11713

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby c0ntango » 04 Jan 2021

TJ, man, come on, this is dummy code written for just the purpose of demonstrating this bug. :)

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: Bug in the EL core compiler/interpreter

Postby syswizard » 06 Jan 2021

Just a comment Dude: I didn't know this was even supported:

Code: Select all

negnum+=Trades[loop]; loop+=1;
Did you try ?:

Code: Select all

negnum=negnum + Trades[loop]; loop = loop + 1;
It's been my experience that the interpreter parsing is weak.
I remember banging my head against the wall on this one:
Begin Once
Value1 = 10;
End;
Important: No error was thrown, but it wasn't working.
Then I had been told THAT'S NOT SUPPORTED, You must do this:
Once Begin
Value1 = 10;
End;

I was like: "Why wasn't an error thrown ?" Welcome to Power Language....full of surprises.

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Bug in the EL core compiler/interpreter

Postby c0ntango » 06 Jan 2021

LOL. That's a good one.

Yeah += is supported, man :)


Return to “MultiCharts”