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

Re: EL question - static variables?



PureBytes Links

Trading Reference Links

> In easy language, if I want a variable that I can set it a bar and 
> remains the same until I change it, how would I do that?

Just set a value on any variable.  It will retain that value until 
you change it to something else.

> Variables MyNum(0);
> If BarNumber = 10 then MyNum = Close;
> If I'm anywhere but the 10th bar, MyNum will equal 0.

I believe you're confused about how variables work.  MyNum will be 0 
until you set it to Close on the 10th bar, because the "Vars" 
statement initialized it to 0 **before the first bar**.  It *DOES 
NOT* keep setting it to that value on every bar.

After bar 10, MyNum contains the value of Close from the 10th bar.  
If you don't change it to another value, it will retain the value of 
the 10th bar close on the 100th, 1000th, or Nth bar.

Gary