[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unusual Array Call



PureBytes Links

Trading Reference Links

Here's a query that doesn't appear in the manual... ;~)

Please examine the following indicator code that is applied to a 500 bar
chart:

--------------------------------------------------------------------------

Input:  Price((H+L+C)/3);

Vars:  ALoopCount(0), MyClose(0), CallFunction(0);

Array: MyArray[100,2](0);   {100x2 array filled with 0's}

MyClose = Close;
Print(ALoopCount, MyClose);
CallFunction = MyFunction(Price, MyArray);
ALoopCount = ALoopCount+1;

If MyArray[1,2] > 0 then begin  {Wait for MyArray to fill up}
    Print(ALoopCount);              {Print Final ALoopCount}
    Print(CurrentBar);                {Print How many bars we sent to the
Function, = ALoopCount}
    For XX = CurrentBar-1 downto 0 begin
        Print(MyClose[XX]);
    end;
end;

--------------------------------------------------------------------------

Now the Function's inputs are:

Price(numericSimple);
MyArray(numericArrayRef);

So, what I intend to happen is for MyFunction to be called on every bar. All
the code after the If...Then is ignored until MyArray is filled. MyFunction
always waits for the LastBarOnChart before it populates MyArray.

So after the first run through the data, the following should be true:

1) MyArray is filled, and is available to the calling code. And indeed, it
is.
2) MyClose, a serial variable, should be populated going back to the very
first bar.

Here's the puzzle:

The first Print Statement correctly shows 500 values of MyClose with the
matching ALoopCount. So that part of the code did indeed execute on every
bar.

The ALoopCount and CurrentBar Print statements show that the current bar is
still at 500 after the If...then statement, which I'd expect.

However, the second Print Statement inside the XX loop, shows only one value
for MyClose for the entire 500 values (and it's not 0, and it's not from the
lastbaronchart either), as if MyClose forgot it's history.

Any takers?

Best regards,

Gene Pope