METASTOCK FORMULAS     
Page 1
                                                     

Guppy MMA Oscillator

by Leon Wilson

((Mov(CLOSE,3,E)+Mov(CLOSE,5,E)+
Mov(CLOSE,8,E)+Mov(CLOSE,10,E)+
Mov(CLOSE,12,E)+Mov(CLOSE,15,E))-
(Mov(CLOSE,30,E)+Mov(CLOSE,35,E)+
Mov(CLOSE,40,E)+Mov(CLOSE,45,E)+
Mov(CLOSE,50,E)+Mov(CLOSE,60,E)))*10;
(Mov((Mov(CLOSE,3,E)+Mov(CLOSE,5,E)+
Mov(CLOSE,8,E)+Mov(CLOSE,10,E)+
Mov(CLOSE,12,E)+Mov(CLOSE,15,E))-
(Mov(CLOSE,30,E)+Mov(CLOSE,35,E)+
Mov(CLOSE,40,E)+Mov(CLOSE,45,E)+
Mov(CLOSE,50,E)+Mov(CLOSE,60,E)),13,E))*10;0;

Candle Shadow Support

This is a custom - made Formula based on Candlesticks called CANDLE SHADOW SUPPORT - RESISTANCE (by John D. Kontessis) Based on extensive study of the following books "Japanese Candlestick Charting Techniques", S.Nison, 1991 "Beyond Candlesticks" S.Nison, 1994 "Tehcical Analysis" X.E. Kourouklis, METAPUBLICATIONS (in greek language only) As we all know, one of the most important components of a candlestick is its shadow. A candle's shadow tends to get longer as prices get closer to support-resistance levels, as well as when they reach points of change in Trend (e.g. pullbacks or entry in ranging periods). As prices reach a Support level (or when building a support) the candles' lower shadows get longer. Consequently, as prices reach a Resistance Level (or when building a resistance) the candles' upper shadows get longer. The obvious problem that an analyst faces is that such subtle changes are difficult to discern and evaluate by naked eye only.

This problem can be easily solved by using the following two Formulas in Metastock's Indicator Builder. After Opening the "Indicator Builder", choose "New" and name the Formula : "CandleShadow Resistance ", enter the following :

ShadowResistance:=If(OPEN<CLOSE,(HIGH-CLOSE),(HIGH-OPEN));
Mov(ShadowResistance,3,S); {for not so short-term results, use:
Mov(ShadowResistance,10,w)}
and press "ok".

Now let's build the second Formula: After Opening the "Indicator Builder", choose "New" and name the Formula : "CandleShadow Support", enter the following :

ShadowSupport:=If(CLOSE>OPEN,(OPEN-LOW),(CLOSE-LOW)); Mov(ShadowSupport,3,S); {for not so short-term results, use: Mov(ShadowSupport,10,w)} and press "ok".

So far we have built two Formulas, who, after measuring the shadows of the candles in our chart, they "draw" a 3-Day Mov.Average of the size of the shadows (or alternatively a 10day weighted Mov.Average). The first Formula "CandleShadow Resistance" measures the upper shadow and the second Formula "CandleShadow Support" measures the lower shadow. You can always experiment with the type of Mov.Averages (simple, weighted, exponential etc) and the periods used so as to achieve the best "optical" results. Now let's see these Formulas at work. In an UPTREND : Higher Tops in "CandleShadow Resistance " and simultaneously lower tops in "CandleShadow Support" , state a weakness of the uptrend.(bearish signal). Lower Tops in "CandleShadow Resistance " and simultaneously higher tops in "CandleShadow Support" , state a strength of the uptrend. (bullish signal). In a DOWNTREND : Higher Tops in "CandleShadow Resistance " and simultaneously lower tops in "CandleShadow Support" , state a strength of the downtrend. (bearish signal). Lower Tops in "CandleShadow Resistance " and simultaneously higher tops in "CandleShadow Support" , state a weakness of the downtrend. (bullish signal). At your disposal for any questions or comments. John D.

Kontessis

http://users.otenet.gr/~kontesis
www.delphi.com/kontessis
http://groups.yahoo.com/group/greekanalysts  



Common Metastock Bar Patterns


BAR - 3 Higher Highs
H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(H,-2)>Ref(H,-3)

BAR - 3 Lower Lows & Reversal H
L>Ref(L,-1) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3) AND
Ref(L,-3)<Ref(L,-4)

