Translating MetaStock PREV function to WealthScript
Author: eyagan
Creation Date: 2/11/2011 6:46 AM
profile picture

eyagan

#1
Hi everyone,

I am very new to the wealth-lab world and I want to start trading with this great program sooner or later. I have some custom indicators on Metastock but how to interpret them to wealth-lab language... got no clue? can you please help me with the basic indicator below so that I can see what ise waiting for me?

period:=Input("TRUE RANGE period",1,100,17);
Q3:=ATR(PERIOD)/C;
Q4:=Mov( Typical(),period,S) ;
Q5:=If((Q4*(1-Q3))>PREV,Q4*(1-Q3),If((Q4*(1+Q3))<PREV,Q4*(1+Q3),PREV));
Q5

cheers...

profile picture

Eugene

#2
Hi there,

The Q3 and Q4 are trivial:
CODE:
Please log in to see this code.

CODE:
Please log in to see this code.

References: TypicalPrice = AveragePriceC; ATR

The Q5 line will be a bit more involved to translate. Here's one clue from the Wealth-Lab Wiki FAQ | Strategies and WealthScript > How to program MetaStock's PREV function in Wealth-Lab?

There is a function in MetaStock formula language called PREV that slows down processing dramatically, but is quite helpful.

A common mistake when translating a MetaStock formula with PREV statement is confusing it with the series value on the previous bar. However, MetaStock does have a way to reference previous bar value which is "Ref": e.g. "Ref(c,-1)". PREV is a statement-oriented self-referencing directive that references its own value on the previous bar.

If a bar loop is being used, simply reference the variable like shown below to create a PREV equivalent:


CODE:
Please log in to see this code.

profile picture

eyagan

#3
thanks for the quick answer Eugene...
I will check the wiki for the prev function, that's the crucial part...
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).