MetaStock™ Zone Forum & FAQ Artykuły Linki Elliott Waves EasyLanguage™ Zone

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

ZigZagTrend Sum by Spyros Raftopoulos

It is based on the SR ZigZag Trend indicator. It is actually a sum of 5 fixed-amount
SR ZigZag Trend indicators (I have suggested 3%, 5%, 10%, 15% and 20% but these values can be changed to suit the user's preferences.) This indicator is quite suitable for Experts since it shows the strength of the trend. Such an Expert with Highlights and a simple Commentary is also provided below.

This indicator is the sum of 5 fixed-amount SR Zigzag Trends (SR ZZTs) and it shows the strength of a trend.

Make 5 fixed amount indicators called "SR ZZT1", "SR ZZT2", ..."SR ZZT5" that use different reversal amounts. I had suggested 3%, 5%, 10%, 15% and 20% respectively, but one can use Fibonacci numbers instead: 3, 5, 8, 13, 21 or try other values. Some users complained that they don't see anything displayed in their charts.

If this happens, use lower numbers for the reversal amounts and/or increase the number of periods displayed in your chart. The code for each one of the SR ZZTs is this:

SR ZZT1

{******************** Start of code **********************}
{SR ZZT1}
amnt:=3; {This is different for each of the 5 indicators}

{ Don't change anything below this line unless you know what you are
doing}
md:=1;
vr:=CLOSE;
zz0:=If(md=1, Zig(vr,amnt,%), Zig(vr,amnt,\$));
zz1:=Ref(zz0,-1);
zz2:=Ref(zz0,-2);

tr:=ValueWhen(1,zz0>zz1 AND zz1<zz2, zz1);
pk:=ValueWhen(1,zz0<zz1 AND zz1>zz2, zz1);
PU:=If(md=1,tr+Abs(tr)*amnt/100,tr+amnt);
PD:=If(md=1,pk-Abs(pk)*amnt/100,pk-amnt);

res:=If(vr>=PU AND zz0>zz1,1,
If(vr<=PD AND zz0<zz1,-1,0));
res:=If(res<>0,res,ValueWhen(1,res<>0,res));
res
{********************* End of code *********************}

SR ZZT2

{******************** Start of code **********************}
{SR ZZT1}
amnt:=5; {This is different for each of the 5 indicators}

{ Don't change anything below this line unless you know what you are
doing}
md:=1;
vr:=CLOSE;
zz0:=If(md=1, Zig(vr,amnt,%), Zig(vr,amnt,\$));
zz1:=Ref(zz0,-1);
zz2:=Ref(zz0,-2);

tr:=ValueWhen(1,zz0>zz1 AND zz1<zz2, zz1);
pk:=ValueWhen(1,zz0<zz1 AND zz1>zz2, zz1);
PU:=If(md=1,tr+Abs(tr)*amnt/100,tr+amnt);
PD:=If(md=1,pk-Abs(pk)*amnt/100,pk-amnt);

res:=If(vr>=PU AND zz0>zz1,1,
If(vr<=PD AND zz0<zz1,-1,0));
res:=If(res<>0,res,ValueWhen(1,res<>0,res));
res
{********************* End of code *********************}

SR ZZT3

{******************** Start of code **********************}
{SR ZZT1}
amnt:=10; {This is different for each of the 5 indicators}

{ Don't change anything below this line unless you know what you are
doing}
md:=1;
vr:=CLOSE;
zz0:=If(md=1, Zig(vr,amnt,%), Zig(vr,amnt,\$));
zz1:=Ref(zz0,-1);
zz2:=Ref(zz0,-2);

tr:=ValueWhen(1,zz0>zz1 AND zz1<zz2, zz1);
pk:=ValueWhen(1,zz0<zz1 AND zz1>zz2, zz1);
PU:=If(md=1,tr+Abs(tr)*amnt/100,tr+amnt);
PD:=If(md=1,pk-Abs(pk)*amnt/100,pk-amnt);

res:=If(vr>=PU AND zz0>zz1,1,
If(vr<=PD AND zz0<zz1,-1,0));
res:=If(res<>0,res,ValueWhen(1,res<>0,res));
res
{********************* End of code *********************}

SR ZZT4

{******************** Start of code **********************}
{SR ZZT1}
amnt:=15; {This is different for each of the 5 indicators}

{ Don't change anything below this line unless you know what you are
doing}
md:=1;
vr:=CLOSE;
zz0:=If(md=1, Zig(vr,amnt,%), Zig(vr,amnt,\$));
zz1:=Ref(zz0,-1);
zz2:=Ref(zz0,-2);

tr:=ValueWhen(1,zz0>zz1 AND zz1<zz2, zz1);
pk:=ValueWhen(1,zz0<zz1 AND zz1>zz2, zz1);
PU:=If(md=1,tr+Abs(tr)*amnt/100,tr+amnt);
PD:=If(md=1,pk-Abs(pk)*amnt/100,pk-amnt);

res:=If(vr>=PU AND zz0>zz1,1,
If(vr<=PD AND zz0<zz1,-1,0));
res:=If(res<>0,res,ValueWhen(1,res<>0,res));
res
{********************* End of code *********************}

SR ZZT5

{******************** Start of code **********************}
{SR ZZT1}
amnt:=20; {This is different for each of the 5 indicators}

{ Don't change anything below this line unless you know what you are
doing}
md:=1;
vr:=CLOSE;
zz0:=If(md=1, Zig(vr,amnt,%), Zig(vr,amnt,\$));
zz1:=Ref(zz0,-1);
zz2:=Ref(zz0,-2);

tr:=ValueWhen(1,zz0>zz1 AND zz1<zz2, zz1);
pk:=ValueWhen(1,zz0<zz1 AND zz1>zz2, zz1);
PU:=If(md=1,tr+Abs(tr)*amnt/100,tr+amnt);
PD:=If(md=1,pk-Abs(pk)*amnt/100,pk-amnt);

res:=If(vr>=PU AND zz0>zz1,1,
If(vr<=PD AND zz0<zz1,-1,0));
res:=If(res<>0,res,ValueWhen(1,res<>0,res));
res
{********************* End of code *********************}

This was the code for SR ZZT1. After you have created it, make a copy of it, name it "SR ZZT2" and change the reversal amount to read amnt:=5;

Leave the rest of the code as it is. Make subsequent copies, each time using a different amount, until you have made all 5 SR ZZTs. After you've done that, create the SR ZZTsum indicator:

ZigZag Trend Sum

{***********************Start of code ***********************}
{SR ZZTsum}
Fml("SR ZZT1") + Fml("SR ZZT2") + Fml("SR ZZT3") + Fml("SR ZZT4") +
Fml("SR ZZT5")
{*********************** End of code *********************}

Since this indicator sums the 5 binary (1 or -1) SR ZZTs, it returns these values: 5, 3, 1, -1, -3, -5, where 5 represents a very strong uptrend and -5 a very strong downtrend.

In case you decide later that the reversal amounts of some SR ZZTs should be different, you can simply open

the corresponding indicators and change the value of the "amnt" variable. No changes are necessary for the SR ZZTsum.

Contact me for comments or questions at raftsp@otenet.gr

Source / From: TOP
Metastockusers[at]yahoogroups[dot]com

Equis and MetaStock® and MetaStock Professional® are registered trademarks of Equis International. Achelis Binary Wave®, The DownLoader®,
Expert Advisor®, OptionScope®, Quotecenter® and Smart Charts® are trademarks of Equis International, a Thomson Reuters company.