BAR - 3 Lower Lows
L<Ref(L,-1) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3)

BAR - 5 Lower Lows
L<Ref(L,-1) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3) AND
Ref(L,-3)<Ref(L,-4) AND Ref(L,-4)<Ref(L,-5)

BAR - Expansion Buy
If(C > Ref(HHV(C,42),-1) AND H-L >= Ref(HHV((H-L),9),-1),1,0)

BAR - Expansion Sell
If(C < Ref(LLV(C,42),-1) AND (H-L) >= Ref(HHV((H-L),9),-1),1,0)

BAR - Fractal-down
If(LOW < Ref(LOW, -1),1,0) AND If(LOW < Ref(LOW, -2),1,0) AND If(LOW <
Ref(LOW,+1),1,0) AND If(LOW < Ref(LOW,+2),1,0)

BAR - Fractal-up
(If(HIGH > Ref(HIGH, -1),1,0) AND If(HIGH > Ref(HIGH, -2),1,0) AND If(HIGH
> Ref(HIGH, +1),1 ,0)AND If(HIGH > Ref(HIGH,+2),1,0))

BAR - Gap Down
GapDown()

BAR - Gap Up
GapUp()

BAR - H > Yesterday's H
H>Ref(H,-1)

BAR - Highest Bars Ago
HighestBars(CLOSE)

BAR - Highest High Value Bars Ago
HHVBars(CLOSE,50)

BAR - Inside Day + Day 3
Ref(Fml("BAR - Inside Day"),-3)

BAR - Inside Day
HIGH < Ref(HIGH,-1) AND LOW > Ref(LOW,-1)

BAR - Lizard Buy
If(O >= L + ((H-L) * .75) AND C >= L + ((H-L) * .75) AND L <
Ref(LLV(L,9),-1),1,0)

BAR - Lizard Sell
If(O <= L + ((H-L) * .25) AND C <= L + ((H-L) * .25) AND H >
Ref(HHV(H,9),-1),1,0)

BAR - Narrow Range 4
HIGH - LOW < Ref(LLV(H-L,3),-1)

BAR - Narrow Range 7
HIGH - LOW < Ref(LLV(H-L,6),-1)

BAR - O > Yesterday's C
O>Ref(C,-1)

BAR - Outside Day & > C
Outside() AND C>Ref(C,-1)

BAR - Outside Day
HIGH > Ref(HIGH,-1) AND LOW < Ref(LOW,-1)

BAR - Pivot Buy
If(H-L > Ref(HHV((H-L),9),-1) AND ((L <= Mov(C,50,S)) OR Ref(L,-1) <=
Ref(Mov(C,50,S),-1))
AND C > Mov(C,50,S),1,0)

BAR - Pivot Sell
If(H-L > Ref(HHV((H-L),9),-1) AND ((H >= Mov(C,50,S)) OR Ref(H,-1) >=
Ref(Mov(C,50,S),-1))
AND C < Mov(C,50,S),1,0)

BAR - Reaction Day with Volume
ReactionWithVol()

BAR - Reaction Day
Reaction()

BAR - Surprise Day Down
O<Ref(C,-1) AND C>O AND C<Ref(C,-1)

BAR - Surprise Day Up
O>Ref(C,-1) AND C<O AND C>Ref(C,-1)

BAR - Trough Value - 5
Trough(1,CLOSE,5)

BAR - Typical Price
Typical()

(from Walter Lake}

 

Miesal Indicator

"It's a short term timing tool. It's not worth using for long term
investors. Some have also suggested using periods of 25 or 50 days, though I
use only 10 days. Others have suggested it's very useful when used
in conjunction with Welles Wilder's RSI."

Sum(If(C > Ref(C,-1), +1, If(C < Ref(C,-1), -1, 0)),10)

Entry/Exit signal
buy:
Fml("CCIF-P")>Ref(Fml("CCIF-P"),-1) AND
Cross(Fml("CCIF-P"),-100) OR
Cross(Fml("CCIF-P"),100)

sell:
Fml("CCIF-P")<Ref(Fml("CCIF-P"),-1) AND
Cross(100,Fml("CCIF-P")) OR
Cross(-100,Fml("CCIF-P"))
{horizontal lines @ -100 & +100}

where:
{"CCIF-P" is}
(CCI(8)+CCI(13)+CCI(21))/3

{from Mike Arnoldi}

 

Mixed Balance Point Krause Update

