Page 12                                                      

ADX with Stochastic Signals

Metastock users can reproduce the trend bars and entry signals shown on the CWO chart using the Expert Advisor. Create a new expert and under Symbols add a new entry with the following condition :

ADX(14) > 20 AND ( Mov(C,15,S) > Mov(C,30,S)) AND ( Mov(C,5,S) > Mov(C,30,S)) AND Stoch(5,3) < 30 AND Ref(Stoch(5,3) ,-1) >=30

Under Trends add the Bullish formula :

ADX(14) > 20 AND ( Mov(C,15,S) > Mov(C,30,S)) AND ( Mov(C,5,S) > Mov(C,30,S))

and the Bearish formula :

ADX(14) > 20 AND ( Mov(C,15,S) < Mov(C,30,S)) AND ( Mov(C,5,S) < Mov(C,30,S))

C Miller, ccm@itga.com.au


Chandeleir Exit, version II

Below is the MetaStock code I posted for the Chandelier exit back in October, 1999. The trick is to define the entry date/price as the point at which your system triggered the entry, not by using the date functions. A side benefit is that you can also use it to implement a fixed dollar, or money management, stop.

The more time I spend with the Chandelier exit, the more I admire its strength as an exit and its simplicity. Because exits tend to be the weakest part of a system, I would urge everyone to spend some time with it.

And Chuck LeBeau gets credit for the MetaStock code, not me. I just took his framework and applied it to his exit.


{LONG EXIT}
LongEntry:= {this your entry system, eg. Cross(CLOSE, Mov(C,20,E))};
MoneyMgmtStop:= {this is your maximum loss, in points};

{DEFINE ENTRY PRICE, WITH EXIT BEING -- ENTRY PRICE AND NO TRADE BEING 0}
EntryPrice:= If(PREV <= 0,
{Trade entered today?}
If(LongEntry, CLOSE, 0),
{Trade entered before today. Stopped today?}
If(LOW <= PREV - MoneyMgmtStop, -PREV,
If(LOW <= HighestSince(1,PREV=0, HIGH) - 3 * ATR(10), -PREV,
If(LOW <= HighestSince(1,PREV=0, CLOSE) - 2.5 * ATR(10), -PREV,
PREV))));

{EXIT IF ENTRY PRICE < 0 (MEANING EXIT)}
EntryPrice < 0

{SHORT EXIT}
ShortEntry:= {this your entry system, eg. Cross(Mov(C,20,E), CLOSE)};
MoneyMgmtStop:= {this is your maximum loss, in points};

{DEFINE ENTRY PRICE, WITH EXIT BEING -ENTRY PRICE AND NO TRADE BEING 0}
EntryPrice:= If(PREV <= 0,
{Trade entered today?}
If(ShortEntry, CLOSE, 0),
{Trade entered before today. Stopped today?}
If(HIGH >= PREV + MoneyMgmtStop, -PREV,
If(HIGH >= LowestSince(1,PREV=0, LOW) + 3 * ATR(10), -PREV,
If(HIGH >= LowestSince(1,PREV=0, CLOSE) + 2.5 * ATR(10), -PREV,
PREV))));

{EXIT IF ENTRY PRICE < 0 (MEANING EXIT)}
EntryPrice < 0

from Glen Wallace

Moving Average Crossovers

What follows is a simple example using a moving average crossover system for MetaStock, employing 10 and 30 day exponential averages. These are just examples and profitability is dubious.

Custom indicator which gives 1 for longs and -1 for shorts--

Indicator Name: Position
MASwitch:=If(Mov(C,10,E)>Mov(C,30,E),1,If(Mov(C,10,E)<Mov(C,30,E),-1,0));
If(BarsSince(MASwitch=1) <BarsSince(MASwitch=-1),1,-1)

Custom indicator for cumulative open Equity curve without trading costs--

Indicator name: Equity
Cum(If(Ref(Fml("Position"),-1)=1,C-Ref(C,-1),Ref(C,-1)-C))

