Metastock Formulas - C 1
Click here to go back to Metastock Formula Index

IMPORTANT: These formulas aren't my complete collection. For my complete collection of instantly usable, profitable and powerful MetaStock formulas Click Here

Would You Like To Use MetaStock To Its Full Potential? Discover the Amazingly Simple Secret to Master Metastock Step-By-Step - click here


A | A 1 | B | B 1 | C | C 1 | D | D 1 | E | F | G | H | I | J | K | L | M | M 1 | N | O | P | R | S | S 1 | T | U | V | W | Z |

Channel Analysis
Combining Statistical and Pattern Analysis, Shark – 32
CCI Moving Average Crossover Test
Combining Trend and Oscillator Signals
Commodity Channel Index Buy and Sell Signals

Calendar Day counter
Calendar Day of Year

Calendar Weekday counter
Calendar Week counter
Calendar Week of Year
Calendar ASX non-Friday end-of-week(1)
Calendar Weekday of Month
Calendar Week of Month
Cycle Length


Channel Analysis

Channel Analysis, beginning on page 18 of the July 1998 Technical Analysis of Stocks & Commodities Magazine It's quite easy to create the Trend Channels discussed in Thom Hartle's Channel Analysis article in MetaStock for Windows.

After opening a chart, you may want to zoom in a little to make it easier to draw the Trend Channels more precisely. You can do this by clicking on the "+" button located on the Chart Toolbar at the bottom of the chart. Next you may want to identify the bars for the support or resistant points by drawing circles on the bars as Mr. Hartle did in the article, or you can use symbols from the symbol palette.

Both can be chosen from the Drawing Toolbar which is on left side of the chart. After identifying the points to draw the trendline, click on the Trendline button, also located on the Drawing Toolbar, and draw the trendline between the closing prices of the two bars. If you are using MetaStock 6.5, you may want to right-click on the trendline, choose properties, and then check the Snap to Price checkbox. This will make the trendline line up exactly with the closing prices.

To create the second trendline of the Trend Channel, right-click on the first trendline and choose Create Parallel Line. Drag this parallel line so it aligns with the highest high between the two support points or the lowest low between two resistance points. If desired, you can go to the properties of each of these trendlines and choose to extend the lines to the right.

(Go Top...)

Combining Statistical and Pattern Analysis, Shark – 32

In MetaStock for Windows you can use the Expert Advisor to recreate the "Shark – 32" signals on your charts as discussed in Walter T. Down's article "Combining Statistical and Pattern Analysis".

First, choose Expert Advisor from the Tools menu in MetaStock 6.5. Next, choose New and enter the following formulas:

Name:
Click the Name tab and enter "Shark – 32" in the Name field.

Trends:
Click the Trends tab and enter the following formulas in the Bullish and Bearish fields.

Bullish: Mov(C,5,S)>Mov(C,20,S);
Bearish: Mov(C,5,S)<Mov(C,20,S);

Highlights:
Click the Highlights tab, choose New, and enter "3rd Bar" in the Name field. Now change the color in the Color field to Blue. Finally, enter the following formula in the Condition field, and then choose OK.

Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);
Shark:=If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND Ref(L,-1)>Ref(L,-2))=1,If(Apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >= (Ref(L,-2)+(WB*Symmetry)) ,1,0),0);
Shark;

Using the same method as above, enter the following 2 highlight formulas.

Name: 2nd Bar

Color: Blue

Condition:
Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);
Shark:=If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND Ref(L,-1)>Ref(L,-2))=1,If(Apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >= (Ref(L,-2)+(WB*Symmetry)) ,1,0),0);
Ref(Shark,+1)=1;

 

Name: 1st Bar

Color: Blue

Condition:
Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);
Shark:=If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND Ref(L,-1)>Ref(L,-2))=1,If(Apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >= (Ref(L,-2)+(WB*Symmetry)) ,1,0),0);
Ref(Shark,+2)=1;

Symbols:
Click the Symbols tab, choose New and enter "Shark Buy" in the Name field. Now enter the following formula in the Condition field.

Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);
Shark:=If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND Ref(L,-1)>Ref(L,-2))=1,If(apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >= (Ref(L,-2)+(WB*Symmetry)) ,1,0),0);
Buyok:=Cross(C,ValueWhen(1,Shark=1,Ref(H,-2)));
Chk:=Cum(Buyok)-ValueWhen(1,Shark=1,Cum(Buyok));
ValidChk:=Alert(Shark=1,25);

