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

Global variables



PureBytes Links

Trading Reference Links

In answer to my inquiry to Omega about global variables in TS2000i, here is
their answer.  I'll have to play with this a bit, but it looks like it can
save some dll work.  I wonder how many other hidden goodies there are?

>>>>>>>

2)	In version four the answer is you would have to purchase or build a
library file to use global variables.  In version 2000i you can now pass
variables and arrays by reference.  For example:

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.  The function itself returns a zero (0).

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.