Adding PREV constant to amibroker??

#1
PREV constant is a built in function in metastock
here is its describtion in metastock help file.
-----------
Self Referencing Formulas Using PREV

The PREV constant allows you to create self-referencing formulas. A self referencing formula is one that is able to reference the "previous" period's value of itself.
For example, the following is an example of a self referencing formula:
((H+L+C)/3) + PREV
This simple formula divides the high, low, and closing prices by 3 and then adds this value to yesterday's value of the ((H+L+C)/3).
The calculation of the popular indicator On Balance Volume illustrates the use of the PREV function.

(if(c>ref(c,-1),1,-1)*volume)+PREV
Although On Balance Volume can be calculated without the use of the PREV function, an exponential moving average cannot (other than using the mov() function). The following formula shows how a 18% exponential moving average (approximately 10-periods) is calculated using the PREV function.
(close*0.18)+(PREV*0.82)
--------------------
my question is how to make similer to prev constant in amibroker
thanks to all
 

soumya_b

Active Member
#2
PREV constant is a built in function in metastock
here is its describtion in metastock help file.
-----------
Self Referencing Formulas Using PREV

The PREV constant allows you to create self-referencing formulas. A self referencing formula is one that is able to reference the "previous" period's value of itself.
For example, the following is an example of a self referencing formula:
((H+L+C)/3) + PREV
This simple formula divides the high, low, and closing prices by 3 and then adds this value to yesterday's value of the ((H+L+C)/3).
The calculation of the popular indicator On Balance Volume illustrates the use of the PREV function.

(if(c>ref(c,-1),1,-1)*volume)+PREV
Although On Balance Volume can be calculated without the use of the PREV function, an exponential moving average cannot (other than using the mov() function). The following formula shows how a 18% exponential moving average (approximately 10-periods) is calculated using the PREV function.
(close*0.18)+(PREV*0.82)
--------------------
my question is how to make similer to prev constant in amibroker
thanks to all
i also have the same quary.....
 
U

uasish

Guest
#3
PREV constant is a built in function in metastock
here is its describtion in metastock help file.
-----------
Self Referencing Formulas Using PREV

The PREV constant allows you to create self-referencing formulas. A self referencing formula is one that is able to reference the "previous" period's value of itself.
For example, the following is an example of a self referencing formula:
((H+L+C)/3) + PREV
This simple formula divides the high, low, and closing prices by 3 and then adds this value to yesterday's value of the ((H+L+C)/3).
The calculation of the popular indicator On Balance Volume illustrates the use of the PREV function.

(if(c>ref(c,-1),1,-1)*volume)+PREV
Although On Balance Volume can be calculated without the use of the PREV function, an exponential moving average cannot (other than using the mov() function). The following formula shows how a 18% exponential moving average (approximately 10-periods) is calculated using the PREV function.
(close*0.18)+(PREV*0.82)
--------------------
my question is how to make similer to prev constant in amibroker
thanks to all
http://www.traderji.com/forum-sponsors/25169-amibroker-now-available-india-3.html#post270384
http://www.traderji.com/metastock/13251-free-metastock-indicator-system-3.html#post174448
 

kkseal

Well-Known Member
#4
Everything done with PREV can be done with REF.

Like
prc = (H+L+C)/3;
CP = prc + Ref(prc,-1);

Only certain initial conditions need to be checked Like in

prc = (H+L+C)/3;
CP = iif(BarIndex>0, prc+Ref(prc,-1), prc);

(I don't know how PREV handles this - i.e. situations where no previous value is as yet avlbl)
 
Last edited:

oxusmorouz

Well-Known Member
#6
The loop maybe a bit difficult to code but the calculation speed is much faster compared with metastock's prev. Biggest advantage of a lower level programming language.
 
U

uasish

Guest
#7
Thks kalyan ,but PREV is not exactly ref(condition,-1) however as You ,Ajay & Adheer guided ,will try the 'Loop' function in Amibroker.
 

kkseal

Well-Known Member
#8
Ashishda, i'm trying to figure out what PREV stands for exactly* (Can you quote from the MS documentation?) Once the entire scope & functionality is known an equivalent function can be written in Ami (but it has to be generic which is why every aspect of PREV has to be known & understood first)

Regards

*for e.g. the OBV cannot be coded without internal looping/cumulation
 

kkseal

Well-Known Member
#9
PREV seems to be some kind of global variable to which the output of recursive function calls (internal) is assigned. This might create some problems where multiple PREVs are used in a single piece of code/formula. (One PREV would change the value of another, specially if used both within & outside user-defined functions, & the value of only the last call can be used reliably).

Also being recursive it'll inevitably be slow.

Still, an interesting piece of lexicon in MS.
 

Similar threads