{Note* The above ValidChk variable makes the Shark signal valid for 25 periods. If the price does not cross above the High value of the base within 25 periods, you will not receive a signal. You can change the number of periods by changing 25 to the number of periods you desire. *}

Buy:= Buyok=1 AND Ref(Chk,-1)=0 AND ValidChk=1;
Buy;

Click the Graphic tab. Change the symbol in the Graphic field to Buy Arrow. Now change the color in the Color field to Green. Finally, type "Buy" in the Label field, and then choose OK.

Using the Same method as above, enter the following Symbol formula.

Name: Shark Sell

Condition:
Symmetry:=.28;
Apex:=(H+L)/2;
WB:=Ref(H,-2)-Ref(L,-2);
Shark:=If((H<Ref(H,-1) AND L>Ref(L,-1) AND Ref(H,-1)<Ref(H,-2) AND Ref(L,-1)>Ref(L,-2))=1,If(apex <= (Ref(H,-2)-(WB*Symmetry)) AND Apex >= (Ref(L,-2)+(WB*Symmetry)) ,1,0),0);
Sellok:=Cross(ValueWhen(1,Shark=1,Ref(L,-2)),C);
Chk:=Cum(Sellok)-ValueWhen(1,Shark=1,Cum(Sellok));
ValidChk:=Alert(Shark=1,25);

{Note* The above ValidChk variable makes the Shark signal valid for 25 periods. If the price does not cross below the Low value of the base within 25 periods, you will not receive a signal. You can change the number of periods by changing 25 to the number of periods you desire. *}

Sell:= Sellok=1 AND Ref(Chk,-1)=0 AND ValidChk=1;
Sell;

Symbol: Sell Arrow

Color: Red

Label: Sell

After you have finished creating the Symbol formulas, you can attach the Expert to your chart by choosing Expert Advisor from the Tools Menu. Select the Expert called "Shark – 32" from your list of Experts, choose Attach, and then Close.

(Go Top...)

CCI Moving Average Crossover Test

System Explanation:  Buy when the Moving Average crosses up through the CCI and sell on the reverse condition.

Signal Formulas
Enter Long
When( CCI( opt1 ) ,< ,Mov( CCI( opt1 ) ,opt2 ,E ) ) AND When( Ref( CCI(opt1) ,-1) ,>= ,Ref( Mov( CCI( opt1 ) ,opt2 ,E ) ,-1 ) )
Enter Short
When( CCI( opt1 ) ,> ,Mov( CCI( opt1 ) ,opt2 ,E ) ) AND When( Ref( CCI(opt1) ,-1) ,<= ,Ref( Mov( CCI( opt1 ) ,opt2 ,E ) ,-1 ) )
 
Optimization Variables
Opt1: Min = 5 Max = 40 Step = 1
Opt2: Min = 5 Max = 40 Step = 1

(Go Top...)

Combining Trend and Oscillator Signals

The information for this test was published in the December 1996 issue of Technical Analysis of Stocks and Commodities. The test appears in the article "Combining Trend and Oscillator Signals" by Jeremy G. Konstenius. Mr. Konstenius describes a trading system that combines Linear Regression and Moving averages to generate trades.

To create this test in MetaStock do the following:

  • Run MetaStock version 6.0 or higher
  • Click Tools | System Tester | New
  • Type a name for the test in the Name column
  • Enter the following System Test rules and options.
     
Signal Formulas
Enter Long
C>Mov(C,OPT1,S) AND LinRegSlope(C,OPT2)>LinearReg(LinRegSlope(C ,OPT3),50)
Close Long
C<Mov(C,OPT1,S) OR LinRegSlope(C,OPT2)<LinearReg(LinRegSlope(C ,OPT3),50)
Enter Short
C<Mov(C,OPT1,S) AND LinRegSlope(C,OPT2)<LinearReg(LinRegSlope(C ,OPT3),50)
Close Short
C>Mov(C,OPT1,S) OR LinRegSlope(C,OPT2)>LinearReg(LinRegSlope(C ,OPT3),50)
 
Optimize
OPT1: Minimum 5 Maximum 50 Step 5
OPT2: Minimum 5 Maximum 50 Step 5
OPT3: Minimum 5 Maximum 50 Step 5
 
  • Initial Equity: Any amount
  • Positions: Long and Short
  • Trade Price: Close
  • Trade delay: 0

The author uses weekly data and a $50 round turn commission. You can modify this test by changing the distance from Minimum to Maximum or the Step used in each OPT variable.

