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

Re: How to keep a value in a variable over consecutive bars?


  • To: "Abhijit Dey" <omegalist@xxxxxxxxxx>
  • Subject: Re: How to keep a value in a variable over consecutive bars?
  • From: "Gary Fritz" <fritz@xxxxxxxx>
  • Date: Fri, 14 May 2004 08:59:01 -0700

PureBytes Links

Trading Reference Links

> Is there a way to set a variable in a bar and have access to it from
> a subsequent bar? I do not wish to have the variable to be a series. 

ALL variables are available in subsequent bars, without any added 
effort.  ALL variables have history (series) available.

> As far as I understand, a variable, defined as var: something(0)
> would get reset to 0 every bar.  

Nonono.  "var: something(0);" initializes the variable to 0 at 
the START OF THE CHART.  After that the variable only changes 
value when you change it.

Try this, for example:

var: BarNum(0);
BarNum = BarNum + 1;
plot1(BarNum, "BarNum);

So if you want the value of a variable as it was N bars ago, 
access it as BarNum[N].  N must be <= the MaxBarsBack setting for 
your study, since TS only retains the last MaxBarsBack bars of 
variable history.

But if you just want to remember the value as it was the last 
time you set it, just access the variable.  It will still have 
the value you set into it.

Gary