PureBytes Links
Trading Reference Links
|
Hi Jim,
Although Howard gave me a very clear and simple explanation, you'll find
here below what the techsupp answered me about NumericArrayRef and
NumericArray :
In regards to using Array declarations in functions, here is more detailed
information you can use:
Passing Variables by reference
The most common example used in any programming textbook is the swap()
function. What this function does is it receives two variables and swaps
their value, returning 0 if successful and 1 if it had problems.
We added new keywords to the language that will allow functions to receive
variables by reference, these names are
NumericRef
TrueFalseRef
StringRef
So when writing functions, we will be able to specify that a certain
parameter will be a variable that we will use by reference. Here would be
the syntax for the swap function:
Swap Function
Inputs: varA(numericRef), varB(numericRef);
Variable: temp(0);
Temp = varA;
VarA = varB;
VarB = temp;
Swap = 0;
Then this function can be used by an indicator the following way:
Indicator test
Variable; x(0);
If BarNumber = 1 then begin
Value1 = 1;
Value2 = -1;
End;
X = Swap(value1, value2);
Plot1(value1);
Plot2(value2);
When you plot this indicator, you will see that value1 and value2 swap
values on every bar. Note that the function Swap is effectively returning
three values: it returns a result like any other function which in this
example is stored in the variable x¸ and by modifying the values of the
variables value1 and value2 it is returning two additional values.
In this example we are not using the returning value of the function (which
we store in the variable x), but this value can easily be put to use, for
example in more complex operation which might succeed or fail (like
searching for a bar patter) you can return 0 if successful and 1 if the
function failed.
Note: currently you can not pass array elements to a function that receive
variables addressed by reference, for example in the above indicator the
following would not work:
Indicator test
Variable; x(0);
Array: Myarray[2](0);
If BarNumber = 1 then begin
Myarray[1] = 1;
MyArray[2] = -1;
End;
X = Swap(MyArray[1],Myarray[2]);
Plot1(MyArray[1]);
Plot2(MyArray[2]);
The function will not be able to effectively change the values for the array
elements. No errors will occur, the array elements will remain unchanged.
Passing arrays by value
Many times you wish to perform an operation on an array to get one value off
it. For example, you might want to see what is the greatest value of the
array, but since you repeatedly do this in your analysis techniques, you do
not want to write the loop over and over. For these purposes you are able
to pass an array to a function. Lets see an example:
Suppose you were keeping an array in indicator that has the price of the
last 10 swing highs. You can write a function that will return the value
of the highest element of the array as follows:
Function HighestElement()
Input: theArray[n](NumericArray);
vars: hh(0);
hh = -999999;
For value1 = 0 to n begin
if theArray[value1] > hh then
hh = theArray[value1];
end;
highestElement = hh;
Then form the indicator, you can write:
{ here would be the instructions to keep the array updated }
value1 = HighestElement(myArray);
Plot1(value1);
Note that you will not be able to modify the values of the array inside the
function.
Passing arrays by reference
Many times you will want to send an array into a function in order for it to
be modified in some way and have the change reflected in the original
EasyLanguage document. For instance, you might want to keep an array in
your indicator, and have a function sort it and return the array completely
sorted. In order to address this, you can write the following function:
Sort Function
Input: theArray[n](numericArrayRef);
Vars: temp(0), changes(true);
Changes = true;
While changes Begin
Changes = false;
For value1 = 0 to n-1 begin
If theArray[value1] < theArray[value1+1]
then begin
Temp = theArray[value1];
theArray[value1] =
theArray[value1+1];
theArray[value1+1] =
theArray[value1];
changes = true;
end;
end;
end;
Sort = 0;
The above function is a common 'bubble sort' procedure. What it does is
that it goes through each element of the array, comparing it to the next
element. If they are not in the correct order it swaps their value and
continues doing this until it reaches the bottom of the array. This
function will continue to pass through the array until no swaps are made in
one pass, only then the array is considered ordered.
In order to call this function from an indicator, you will have to use the
following syntax
Indicator test
Variable; x(0);
Array: Myarray[200](0);
{instructions that maintain the array}
X = Sort(MyArray);
Plot1(MyArray[0]);
After the Sort() function is called, the array will be sorted from that
point on in the indicator.
General notes about working with arrays:
When functions receive arrays from other analysis techniques, they will have
the following syntax in the input declaration:
Input: theArray[n](numericArrayRef);
Where n is any word (similar to a variable) that will receive the size
(number of cells) of the array. You need to use this word in order to know
the size of the array being read.
When working with multidimensional arrays, you will need to declare array
inputs in similar fashion as to when you create arrays:
Input: theArray[m,n,s](numericArrayRef);
This instruction will allow a three dimension array to be passed into the
function. Similarly as explained before m,n and s will be the size of each
one of the dimensions of the array.
This means that you will need to write different functions to sort a one
dimension array, and a two dimension array as the syntax will be different.
If a function receives an array by value, you will be able to pass this
array into a second function that receives an array by value, but you will
get an error from the PowerEditor if you try to pass a value array into a
function that receives a reference array.
You will be able to pass an array that is received by reference into a
function that expects an array per value. And you will be able to pass a
reference array into a second function that receives a reference array.
Thank you for choosing Omega Research, Inc.
Julio Zayas
EasyLanguage Specialist
Omega Research, Inc.
Hope this helps,
Philippe
////////////////////////////////////////////////////////
philippe_lhermie@xxxxxxxxxxx
///////////////////////////////////////////////////////
----- Original Message -----
From: <Jwtrader@xxxxxxx>
To: <omega-list@xxxxxxxxxx>
Cc: <hrjf4@xxxxxxxxx>
Sent: Sunday, August 01, 1999 8:03 AM
Subject: Re: NumericArrayRef and NumericArray ? ( Thank U Howard ! !)
> Howard,
> Thank you very much for your generous contribution to this list.
|