(Go Top...)

Commodity Channel Index Buy and Sell Signals

This system generates buy and sell signals based on the criteria using the Commodity Channel Index indicator. It enters a long position when yesterday's 14 period CCI is greater than -250 and today's 14 period CCI is less than -250. It will close long according to the criteria you specify in close long. It enters a short position when yesterday's 14 period CCI is less than 250 and today's 14 period CCI is greater than 250 and closes short according to the criteria you specify in close short.

Signal Formulas
Enter Long
When( Ref(CCI( 14 ) ,-1 ) ,> ,-250 ) AND When(CCI( 14 ) ,< ,-250 )
Close Long
When( enter your criteria here )
Enter Short
When( Ref(CCI( 14 ) ,-1 ) ,< ,250 ) AND When(CCI( 14 ) ,> ,250 )
Close Short
When( enter your criteria here )
 

** You can change to a different periodicity other than 14 by changing every occurrence of 14 with the desired periodicity.

(Go Top...)

Calendar Day counter

{ Day counter from 1/1/0001, Gregorian calendar }{ Count is independent of any missing chart data }{ ©Copyright 2003-2004 Jose Silva }{ [email protected] }

limit:=Input("count calendar days from year",1,2100,2000);

LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0 OR Frac(limit/400)=0;
NoCount:=limit*365+Int(limit/4) -Int(limit/100)+Int(limit/400)-LimLeap;
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4) -Int(Year()/100)+Int(Year()/400)-NoCount;
m:=
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
DayNr:=y+m+DayOfMonth();

DayNr

(Go Top...)

Calendar Day of Year

{ Calendar Day of Year counter }{ count is independent of any missing chart data }{ ©Copyright 2003 Jose Silva }{ [email protected] }

leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
m:=leap+
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
Day:=m+DayOfMonth();

Day

(Go Top...)

Calendar Weekday counter

{ Weekday (Mon~Fri) counter from 1960 }{ Count is independent of any missing chart data }{ ©Copyright 2003 Jose Silva }{ [email protected] }

limit:=1960;  {do not change limit year}
LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0 OR Frac(limit/400)=0;
NoCount:=limit*365+Int(limit/4)-Int(limit/100)+Int(limit/400)-LimLeap;
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4) -Int(Year()/100)+Int(Year()/400)-NoCount;
m:=
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
DayNr:=y+m+DayOfMonth();
WkDayCount:=
 Int((DayNr+3)/7)+   {Mon}
 Int((DayNr+2)/7)+   {Tue}
 Int((DayNr+1)/7)+   {Wed}
 Int((DayNr)/7)+     {Thu}
 Int((DayNr-1)/7);   {Fri}

WkDayCount

Missing trading days

{Plots missing daily (weekday) bars count}
{©Copyright 2003-2004 Jose Silva}
{[email protected]}

ChkVol:=Input("Zero-volume days = missing data days?  Yes=1, No=0",0,1,1);
VolMissing:=If(ChkVol,V=0,0);

limit:=1960;  {do not change limit year}
LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0
 OR Frac(limit/400)=0;
NoCount:=limit*365+Int(limit/4)
 -Int(limit/100)+Int(limit/400)-LimLeap;
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
 OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4)
 -Int(Year()/100)+Int(Year()/400)-NoCount;
m:=
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
DayNr:=y+m+DayOfMonth();
WkDayCount:=
 Int((DayNr+3)/7)+   {Mon}
 Int((DayNr+2)/7)+   {Tue}
 Int((DayNr+1)/7)+   {Wed}
 Int((DayNr)/7)+     {Thu}
 Int((DayNr-1)/7);   {Fri}

WkDayCount-ValueWhen(2,1,WkDayCount)-1
 +VolMissing

(Go Top...)

Calendar Week counter

{ Week counter v2.0, Gregorian calendar }{ Count is independent of any missing chart data }{ ©Copyright 2003-2004 Jose Silva }{ [email protected] }

limit:=2000;  {do not change limit year}
LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0
 OR Frac(limit/400)=0;
NoCount:=limit*365+Int(limit/4)
 -Int(limit/100)+Int(limit/400)-LimLeap;
leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0
 OR Frac(Year()/400)=0;
y:=Year()*365+Int(Year()/4)
 -Int(Year()/100)+Int(Year()/400)-NoCount;
m:=
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
DayNr:=y+m+DayOfMonth();
WkCount:=Int((DayNr-1)/7)+(Year()>=limit);

WkCount

