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

Re: Local variable initialization



PureBytes Links

Trading Reference Links

That code plots the value = 10 on all bars.

Variables are local to the total function/indicator/strategy module, not just inside the begin/end loop.

Variables can also be passed by reference as an input to a function. 

There are global variable packages that allow variables to be global throughout the charting module. 

The Var statement must appear before the variable is used and can be inside a conditional but it is processed as though it was not inside the conditional statement.

Variables are initialized at CurrentBar = 1 but some are initialized before CurrentBar = 1. As I recall:

  Var: Price(Close); 

initializes "Price" back in time to the first bar of data, including the MaxBarsBack interval.

Most of the code I see has initialization problems, indicating that most people do not understand this. For example:

   Var: Avg(0);

   Avg = XAverage(Close, 200);

Avg starts at zero and takes hundreds of bars to reach near the correct value.

Bob Fulks



At 11:31 AM 3/22/2007, Joel Reymont wrote:

>On Mar 22, 2007, at 3:21 PM, DH wrote:
>
>>if false then begin
>>  var: n1(10);
>>end;
>>plot1(n1, "test");
>
>This won't work because n1 does not exist outside of the scope  
>(begin ... end) of the if statement. A better test would be to print  
>the value of n1 right after it's declared and see if it always prints  
>the same in the if statement.
>
>I don't have TS installed, can someone tell me what happens in this  
>case?
>
>        Thanks in advance, Joel
>
>--
>http://wagerlabs.com/
>
>
>