You can make several such equity lines and then just add them by using a yet another custom indicator, e.g.,

Indicator name: TotalEquity
Fml("Equity1")+Fml("Equity2")

from Yngvi
hardy@consulting.is


Setting up the ADX Template

This constructs the template mentioned in the ADX article of the October 1999 issue of TASC by Paul Babbitt.

1. Chart your stock/index/whatever, using a "Clean" template, then do the same again, so that the two overlapping charts are displayed.

2. On the menu bar, click Windows, then Columns. The two charts will then be displayed side-by-side.

3. Change the left-hand chart from Daily to Weekly. Right click on the date scale and select X-Axis. Set the displayed range of dates to what you want, e.g., 1996 to 1999. Make sure the loaded dates range starts earlier. Click the Margin tab and set the margin to 1.

4. From the Indicator drop-down list select Moving Average and drag it to the left-hand chart. A 40 period on the weekly chart corresponds to a 200 day MA.

5. For the right-hand chart, leave it at a daily interval but set the X-Axis as in paragraph 3 above to, say, a 3-month display.

6. Drag the Bollinger Band indicator to the right-hand chart.

7. Drag the Directional Movement ADX indicator to the top of the right-hand chart until the cursor changes to a box, then release. Set the horizontal lines as desired.

8. Similarly drag the RSI indicator to the bottom of the right-hand chart.

from HHP


Writing Metastock Explorations

MetaStock is a marvellous program for traders, but can appear complicated and intimidating at first. In reality, it's easy and fun, if you take it slowly, step by step.

Let's consider a common trader's question: "How can MetaStock help me find all the stocks where the 3 day moving average has just crossed above the 10 day moving average?"

MetaStock's Explorer tool allows you to search all the stocks in the ASX, and within a minute or two (depending on your computer's speed!) generate a list of all stocks meeting this particular criteria.

Here's a step by step guide for beginners:

1. Open up your Explorer tool in MetaStock by clicking on the little "binoculars" symbol in the upper right field of your screen, or find it under Tools in the drop-down menu.

2. You will be presented with the Explorer screen showing a list of ready-made Equis Explorations plus various options to view or edit them. More about these later. Look instead at the list of options to the right.

3. Choose the "New" button and click. You've just starting writing your own MetaStock Exploration! MetaStock gives it the name "<New Exploration>" but let's rename it "Moving Average Crossover" for the sake of this exercise.

4. Note that the Explorer screen has an upper section labelled "Notes" and then, just below, seven columns, with tabs, labelled "A" to "F," plus "Filter." For now we're just going to work with the "Filter" column. Click on its tab and you're ready to write a MetaStock formula in this column.

5. Enter the following without the quotation marks: "Cross( Mov(c,3,s) , Mov(c,10,s) )" but don't worry about the *spaces* between letters and punctuations marks, nor about capitalisation.

6. Here's a quick explanation to ponder, before we go further. What you've just entered under MetaStock Explorer's Filter is a much more simple formula than you realise! It means only "Crossover A over B" or "Crossover 3 over 10" in ordinary English. MetaStock writes this as "Cross( A , B )" where A and B are other MetaStock formulas, any formulas you like. In this case, we're putting two different moving averages in the place of A and B. MetaStock writes the English language phrase "Moving Average of the past 3 days" as "mov(c,3,s)" and the second moving average is exactly the same, with the numeral 10 substituted for the 3.

7. Your first MetaStock Exploration is now finished. Click "OK" in the lower left of the Explorer field to save it and you will quickly find your own "Moving Average Crossover" Exploration added to those already on MetaStock's ready-made list.

8. Next, click on the "Explore" button and MetaStock will prompt you for the path to the place on your computer where you have all your ASX (or other) data. Choose which securities you want to scan. I suggest that you choose them all to start with, and save this as a "List" named "All" so that when you make more Explorations you won't have to go through this step again. You can just choose the "All" list whenever you want to scan stocks. (Take note at this point that MetaStock has excellent assistance for you under its "Help" tab as well as one of the best software manuals ever written.)