(Go Top...)

Calendar Week of Year

{ Calendar Week of year counter v2.1 }{ count is independent of any missing chart data }{ ©Copyright 2003 Jose Silva }{ [email protected] }

leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0;
y:=Year()*365-715870 {count from 1960}
 +Int(Year()/4)-Int(Year()/100)+Int(Year()/400);
m:=leap+
 If(Month()=2,31-leap,
 If(Month()=3,59,
 If(Month()=4,90,
 If(Month()=5,120,
 If(Month()=6,151,
 If(Month()=7,181,
 If(Month()=8,212,
 If(Month()=9,243,
 If(Month()=10,273,
 If(Month()=11,304,
 If(Month()=12,334,
 -leap)))))))))));
d:=m+DayOfMonth();

{1st day of week in year}
fdy:=Int(Frac((y+.5-leap)/7)*7)+1;

{offset necessary for week start sync}
offset:=If(fdy=3,2,If(fdy=4,3,If(fdy=5,-3,
 If(fdy=6,-2,If(fdy=7,-1,1)))));

Week:=Int(Frac((d+.5+offset)/(374+offset))
 *(374+offset)/7)+1;

Week

(Go Top...)

Calendar ASX non-Friday end-of-week(1)

{ ASX non-Friday end-of-week dates, 01/01/1980~31/12/1999 }

Year()=1980 AND Month()=04 AND DayOfMonth()=03
OR
Year()=1981 AND Month()=04 AND DayOfMonth()=16
OR
Year()=1982 AND Month()=04 AND DayOfMonth()=08
OR
Year()=1983 AND Month()=03 AND DayOfMonth()=31
OR
Year()=1984 AND Month()=04 AND DayOfMonth()=19
OR
Year()=1985 AND Month()=04 AND DayOfMonth()=04
OR
Year()=1986 AND Month()=03 AND DayOfMonth()=27
OR
Year()=1986 AND Month()=04 AND DayOfMonth()=24
OR
Year()=1986 AND Month()=12 AND DayOfMonth()=24
OR
Year()=1987 AND Month()=04 AND DayOfMonth()=16
OR
Year()=1987 AND Month()=12 AND DayOfMonth()=24
OR
Year()=1987 AND Month()=12 AND DayOfMonth()=31
OR
Year()=1988 AND Month()=03 AND DayOfMonth()=31
OR
Year()=1989 AND Month()=03 AND DayOfMonth()=23
OR
Year()=1990 AND Month()=01 AND DayOfMonth()=25
OR
Year()=1990 AND Month()=04 AND DayOfMonth()=12
OR
Year()=1991 AND Month()=03 AND DayOfMonth()=28
OR
Year()=1992 AND Month()=04 AND DayOfMonth()=16
OR
Year()=1992 AND Month()=12 AND DayOfMonth()=24
OR
Year()=1992 AND Month()=12 AND DayOfMonth()=31
OR
Year()=1993 AND Month()=04 AND DayOfMonth()=08
OR
Year()=1994 AND Month()=03 AND DayOfMonth()=31
OR
Year()=1995 AND Month()=04 AND DayOfMonth()=13
OR
Year()=1996 AND Month()=01 AND DayOfMonth()=25
OR
Year()=1996 AND Month()=04 AND DayOfMonth()=04
OR
Year()=1997 AND Month()=03 AND DayOfMonth()=27
OR
Year()=1997 AND Month()=04 AND DayOfMonth()=24
OR
Year()=1997 AND Month()=12 AND DayOfMonth()=24
OR
Year()=1998 AND Month()=04 AND DayOfMonth()=09
OR
Year()=1998 AND Month()=12 AND DayOfMonth()=24
OR
Year()=1998 AND Month()=12 AND DayOfMonth()=31
OR
Year()=1999 AND Month()=04 AND DayOfMonth()=01
OR
Year()=1999 AND Month()=12 AND DayOfMonth()=30

Calendar ASX non-Friday end-of-week(2)

{ ASX non-Friday end-of-week dates, since 01/01/2000 }

Year()=2000 AND Month()=04 AND DayOfMonth()=20
OR
Year()=2001 AND Month()=01 AND DayOfMonth()=25
OR
Year()=2001 AND Month()=04 AND DayOfMonth()=12
OR
Year()=2002 AND Month()=03 AND DayOfMonth()=28
OR
Year()=2003 AND Month()=04 AND DayOfMonth()=17
OR
Year()=2003 AND Month()=04 AND DayOfMonth()=24