I have updated some of the code since my last post concerning the TASC
articles written by Robert Krausz. The code now plots on the proper days
(instead of 1 day ahead) and they should also be more efficient to
calculate. These are named different so you should delete the old code after
you have installed the new. I will
also post a follow up with a graphic to show how these plot. Note: the
formulas on the Equis web page WILL NOT calculate for missing days
(Holidays).

from Adam Hefner.
VonHef@email.msn.com


MTF-Fixed Balance Point

name: MTF-Fixed Balance Point

{Multiple Time Frame
"Fixed Balance Point" 4/23/99}

Dw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);
Wt:=If(Dw=1,
{then}(Ref(HighestSince(1,Dw=1,H),-1)+
Ref(LowestSince(1,Dw=1,L),-1) +
Ref(C,-1))/3,
{else}0);
DwP:=ValueWhen(1,Wt>0,Wt);
Dwp


name: MTF-Fixed Balance Point Step

{Multiple Time Frame
"Fixed Balance Point Step" 4/23/99}

Dw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);
Wt:=If(Dw=1,
{then}(Ref(HighestSince(1,Dw=1,H),-1)+
Ref(LowestSince(1,Dw=1,L),-1) +
Ref(C,-1))/3,
{else}0);
DwPs:=(ValueWhen(1,Wt>0,Wt)+
ValueWhen(2,Wt>0,Wt)+
ValueWhen(3,Wt>0,Wt)+
ValueWhen(4,Wt>0,Wt)+
ValueWhen(5,Wt>0,Wt))/5;
Dwps
------------------------------------------------

name: MTF-Dynamic Balance Point

{Multiple Time Frame
Dynamic Balance Point 4/23/99}
dt:=DayOfWeek();
dc:=If(Dt=1,BarsSince(Ref(dt,-1)=1)+1,
If(Dt=2,BarsSince(Ref(dt,-1)=2)+1,
If(Dt=3,BarsSince(Ref(dt,-1)=3)+1,
If(Dt=4,BarsSince(Ref(dt,-1)=4)+1,
BarsSince(Ref(dt,-1)=5)+1))));
DBC:=If(dc=5,
{then}(Ref(HighestSince(5,dt,H),-1)+
Ref(LowestSince(5,dt,L),-1)+
Ref(CLOSE,-1))/3,
{else}(Ref(HighestSince(4,dt,H),-1)+
Ref(LowestSince(4,dt,L),-1)+
Ref(CLOSE,-1))/3);
DBC
------------------------------------------------

name: MTF-Dynamic Balance Point Step

{Multiple Time Frame
Dynamic Balance Point Step 4/23/99}
Dr:= FmlVar("MTF-Dynamic Balance Point","DBC");
Dsc:=(ValueWhen(1,Dr,Dr)+
ValueWhen(5,Dr,Dr)+
ValueWhen(10,Dr,Dr)+
ValueWhen(15,Dr,Dr)+
ValueWhen(20,Dr,Dr))/5;
Dsc
--------------------------------------------------

name: MTF-S&R

{Multiple Time Frame
"Weekly Support & Resistance" 4/23/99}

Dw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);
Wt:=If(Dw=1,
{then}(Ref(HighestSince(1,Dw=1,H),-1)+
Ref(LowestSince(1,Dw=1,L),-1) +
Ref(C,-1))/3,
{else}0);
Wh:=If(Dw=1,
{then}Ref(HighestSince(1,Dw=1,H),-1),
{else}0);
Wl:=If(Dw=1,
{then}Ref(LowestSince(1,Dw=1,L),-1),
{else}0);
Wr:=ValueWhen(1,Wh>0,Wh)-ValueWhen(1,Wl>0,Wl);
DwP:=ValueWhen(1,Wt>0,Wt);
RR1:=DwP+(Wr*.5);
RR2:=DwP+(Wr*.618);
SR1:=DwP-(Wr*.5);
SR2:=DwP-(Wr*.618);
SR2;
SR1;
RR1;
RR2;
---------------------------------------

name: MTF-Tendency

Mt:=If(DayOfWeek()=1,
Ref(C,-1)- FmlVar("MTF-Fixed Balance Point","DWP"),
0);
If(Mt>0,1,If(Mt<0,-1,0))
---------------------------------------



Weekly Indicators

MetaStock Weekly Indicators