9. MetaStock will quickly verify that your stocks are where you say they are, and prompt you for an "OK". Once you do this, you can watch a nifty screen where MetaStock outlines its search for all the stocks that match your search (Filter) criteria. How long this process takes depends once again on the speed of your computer!

10. When Explorer is finished you should choose the "Report" option to find a filtered list of all the stocks which *today* have their 3 day moving average rising above their 10 day moving average. MetaStock allows you to open each or all of these stocks in full screen pages for further analysis.

Patrick McDonald, patrick@mpx.com.au


Backdating Metastock Explorations

Perhaps the above is enough for many traders, but a few further MetaStock nuances can add to the value of the information you've uncovered. For example, wouldn't you like to know which stocks have met the chosen crossover criteria in the past, say, five days? And wouldn't it be handy to be able to sort your newly discovered stocks in order of price or volume? If so, read on for a few more simple tips.

1. Go back to the main Explorer tool section, highlight your "Moving Average Crossover" Exploration, and hit the "edit" key this time. You can now make alterations to your Exploration. Ignore the upper "Notes" section and click on Column A first. You will see a large white field for entry of formulas and a small field in the lower left, entitled "Col Name." Simply put a "c" in the large formula section and "Close" in the column name section. Repeat these actions for Column B, with "v" and "Volume" respectively. Now when your Exploration presents you with your data, you can easily sort by price (c) or volume (v).

2. Finally, click on the "Filter" tab again to slightly modify your Exploration formula. The way you have it set up initially tells MetaStock to find all stocks which meet the criteria today. You now want it to find all stocks that have met these criteria over the past five days. The answer is the MetaStock Alert function, which is written "Alert( A , Number ) where "A" is any formula you care to choose, and "Number" is the number of days. So now you put your original formula in the place of A. The result is: "Alert( Cross( Mov(C,3,E) , Mov(C,10,E) ) ,5)" without the quotation marks. Save your new Exploration with the "OK" button and you're ready to find all stocks whose 3 day moving average passed above the 10 day moving average in the past five trading days!

The above information should allow you to write further Explorations by simply changing the numbers. If you prefer to use Exponential Moving Averages instead of Simple Moving Averages, change "s" to "e" in the formulas. You can also open up the ready made Equis Explorations, investigate how they're written, and change them with the "Edit" command (then saving with a new name). A further step is to investigate the hundreds of formulas available here on this web site and modify them in the same way. This is the quick and easy way to learn how to program with MetaStock. Follow the examples given by all the kind and clever MetaStock users who have gone before you, and tweak, tweak, tweak.

Patrick McDonald, patrick@mpx.com.au


Vidya 21, 5

This is the MetaStock code for VIDYA 21,5 which applies to the article "Breaking Out Of Price Channels" by Gerald Marisch in the TASC January 1998 edition.

Length:=Input("Length",1,200,21);
Smooth:=Input("Smoothing",1,200,5);
AbsCMO:=(Abs(CMO(C,Length)))/100;
SC:=2/(Smooth+1);
VIDYA:=If(Cum(1)<=(Length+1),C,(SC*AbsCMO*CLOSE)+(1-(SC*AbsCMO))*PREV);
VIDYA

from Ian Burgogyne


Vidya with P variable, version II


My version of Tushar Chande's Vidya, using the P variable

Vidya{P}
Periods:=Input("length of MA",5,100,20);
K:=Stdev(P,5)/Mov(Stdev(P,5),20,S);
A:=(2/(Periods+1));
Vidya:=A*K*(P)+(1-A*K)*Ref(P,-1);
Vidya;

Tar(SZ)an Long
C-(((462*Mov(C,34,E))-(420*Mov(C,13,E))+(490*(Mov(Mov(C,13,E)-Mov(C,34,E),89,E))))/42)