{ future Thursday Easter dates }
OR
Year()=2004 AND Month()=04 AND DayOfMonth()=08
OR
Year()=2005 AND Month()=03 AND DayOfMonth()=24
OR
Year()=2006 AND Month()=04 AND DayOfMonth()=13
OR
Year()=2007 AND Month()=04 AND DayOfMonth()=05
OR
Year()=2008 AND Month()=03 AND DayOfMonth()=20
OR
Year()=2009 AND Month()=04 AND DayOfMonth()=09
OR
Year()=2010 AND Month()=04 AND DayOfMonth()=01

Calendar ASX true end-of-week

{ Plots correct end-of-week signals for ASX stocks, including ASX non-Friday end-of-week dates since 01/01/1980 }{ [email protected] }

Fml("Calendar ASX non-Friday end-of-week(1)")+Fml("Calendar ASX non-Friday end-of-week(2)") OR DayOfWeek()=5

(Go Top...)

Calendar Weekday of Month

{ Calendar-absolute, Weekday-of-Month signals }{ Plot on separate window below chart }{ ©Copyright 2004 Jose Silva }{ [email protected] }

dayChosen:=Input("day:  [1]Mon,  [2]Tue,  [3]Wed,  [4]Thu,  [5]Fri",1,7,5);
weekChosen:=Input("[1]st  [2]nd  [3]rd  [4]th  [5]th  week in month",1,5,1);
plot:=Input("plot:  [1]Weekday signals,  [2]Weekday count",1,2,1);

day:=DayOfWeek()=dayChosen;
d:=DayOfMonth();
signalCount:=
 If(day AND d<=7,1,
 If(day AND d>7 AND d<=14,2,
 If(day AND d>14 AND d<=21,3,
 If(day AND d>21 AND d<=28,4,
 If(day AND d>28,5,0)))));
signal:=weekChosen=signalCount;

If(plot=1,signal,signalCount)

(Go Top...)

Calendar Week of Month

{ Calendar-absolute Week-of-Month signals }{ Plot on own window below chart }{ ©Copyright 2004 Jose Silva }{ [email protected] }

WeekOfMonth:=Input("[1]st  [2]nd  [3]rd  [4]th  [5]th  week in month",1,5,1);
plot:=Input("[1]Week signals,  [2]Week count",1,2,1);

d:=DayOfMonth();
weekNr:=If(d<=7,1,
 If(d>7 AND d<=14,2,
 If(d>14 AND d<=21,3,
 If(d>21 AND d<=28,4,5))));
signal:=weekNr=WeekOfMonth;

If(plot=1,signal,WeekNr)
 

(Go Top...)

Cycle Length

{ Price peak/trough cycle length v4.0 }{ Warning: last peak/trough is dynamic!}{ Plot in own window below price chart }

{ 6/4/2004 ASX 1152 active stocks exploration, 3.25% ZigZag cycle lengths, mean price cycles: 3.7 trade days for positive price cycles; 4.5 trade days for negative price cycles; 8.2 trade days complete price cycles.}

{ ©Copyright 2004 Jose Silva }{ [email protected] }

zzper:=Input("ZigZag reversal %",.001,100,3.25);
pds:=Input("avg StdDev periods",2,2520,7);
plot:=Input("[1]Cycles, [2]Cycle Avg, [3]Avg StdDev, [4]ZigZag",1,4,1);

pk:=PeakBars(1,C,zzper)=0;
tr:=TroughBars(1,C,zzper)=0;
lastBar:=Cum(1)=LastValue(Cum(1));
lastLeg:=lastBar*LastValue(BarsSince(pk OR tr));

CycleUp:=pk*BarsSince(tr);
CycleUpAvg:=
 Cum(CycleUp)/(Cum(CycleUp>0)+.000001);
CycleUpStdDev:=Stdev(CycleUp,pds);
CycleUpStdDevAvg:=Cum(CycleUpStdDev)
 /(Cum(CycleUpStdDev>0)+.000001);

CycleDw:=tr*BarsSince(pk);
CycleDwAvg:=
 Cum(CycleDw)/(Cum(CycleDw>0)+.000001);
CycleDwStdDev:=Stdev(CycleDw,pds);
CycleDwStdDevAvg:=Cum(CycleDwStdDev)
 /(Cum(CycleDwStdDev>0)+.000001);

statCycle:=CycleUp-CycleDw;
lastLeg:=If(ValueWhen(1,pk OR tr,statCycle)<0,
 lastleg,-lastleg)*lastBar;