I had basically put the weekly indicators on daily charts thing on the back
burner for the time being, but someone mentioned the subject in an off list
e-mail, and I decided that maybe I should post these two
indicators. They look right to me, but double check them. Remember, they
plot the previous weeks value beginning the first trading day of the
following week, and that value remains constant throughout that
week. These are designed for backtesting.....so if you just gotta know on
this Friday evening what the weekly value of the indicator is going to be
for the following week, simply look a weekly chart.

Stochastic: The %K and %K slowing can be coded to accommodate more
parameters by using the user Input function, but when you do this the %D
always calculates using the default value of the %K slowing, giving
erroneous values. So I just left it as is. Youcan plug in your own
values...I just used the MetaStock default values as a starting point. I
made the %K D as two separate indicators so that you can plot the %D a
different color and/or dashed. The Momentum indicator uses the Input
function just fine.


{`Wkly Stoch 5 per %K, slowing=3, no %D}

{start week}
sw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);
yestClo:=If(sw>0,Ref(C,-1),0);

{lowest low last 5 weeks}
LLow:=(ValueWhen(1,sw>0,
Ref(LowestSince(5,sw>0,L),-1)));

{highest high last 5 weeks}
HHigh:=(ValueWhen(1,sw>0,
Ref(HighestSince(5,sw>0,H),-1)));


{5 per %K, slowing=3}
y:=(ValueWhen(1,sw>0,(yestClo-LLow))+
ValueWhen(2,sw>0,(yestClo-LLow))+
ValueWhen(3,sw>0,(yestClo-LLow)))/

((ValueWhen(1,sw>0,HHigh)+
ValueWhen(2,sw>0,HHigh)+
ValueWhen(3,sw>0,HHigh))-

(ValueWhen(1,sw>0,LLow)+
ValueWhen(2,sw>0,LLow)+
ValueWhen(3,sw>0,LLow)))*100;
y;


=====================
{`Wkly Stoch 3 per %D of a 5 per %K, slowing=3}

{start week}
sw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);
yestClo:=If(sw>0,Ref(C,-1),0);

{lowest low last 5 weeks}
LLow:=(ValueWhen(1,sw>0,
Ref(LowestSince(5,sw>0=1,L),-1)));

{highest high last 5 weeks}
HHigh:=(ValueWhen(1,sw>0,
Ref(HighestSince(5,sw>0,H),-1)));


{5 per %K, slowing=3}
y:=(ValueWhen(1,sw>0,(yestClo-LLow))+
ValueWhen(2,sw>0,(yestClo-LLow))+
ValueWhen(3,sw>0,(yestClo-LLow)))/

((ValueWhen(1,sw>0,HHigh)+
ValueWhen(2,sw>0,HHigh)+
ValueWhen(3,sw>0,HHigh))-

(ValueWhen(1,sw>0,LLow)+
ValueWhen(2,sw>0,LLow)+
ValueWhen(3,sw>0,LLow)))*100;

{This plots the 3 period %D (ma) of the above.}
z:=(ValueWhen(1,sw>0,y)+ValueWhen(2,sw>0,y)+
ValueWhen(3,sw>0,y))/3;
z
========================

