Todd,

> Index = Ref(Index,1) * Multiplier

A few observations:

1. You should use Ref(..., -1) if you want the previous bar's value.

2. Uninitialized variable errors come from trying to use a variable 
that has not yet been assigned a value. In your example, if this is 
the first time you are assigning a value to Index, then the problem 
may be that you are trying to use a value (i.e. Index) that has not 
yet been defined (i.e. what do you expect to be in Ref(Index, ...) 
when Index itself has not yet been set to anything?).

3. Note that the values for an array are all set at the same time, not 
sequentially bar by bar:

http://www.amibroker.com/guide/h_understandafl.html 

When trying to calculate current array values based on earlier values 
from that same array (e.g. current value is a multiple of the previous 
value), you will usually have to use looping code. Though, you may be 
able to use AMA or AMA2 to do the job for you.

http://www.amibroker.com/guide/afl/afl_view.php?id=18
http://www.amibroker.com/guide/afl/afl_view.php?id=19

Mike

-- In amibroker@yahoogroups.com, "toddk63" <[EMAIL PROTECTED]> wrote:
>
> Thanks Mike.  I had read that doc.  And I did notice I had to run
> "Explore" a couple of times to get things to "converge" properly.
> 
> My basic problem is I cannot use yesterdays "Index" times the
> "Multiplier" to get todays "Index".  Something like:
> 
> Index = Ref(Index,1) * Multiplier
> 
> This doesn't work and gives an error.  Something about using an
> un-initialized variable.
> 
> Todd K. 
> 
> --- In amibroker@yahoogroups.com, "Mike" <sfclimbers@> wrote:
> >
> > Hi,
> > 
> > You may find the following document useful for some ideas (thanks 
to 
> > Herman):
> > 
> >   http://www.amibroker.org/3rdparty/IntroToAtc.pdf
> > 
> > Additionally, be sure to study page 17 to ensure that your 
immediate 
> > Foreign usage of ~MyIndex within a single exploration is behaving 
as 
> > you expect.
> > 
> > Mike
> > 
> > --- In amibroker@yahoogroups.com, "toddk63" <toddk63@> wrote:
> > >
> > > I have created a custom "Index" using "AddToComposite". Here is 
the
> > > code that runs in Exploration:
> > > -----------------------------------------
> > > Counter = IIf(IsNull(Close),0,1);
> > > 
> > > AddToComposite( Counter * ROC(Close,1), "~MyIndex", "C", 
1+2+8+16 );
> > > AddToComposite( Counter, "~MyIndex", "I", 1+2+8+16 ); 
> > > 
> > > Index = 100 + Cum(Foreign( "~MyIndex", "C" ) / Foreign( 
"~MyIndex",
> > > "I" ));
> > > 
> > > Multiplier = (100 + Foreign( "~MyIndex", "C" )/Foreign( 
"~MyIndex",
> > > "I" ))/100;
> > > 
> > > Filter=1; 
> > > 
> > > AddColumn (Close,"Close");
> > > AddColumn (Index,"Index");
> > > AddColumn (Multiplier*100,"Multiplier x 100");
> > > --------------------------------------------------
> > > The problem is using the "CUM" function adds the daily percent 
> > change
> > > to calculate the "Index".  I wish to use the "Multiplier" to 
> > calculate
> > > an index where the previous days index value is multiplied by 
the
> > > "Multiplier".  The index should initialize as "Index = 100" to 
start
> > > with the first bar. Its probably simple fix, but I can't get 
there.
> > > 
> > > Frustrated,
> > > 
> > > Todd K.
> > >
> >
>



Reply via email to