[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SR ZigZag Trend v.4 (full)



PureBytes Links

Trading Reference Links

This 4th version of the SR ZigZag Trend indicator (short name: "SR ZZT")
works with both methods (Percents AND Points) and can calculate various
price fields (Open, High, Low, Close AND Indicators). This means that you
can use it to check for valid trends and swing points of various prices and
indicators, for valid divergences, for comparisons and much more. The code
is quite fast, clear and very easy to follow. So please do not change it in
case you need to refer to it.


{SR ZigZag Trend (SR ZZT) v.4}
{by Spyros Raftopoulos}

{It is based on the Zig Zag indicator and it returns 1 for a confirmed
uptrend, and -1 for a confirmed downtrend.}

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

vr:=Input("Field (0=Ind/tor, 1=Open, 2=High, 3=Low, 4=Close)",0,4,0);
amnt:=Input("Reversal amount",0.001,1000,10);
md:=Input("Method (1=Percent, 2=Points)",1,2,1);
{****************************************}

vr:=If(vr=1,OPEN,If(vr=2,HIGH,If(vr=3,LOW,If(vr=4,CLOSE,P))));
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


Before you start using it, please read the following.

- The default field value is 0 (the "P" special data array identifier),
since this makes the indicator ready for use in various situations.
Furthermore this choice ensures that when no other plot is used, the SR ZZT
indicator will use Close prices (read about the "P" variable in the MS
manual for more information).

- However, if you drop the indicator on a plot but you have chosen another
option (say 4, for Close), then SR ZZT will examine the Close prices instead
of the plot it was dropped on.

- Some indicators return negative and/or zero values. Though SR ZZT can
handle such values too, the Percent method might practically result in
misleading indications. For example consider the following cases: from -50
to +50 there is a 200% change, whereas from -100 to +50 there is only 150%
change and even more interestingly from -50 to 0 we have 100% change and
from -1 to 0 we have also 100% change! This means that when you drop a zig()
on CMO() for example, you might see the zig (even one with percent=100)
forming zigzags also for tiny CMO() changes! This is practically useless in
analysis, but it is neither a problem of the SR ZZT nor of the Zigzag
indicator. It is rather a strange situation related to percentage
calculations (a mathematical one).
In order to use zig or SR ZZT with indicators returning zero and/or negative
values, you might prefer to use POINTS instead of percentages in many cases.

- On the other hand, the Points method has the following disadvantage: a
fixed difference in points is much more easily covered by large absolute
values than by small ones. For example suppose you search for a reversal
amount of 2 points. It is very easy for the close price to go from 100 to
102 (=2%), but very hard to go from 2 to 4 (=100%). If you drop a zig using
2 points reversal amount on a security, you will notice that it is much more
volatile in high prices than in low ones!

Therefore the method to be used in each situation should be carefully
considered.
In difficult cases, a solution could be to check by using both methods
(percent AND points) providing the proper reversal amount for each method.

A few calculations showed that the indicator works fine, but please check it
yourselves and let me know if you find anything strange in its behaviour.
To check it:
1. Drop a zig() on an indicator (say CMO).
2. Drop SR ZZT with the same method, the same reversal amount and Field=0 on
the same indicator (CMO).
3. Manually calculate the difference between a swing point and the CMO's
value when SR ZZT changes direction. If this value>=abs(reversal amount)
Then,
4. Manually calculate the difference between the same swing point and the
CMO's value 1 bar before SR ZZT changes direction. If this
value<abs(reversal amount) then everything is fine. Else, take a detailed
note and contact me.
End if.

I hope you find this indicator as useful as I do. Have fun and take care.
Spyros


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 19/04/02