{`Wkly Momentum for DAILY Chart }

{This plots WEEKLY Momentum on DAILY charts. -Ken 4/16/99}

n:=Input("Periods",1,20,10);
{start week}
sw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);

(ValueWhen(1,sw>0,Ref(C,-1))/
ValueWhen(n+1,sw>0,
Ref(C,-1)))*100


from  Ken



Modified Williams %R Metastock Indicator

by Rajat Bose

Periods := Input("Time Period", 3,50,5);
NumDev := Input("No. of Standard Deviations", 1,5,2);

(100*(C-BBandBot(C, Periods, S, NumDev))/((( BBandTop(C, Periods, S,
NumDev))-(BBandBot(C, Periods, S, NumDev)))))

{All I have done here is to substitute High and Low of any bar with that of
Bollinger Band Top and Bollinger Band Bottom. I have tested it on various
time periods (for Bollinger Bands) using 2 standard deviations. It sometimes
gives an early indication of reversals than the Williams %R of the same
period. Divergences have also been somewhat better. However, the structure
shows that most of its properties are similar to those of the Williams %R
or, for that matter, of any other overbought-oversold indicator.}

 

Guppy MMA Indicators

(Note this is not the same as the formula given in Trading Tactics. Daryl Guppy)


Try MMA (Multiple Moving Averages). The shorter ones are closer to the
action and the longer ones tell you about the trend. I use two indicators
like this:

Name: MMA Long Term
--------
Mov(C,40,E);
Mov(C,45,E);
Mov(C,50,E);
Mov(C,55,E);

Name: MMA Short Term
--------
Mov(C,5,E);
Mov(C,8,E);
Mov(C,11,E);
Mov(C,14,E);


In the current market I like taking short momentum trades where the MMA
Short is bouncing up off a slowly rising MMA Long Term. The exit at the top
of the bubble is indicated by MMA Short turning down after a good separation
from the underlying MMA Long.

from Jeff Lederman.

{Suggestion: Create a single TEMPLATE with all the above indicators, giving
SHORT and LONG MMAs separate colours; e.g., RED for the SHORTs and BLUE for
the LONGs.}

 

Gann Swing Update

This is an update to Gann-Swing indicators I had posted several months
back. Most of the code has been improved and I have modified the swing
definition slightly.

Gann Weekly Expert Instructions

1. First create a new expert and name it whatever you want.
2a. under "trends" tab put this code for bullish:
ut:=FmlVar("GANN-Trend","TDV");
uplot:=If(BarsSince(Ut=1)<
BarsSince(Ut=-1),1,0);
uplot=1;
2b. and this for bearish:
dt:=FmlVar("GANN-Trend","TDV");
dplot:=If(BarsSince(dt=1)>
BarsSince(dt=-1),1,0);
dplot=1;
Then click on the "ribbon" option and turn off "Display Vertical Lines", I
also turn off
the corner option.
3a. Under highlights tab create a new and call it "HiLo Change", choose
color, and enter this code:
HLd:=If(CLOSE>Ref(Mov(H,3,S),-1),
{then}1,
{else}If(CLOSE<Ref(Mov(L,3,S),-1),
{then}-1,
{else}0));
HLv:=ValueWhen(1,HLd<>0,HLd);
HLv<>Ref(HLv,-1);
3b. Create new and call it "Up-Trend", choose color, and enter this code:
ut:=FmlVar("GANN-Trend","TD");
uplot:=If(BarsSince(Ut=1)<
BarsSince(Ut=-1),1,0);
uplot=1;
3c. Create new and call it "Down-Trend", choose color, and enter this code:
dt:=FmlVar("GANN-Trend","TD");
dplot:=If(BarsSince(dt=1)>
BarsSince(dt=-1),1,0);
dplot=1;
4a. Under "Symbols" tab create new and call it " UpSwing", enter this code:
FmlVar("GANN-Swing","SD2")=1;
then under graphic choose "Buy Arrow", choose color (Dark Green), and small
size, then pick "Above Price Plot".
4b. Create new and call it "DownSwing", enter this code:
FmlVar("GANN-Swing","SD2")=-1;
then under graphic choose "sell arrow", choose color (Dark Red), and small
size, then pick "Below Price Plot".
As for the HiLo ....just plot it as a regular indicator and choose the last
"style" option under "color/style" tab.

Note: For daily bar charts ribbon use these formulas:

2a. ut:= FmlVar("GaW-Trend","TDV") ;
uplot:=If(BarsSince(Ut=1)<
BarsSince(Ut=-1),1,0);
uplot=1;

2b. dt:= FmlVar("GaW-Trend","TDV") ;
dplot:=If(BarsSince(dt=1)>
BarsSince(dt=-1),1,0);
dplot=1;

from Adam Hefner.

------------------------------------------------------
name: GANN-HiLo

{HiLo 4/27/99}
Lb:=Input("Look-Back Periods?",2,10,3);
HLd:=If(CLOSE>Ref(Mov(H,Lb,S),-1),
{then}1,
{else}If(CLOSE<Ref(Mov(L,Lb,S),-1),
{then}-1,
{else}0));
HLv:=ValueWhen(1,HLd<>0,HLd);
HiLo:=If(HLv=-1,
{then}Mov(H,Lb,S),
{else}Mov(L,Lb,S));
HiLo;
------------------------------------------
name: GANN-Swing

{Gann-Swing 4/27/99}
{Market swing is defined as:
Up = 2 higher highs,
Down = 2 lower lows.}
Us:=BarsSince(Sum(H>Ref(H,-1),2)=2);
Ds:=BarsSince(Sum(L<Ref(L,-1),2)=2);
Hc:=HighestSince(1,Us=0,H);
Lc:=LowestSince(1,Ds=0,L);
Sd1:=If(Us=0,
{then}If((L<>Lc) AND (Ref(L,-1)<>Lc),
{then}1,
{else}0),
{else}If(Ds=0,
{then}If((H<>HC) AND (Ref(H,-1)<>Hc),
{then}-1,
{else}0),
{else}0));
Sd2:=If(Sd1=1,
{then} If(Ref(BarsSince(Sd1=1),-1) >
Ref(BarsSince(Sd1=-1),-1),
{then}1,
{else}0),
{else} If(Sd1=-1,
{then}If(Ref(BarsSince(Sd1=1),-1) <
Ref(BarsSince(Sd1=-1),-1),
{then}-1,
{else}0),
{else}0));
TD1:=ValueWhen(1,Sd2<>0,Sd2);
Td1;
--------------------------------------------
name: GANN-Trend

{Gann-Trend 4/27/99}
{Swing Direction}
Sd:= FmlVar("GANN-Swing","TD1") ;
{Swing Change High}
Sch:=If(Sd=1 AND Ref(sd,-1)=-1,
{then}1,
{else}0);
{Swing Change Low}
Scl:=If(Sd=-1 AND Ref(Sd,-1)=1,
{then}1,
{else}0);
{Peak Value}
Pv:=If(Scl=1,
{then}HighestSince(1,Sch=1,H),
{else}0);
{Trough Value}
Tv:=If(Sch=1,
{then}LowestSince(1,Scl=1,L),
{else}0);
{Trend Direction}
Td:=If(H>ValueWhen(1,Pv>0,Pv),
{then}1,
{else}If(L<ValueWhen(1,Tv>0,Tv),
{then}-1,
{else}0));
{UpTrend=1 DownTrend =-1}
Tdv:=ValueWhen(1,Td<>0,Td);
Tdv
------------------------------------------
name: GaW-Swing

{Weekly Swing 4/27/99}
{Market swing is defined as:
Up = 2 higher highs,
Down = 2 lower highs }
{Weekly High/Low}
Dw:=If(DayOfWeek()<=Ref(DayOfWeek(),-1),1,0);
Wh:=If(Dw=1,
{then}Ref(HighestSince(1,Dw=1,H),-1),
{else}0);
Wl:=If(Dw=1,
{then}Ref(LowestSince(1,Dw=1,L),-1),
{else}0);
Hv1:=ValueWhen(1,Wh>0,Wh);
Hv2:=ValueWhen(2,Wh>0,Wh);
Hv3:=ValueWhen(3,Wh>0,Wh);
Lv1:=ValueWhen(1,Wl>0,Wl);
Lv2:=ValueWhen(2,Wl>0,Wl);
Lv3:=ValueWhen(3,Wl>0,Wl);
Us:=BarsSince((Hv1 > Hv2) AND (Hv2 > Hv3));
Ds:=BarsSince((Lv1 < Lv2) AND (Lv2 < Lv3));
Hc:=Ref(HighestSince(1,Us=0 AND Ref(Us,-1)>0,H),
-1);
Lc:=Ref(LowestSince(1,Ds=0 AND Ref(Ds,-1)>0,L),
-1);
{Swing direction Calculation}
Sd1:=If(Us=0 AND Dw=1,
{then}If((Lv1<>Lc) AND (Lv2<>Lc),
{then}1,
{else}0),
{else}If(Ds=0,
{then}If((Hv1<>Hc) AND (Hv2<>Hc),
{then}-1,
{else}0),
{else}0));
Sd2:=If(Sd1=1,
{then} If(Ref(BarsSince(Sd1=1),-1) >
Ref(BarsSince(Sd1=-1),-1),
{then}1,
{else}0),
{else} If(Sd1=-1,
{then}If(Ref(BarsSince(Sd1=1),-1) <
Ref(BarsSince(Sd1=-1),-1),
{then}-1,
{else}0),
{else}0));
TD1:=ValueWhen(1,Sd2<>0,Sd2);
TD1
-------------------------------------------
name: GaW-Trend

{Weekly Trend 4/27/99}
{Swing Direction}
Sd:= FmlVar("GaW-Swing","TD1") ;
{Swing Change High}
Sch:=If(Sd=1 AND Ref(sd,-1)=-1,
{then}1,
{else}0);
{Swing Change Low}
Scl:=If(Sd=-1 AND Ref(Sd,-1)=1,
{then}1,
{else}0);
{Peak Value}
Pv:=If(Scl=1,
{then}HighestSince(1,Sch=1,H),
{else}0);
{Trough Value}
Tv:=If(Sch=1,
{then}LowestSince(1,Scl=1,L),
{else}0);
{Trend Direction}
Td:=If(H>ValueWhen(1,Pv>0,Pv),
{then}1,
{else}If(L<ValueWhen(1,Tv>0,Tv),
{then}-1,
{else}0));
{UpTrend=1 DownTrend =-1}
Tdv:=ValueWhen(1,Td<>0,Td);
Tdv



Stop Loss Indicator

periodsshort:=Input("periods if short",1,50,10); periodslong:=input("periods
if long",1,50,10);

HHV(H,periodsshort)-atr(periodsshort);{stop loss level for short positions}
LLV(L,periodslong)+ATR(periodslong);{stop loss level for long positions}

{by Eric Kendall}

 

Gap Up Formulas

The MetaStock formulas to calculate these percentages are shown below. The
first input is the minimum gap (e.g., 1%), and the second input is the gap
increment (e.g., 1%, which would give you a range of 1-2%). To calculate
gaps down, change the percentage to a negative.

Formula to determine whether the closing price is equal to or exceeds the
opening price on a gap day:

MinGap := Input("Minimum gap to consider (%)",-10000,10000,1);
GapIncrement := Input("Gap Increment (%)",0,100,1);

LookingForGapUp := MinGap >= 0; LookingForGapDown := MinGap < 0;

{ Gap percentage }
Gap := (OPEN - Ref(CLOSE,-1))/Ref(CLOSE,-1)*100;

NumGaps := If(LookingForGapUp, Cum(Gap >= MinGap AND Gap < MinGap +
GapIncrement), If(LookingForGapDown, Cum(Gap <= MinGap AND Gap > MinGap -
GapIncrement),0));

If(LookingForGapUp, Cum(If(Gap >= MinGap AND Gap < MinGap + GapIncrement,
If(CLOSE >= OPEN, +1,0),0)),

If(LookingForGapDown, Cum(If(Gap <= MinGap AND Gap > MinGap - GapIncrement,
If(CLOSE <= OPEN, +1, 0),0)), 0))/NumGaps*100;

Formula to determine whether the daily range crosses the previous day’s
close on a gap day:

MinGap := Input("Minimum gap to consider (%)",-10000,10000,1);
GapIncrement := Input("Gap Increment (%)",0,100,1);

LookingForGapUp := MinGap >= 0; LookingForGapDown := MinGap < 0;

{ Gap percentage }
Gap := (OPEN - Ref(CLOSE,-1))/Ref(CLOSE,-1)*100;

NumGaps := If(LookingForGapUp, Cum(Gap >= MinGap AND Gap < MinGap +
GapIncrement), If(LookingForGapDown, Cum(Gap <= MinGap AND Gap > MinGap -
GapIncrement),0));

If(LookingForGapUp, Cum(If(Gap >= MinGap AND Gap < MinGap + GapIncrement,
If(LOW <= Ref(CLOSE,-1), +1,0),0)),

If(LookingForGapDown, Cum(If(Gap <= MinGap AND Gap > MinGap - GapIncrement,
If(HIGH >= Ref(CLOSE,-1), +1, 0),0)), 0))/NumGaps*100;

Formula to determine whether the following day’s open continues the gap
trend:

MinGap := Input("Minimum gap to consider (%)",-10000,10000,1);
GapIncrement := Input("Gap Increment (%)",0,100,1);

LookingForGapUp := MinGap >= 0; LookingForGapDown := MinGap < 0;

GapYesterday := (Ref(OPEN,-1) - Ref(CLOSE,-2))/Ref(CLOSE,-2)*100;

NumGapsthruYesterday := If(LookingForGapUp, Cum(GapYesterday >= MinGap AND
GapYesterday < MinGap + GapIncrement), If(LookingForGapDown,
Cum(GapYesterday <= MinGap AND GapYesterday > MinGap - GapIncrement),0));

If(LookingForGapUp, Cum(If(GapYesterday >= MinGap AND GapYesterday < MinGap
+ GapIncrement, If(OPEN > Ref(CLOSE,-1), +1,0),0)),

If(LookingForGapDown, Cum(If(GapYesterday <= MinGap AND GapYesterday >
MinGap - GapIncrement, If(OPEN < Ref(CLOSE,-1), +1, 0),0)),
0))/NumGapsthruYesterday*100;