PureBytes Links
Trading Reference Links
|
I have a good one for you. This, to me, is a big example of how completely
non-intuitive EL & TS can be (I am not a neophyte programmer, either).
I've been working with the Hashnums DLL to put some code in functions in order
to visually clean up my main system. I discovered, to my chagrin, that the
order in which a function gets processed can be BACKWARDS to what you want and
expect.
I removed all references to Hashnums and everything else in my code (they were
not the problem), and eventually I whittled it down to the essence of what was
causing the problem. Let me give the code so that its more clear what I'm
saying:
{*********************************************************
Testing the order in which functions are executed.
MAIN PROGRAM
********************************************************}
vars: x(0), y(0);
if barnumber < 5 then
FILEAPPEND("C:\OMEGA\PROG\TEST.TXT", "Main, " + Numtostr(barnumber, 0) +
Newline);
x = CurrentContracts;
y = x[1];
value1 = testorderfunc1;
value2 = testorderfunc2;
{****************************************
Testing the order in which functions are executed.
FUNCTION 1
*******************************************}
VARS: x(0), y(0);
if barnumber < 5 then
FILEAPPEND("C:\OMEGA\PROG\TEST.TXT", "Func 1, " + Numtostr(barnumber, 0) +
Newline);
x = CurrentContracts;
y = x[1];
testorderfunc1 = 1;
{****************************************
Testing the order in which functions are executed.
FUNCTION 2
*******************************************}
vars: x(0), y(0);
if barnumber < 5 then
FILEAPPEND("C:\OMEGA\PROG\TEST.TXT", "Func 2, " + Numtostr(barnumber, 0) +
Newline);
x = CurrentContracts;
y = x[1];
testorderfunc2 = 1;
=======================
That's all there is to it. If you run this code on a chart, you will get the
following in the TEST.TXT file. Note that the number after the comma is the
barnumber:
Func 2, 1
Func 1, 1
Main, 1
Func 2, 2
Func 1, 2
Main, 2
Func 2, 3
Func 1, 3
Main, 3
Func 2, 4
Func 1, 4
Main, 4
If you comment out all of the
y = x[1];
lines you get the order you want and expect, which would be
Main, 1
Func 1, 1
Func 2, 1
Main, 2
Func 1, 2
Func 2, 2
Anyone have any ideas or comments on why this occurs and what can be done
about it? Am I missing something?
Thanks,
Chris
|