Tar(SZ)an Short
(C-(((325*Mov(C,26,E))-(297*Mov(C,12,E))+(351*Mov(Mov(C,13,E)-Mov(C,26,E),9,E))))/28)*2

from Barry Marx


Vidya Explanation

Vidya is a subject that comes up with some regularity. It's actually available in MetaStock as the Variable Moving Average (Mov(C,n,V) but Equis, for their own inscrutable reasons, choose not to identify it by name. If you refer to the MetaStock manual, be aware that there is a typo in the formula (0.078 should read 0.78). Two or three years ago I coded the version given in TAS&C and it overlaid the MetaStock version precisely, except that at the time the MetaStock version was not correctly initialised -- this has since been corrected. Equis acknowledged the typo at the time, but have done nothing about it.

As far as the 'circular reference' is concerned, you are right that eventually you run out of data. However adding a portion of yesterday's value to a portion of today's value is common to several indicators, such as the Exponential Moving Average. If no provision is made, then usually the indicator will start with a value of zero, rise rapidly at first, then take some time to stabilise.

One answer is to initialise it. For a Vidya of the close, period N, you can initialise with something like "If(Cum(1) < N, C,{else} ...)" with the Vidya formula as the 'else'. Then at day N the indicator uses the (N-1) close for yesterday's data and takes much less time to stabilise.

from HHP


Vidya using P variable, version I

Here is a version of Vidya using a P variable that matches MetaStock's built-in Variable Moving Average. You can overlay them in different colours on the same chart to satisfy yourself that they are indeed the same (but remember to use the same number of periods). There is a small difference at the start due to different initialisation, after which they are identical. The coding is spelled out for the benefit of anyone studying the book. It can be adapted by adding a variable input for the CMO length (9), or made universal by replacing each C with a P, or the Abs(CMOsc) can be replaced with a different volatility index that ranges between 0 and 1.

{Vidya (Chande)}

Pds:= Input("Number of Periods?",1,1000,20);
Alpha:= 2/(Pds+1);

{Chande Momentum Oscillator}
{UD = Up day}
{DD = Down day}
UD:= Sum((C-Ref(C,-1))*(C>Ref(C,-1)),9);
DD:= Sum((Ref(C,-1)-C)*(C<Ref(C,-1)),9);
CMOsc:= (UD-DD)/(UD+DD);

k:= Abs(CMOsc);

Vidya:= (Cum(1) < Pds) * C + (Cum(1)>=Pds) * ((Alpha * k * C) + (1-Alpha
* k) * PREV);
Vidya

{from HHP}


Channel Exit with Stop Loss

As people have mentioned before, it is difficult to design exits in MetaStock because of the awkwardness of defining your trade entry price. One exit system that requires your trade entry price is the channel exit.

For those not familiar with it, the channel exit is quite a straight forward trailing stop. Once you're in a trade (let's say, long), you maintain your stops at the lowest low of the past number of days (optimized, in the code below) until you are taken out of the market. This method attempts to let profits run in the direction of the trend, but takes you out when price makes a significant reversal and you risk giving back profits on a retracement or the end of the trend.

Below is the code for a channel exit. It also includes a money management stop to limit losses to an acceptable level until the channel exit exceeds it. Work on variations of this basic theme, such as moving the stop up faster where the market makes rapid gains and your lowest low in, say, 10 or 20 days is just too far away to adequately protect profits.

Glen Wallace

{LONG EXIT}
LongEntry:= {this your entry system, eg. Cross(CLOSE, Mov(C,20,E))};
MoneyMgmtStop:= {this is your maximum loss, in points};

{DEFINE ENTRY PRICE, WITH EXIT BEING -ENTRY PRICE AND NO TRADE BEING 0}
EntryPrice:= If(PREV <= 0,
{Trade entered today?}
If(LongEntry, CLOSE, 0),
{Trade entered before today. Stopped today?}
If(LOW <= Max(PREV - MoneyMgmtStop, Ref(LLV(LOW,opt1),-1)), -PREV,
PREV));