cycle:=statCycle+lastLeg;
zz:=Zig(cycle,zzper,%);

plotUp:=If(plot=1,0,
 If(plot=2,CycleUpAvg,
 If(plot=3,CycleUpStdDevAvg,0)));
plotDw:=If(plot=1,cycle,
 If(plot=2,-CycleDwAvg,
 If(plot=3,-CycleDwStdDevAvg,zz)));

plotUp;plotDw

Market Cycle Explorations

MetaStock -> Tools -> The Explorer -> New
Copy and paste formulae below.

Zig Zag price cycles

 *Input today's data date in filter section!*

Last (dynamic) and previous (static) cycles, based on default values in indicator "ZigZag Cycle Length".

6/4/2004 ASX 1152 active stocks exploration, 3.25% ZigZag cycle lengths, last price cycles:
  4 trade days for positive price cycles;
  5 trade days for negative price cycles;
  9 trade days complete price cycles.

©Copyright 2004 Jose Silva

Column A: + cycle

{ last positive dynamic cycle }
x:=Fml("ZigZag Cycle Length");
If(x>0,x,0)

Column B: - cycle

{ last negative dynamic cycle }
x:=Fml("ZigZag Cycle Length");
If(x<0,x,0)

Column C: AbsCycle

{ absolute last cycle }
Abs(Fml("ZigZag Cycle Length"))

Column D: + prev

{ previous complete (static) positive cycle }
x:=FmlVar("ZigZag Cycle Length","CYCLEUP");
ValueWhen(1,x<>0,x)

Column E: - prev

{ previous complete (static) negative cycle }
x:=FmlVar("ZigZag Cycle Length","CYCLEDW");
-ValueWhen(1,x<>0,x)

Column F: TotalPrv

{ total last complete (static) full cycle }
x:=FmlVar("ZigZag Cycle Length","CYCLEUP");
y:=FmlVar("ZigZag Cycle Length","CYCLEDW");
ValueWhen(1,x<>0,x)+ValueWhen(1,y<>0,y)

Filter:

{ Today's data date, user-input section }

day:=  6;     { current day of month (1~31) }
mth:=  4;     { current month (1~12)        }
yr:= 2004;    { current year, eg 2004       }

{ *********************************** }

DayOfMonth()=day
AND Month()=mth
AND Year()=yr
AND V>0

Zig Zag price cycle averages

 *Input today's data date in filter section!*

Historical Average & StdDev of static cycles, based on default values in indicator "ZigZag Cycle Length".

6/4/2004 ASX 1152 active stocks exploration, 3.25% ZigZag cycle lengths, mean price cycles: 3.7 trade days for positive price cycles; 4.5 trade days for negative price cycles; 8.2 trade days complete price cycles.

©Copyright 2004 Jose Silva

Column A: + avg

{ historical positive static cycle average }
FmlVar("ZigZag Cycle Length","CYCLEUPAVG")

Column B: - avg

{ historical negative static cycle average }
-FmlVar("ZigZag Cycle Length","CYCLEDWAVG")

Column C: TotalAvg

{ historical full static cycle average }
FmlVar("ZigZag Cycle Length","CYCLEUPAVG")+
Abs(FmlVar("ZigZag Cycle Length","CYCLEDWAVG"))

Column D: + StdDev

{ Standard Deviation of positive static cycles}
FmlVar("ZigZag Cycle Length",
"CYCLEUPSTDDEVAVG")

Column E: - StdDev

{ Standard Deviation of nagative static cycles}
-FmlVar("ZigZag Cycle Length",
"CYCLEDWSTDDEVAVG")

Column F: TotStdDv

{ Standard Deviation of full static cycles }
(FmlVar("ZigZag Cycle Length",
"CYCLEUPSTDDEVAVG")
+FmlVar("ZigZag Cycle Length",
"CYCLEDWSTDDEVAVG"))/2

Filter:

{ Today's data date, user-input section }

day:=  6;     { current day of month (1~31) }
mth:=  4;     { current month (1~12)        }
yr:= 2004;    { current year, eg 2004       }

{ *********************************** }

DayOfMonth()=day
AND Month()=mth
AND Year()=yr
AND V>0

(Go Top...)



If you have Metastock formulas you would like to share,
Please email to MetaStock Formula
We look forward to hearing from you!


To learn more about how to use Metastock and its formula click here.


copyright 2003 MetaStock Website Home
Metastock® is a registered trademark of Equis International.