{EXIT IF ENTRY PRICE < 0 (MEANING EXIT)}

EntryPrice < 0


{SHORT EXIT}
ShortEntry:= {this your entry system, eg. Cross(Mov(C,20,E), CLOSE)};
MoneyMgmtStop:= {this is your maximum loss, in points};

{DEFINE ENTRY PRICE, WITH EXIT BEING -ENTRY PRICE AND NO TRADE BEING 0}
EntryPrice:= If(PREV <= 0,
{Trade entered today?}
If(ShortEntry, CLOSE, 0),
{Trade entered before today.Stopped today?}
If(HIGH >= Min(PREV + MoneyMgmtStop, Ref(HHV(HIGH,opt1),-1)), -PREV,
PREV));

{EXIT IF ENTRY PRICE < 0 (MEANING EXIT)}
EntryPrice < 0


Higher Volume Exploration

Required: today's volume to be greater than the highest high over the past 21 days.

MetaStock Explorer filter:

V>Ref(HHV(V,21),-1)

from HHP


Enter 20 Days after MOV Signal

I am trying to use the MetaStock Explorer to find all stocks with the following:

1. c - mov(c,60,s)<0
2. Above condition should be in place for 20 days/

I use c - Mov(c,60,s)<0 but how do I write the Exploration?

from wsb


Use (C - Mov(C,60,S))<0 AND Ref((C - Mov(C,60,S))<0),-1) AND ... Ref((C -Mov(C,60,S))<0),-19)

where ... stands for all Ref( x,-i) with i between 2 and 18.

from Yngvi



Under the MetaStock Explorer filter, use something like:

C>MOV(C,60,S) AND REF((C>MOV(C,60,S)),-1) AND
REF((C>MOV(C,60,S)),-2) AND REF((C>MOV(C,60,S)),-3) AND
REF((C>MOV(C,60,S)),-4) AND REF((C>MOV(C,60,S)),-5) AND
REF((C>MOV(C,60,S)),-6) AND REF((C>MOV(C,60,S)),-7) AND
REF((C>MOV(C,60,S)),-8) AND REF((C>MOV(C,60,S)),-9) AND
REF((C>MOV(C,60,S)),-10) AND REF((C>MOV(C,60,S)),-11) AND
REF((C>MOV(C,60,S)),-12) AND REF((C>MOV(C,60,S)),-13) AND
REF((C>MOV(C,60,S)),-14) AND REF((C>MOV(C,60,S)),-15) AND
REF((C>MOV(C,60,S)),-16) AND REF((C>MOV(C,60,S)),-17) AND
REF((C>MOV(C,60,S)),-18) AND REF((C>MOV(C,60,S)),-19)

That should work ... theoretically. The only thing I'm concerned about is the REF format. However, I think it's correct. The Close is always above (or greater than '>') the MOV. The parentheses always match. Because a 60 day MOV is rather slow, you probably could shorten the formula by leaving out all of the even numbered REFerences:

C>MOV(C,60,S) AND REF((C>MOV(C,60,S)),-1) AND
REF((C>MOV(C,60,S)),-3) AND REF((C>MOV(C,60,S)),-5) AND
REF((C>MOV(C,60,S)),-7) AND REF((C>MOV(C,60,S)),-9) AND
REF((C>MOV(C,60,S)),-11) AND REF((C>MOV(C,60,S)),-13) AND
REF((C>MOV(C,60,S)),-15) AND REF((C>MOV(C,60,S)),-17) AND
REF((C>MOV(C,60,S)),-19)

from Daniel Martinez


Volume Based Exploration

1. Stocks with volume > 10x the previous day's volume

2. Stocks where the above situation hasn't occurred during the previous 60 days.

ColA = if(V > 10*ref(V,-1),1,0)

ColB = ref(barssince(V>10*ref(V,-1)),-1)

Filter: ColA=1 and ColB>60

from warthog