|
|
ZigZag (Swing lines) indicator
Last post 12-31-2009, 1:24 by Asad. 14 replies.
-
09-04-2009, 19:12 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
ZigZag (Swing lines) indicator
Hello,
Could you please assist me with writng a custom indicator that will plot swing lines, with the following rules:
- Swing lines connect either Highs or Lows of individual bars - never Open or Close.
- If the next bar has a higher high and a higher low (or the same low) when compared to the previous bar, then the swing line goes up connecting the high of the next bar.
- If the next bar has a lower high (or same high) and a lower low when compared to the previous bar, then the swing line goes down connecting the low of the next bar.
- If the next bar is an inside bar (lower high and higher low), ignore it and don’t plot a line on it at all – wait for the next bar.
- If the next br is an outside bar (higher high and lower low), plot a swing line on the high of an outside bar if the following bar (one after the outside bar) is lower, OR plot a swing line on the low of an outside bar if the following bar (one after the outside bar) is higher.
Regards
Damien
|
|
-
09-06-2009, 22:04 |
-
johnl
-
-
-
Joined on 11-08-2005
-
-
Posts 388
-
-
|
Re: ZigZag (Swing lines) indicator
a1:=If((H>Ref(H,-1) and (L>Ref(L,-1)),H,prev); a2:=If((H<Ref(H,-1) and (L<Ref(L,-1)),L,prev); Your #2 and #3 should look like this, from this code you should be able to work out the rest.
|
|
-
09-07-2009, 5:01 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
Re: ZigZag (Swing lines) indicator
Hi,
Thanks for this. It's not working. Would you pleasee write the complete formula so I could test it then?
Rgds
Damien
|
|
-
09-07-2009, 5:44 |
-
bobylam
-
-
-
Joined on 06-25-2009
-
-
Posts 11
-
-
|
Re: ZigZag (Swing lines) indicator
maybe this is what john1 mean: just one more ")"
If((H>Ref(H,-1)) AND (L>Ref(L,-1)),H,PREV); If((H<Ref(H,-1)) AND (L<Ref(L,-1)),L,PREV);
|
|
-
09-07-2009, 7:07 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
Re: ZigZag (Swing lines) indicator
Thanks. Now there is no error, but the formula has produced no result/swing line at all.
Rgds
Damien
|
|
-
09-07-2009, 10:35 |
-
bobylam
-
-
-
Joined on 06-25-2009
-
-
Posts 11
-
-
|
Re: ZigZag (Swing lines) indicator
Damien:Thanks. Now there is no error, but the formula has produced no result/swing line at all.
Rgds
Damien
maybe this is what you most wanted :-) a1:= If((H>Ref(H,-1)) AND (L>Ref(L,-1)),H,PREV); a2:= If((H<Ref(H,-1)) AND (L<Ref(L,-1)),L,PREV); If( a1<>Ref(a1,-1),a1,a2);
|
|
-
09-08-2009, 6:08 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
Re: ZigZag (Swing lines) indicator
Thanks.
I wanted to attach a screen shot of swing lines on a real chart....that would assist in the explanation what it should look like. Do you maybe have an email I could send you that?
Rgds
Damien
|
|
-
09-08-2009, 20:47 |
-
johnl
-
-
-
Joined on 11-08-2005
-
-
Posts 388
-
-
|
Re: ZigZag (Swing lines) indicator
The attachment didn't work Upload it to the internet and give us a link to the jpg. Thanks.
|
|
-
09-08-2009, 23:21 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
Re: ZigZag (Swing lines) indicator
|
-
09-09-2009, 0:23 |
-
09-09-2009, 0:34 |
-
bobylam
-
-
-
Joined on 06-25-2009
-
-
Posts 11
-
-
|
Re: ZigZag (Swing lines) indicator
Damien:Thanks. Now there is no error, but the formula has produced no result/swing line at all.
Rgds
Damien
this code worked, you can see sample with DJ If((H>Ref(H,-1)) AND (L>Ref(L,-1)),H,PREV); If((H<Ref(H,-1)) AND (L<Ref(L,-1)),L,PREV); sample: http://img193.imageshack.us/img193/4686/swinglines.png
|
|
-
09-09-2009, 0:55 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
Re: ZigZag (Swing lines) indicator
|
-
09-09-2009, 20:54 |
-
johnl
-
-
-
Joined on 11-08-2005
-
-
Posts 388
-
-
|
Re: ZigZag (Swing lines) indicator
Thanks for the chart, much better. Play around with- a1:=Trough(2,C,5); a1 It might be closer to what you are looking for. Be careful with zigzag, the first zigzag is bogus.
|
|
-
09-10-2009, 5:39 |
-
Damien
-
-
-
Joined on 06-19-2009
-
-
Posts 14
-
-
|
Re: ZigZag (Swing lines) indicator
Thanks. I tried, but it's just not working for me...
|
|
-
12-31-2009, 1:24 |
-
Asad
-
-
-
Joined on 02-28-2007
-
-
Posts 1
-
-
|
Re: ZigZag (Swing lines) indicator
Dear Damien:
As per your query following codings would appropriate.
pr:=Input("Reversal amount", 0.001,100000,1);
pk:=PeakBars(1,H ,pr)=0;
tr:=TroughBars(1,L,pr)=0;
oHi:=Zig(H ,pr,%);
oLo:=Zig(L,pr,%);
avg:=(oHi+oLo)/2;
x:=If(H>Ref(H,-1) AND LIf(HRef(L,-1),LOW,
If(HIf((Ref(LOW,-1)>(H>Ref(H,-1) AND L>Ref(L,-1))) ,HIGH ,
If((Ref(HIGH,-1)>(H>Ref(H,-1) AND L>Ref(L,-1))),LOW, If(avg>Ref(avg ,-1),L,H)))) ));
X1:=Zig(x,pr,%);
X1;
But not equals to the indicator ploted on HSI graph that you had sent me via e-mail. You have to rewrite the rules if you want an accurate indicator equals to the indicator ploted on HSI graph .
1- Swing lines connect either Highs or Lows of individual bars - never Open or Close.
2 -If the next bar has a higher high and a higher low (or the same low) when compared to the previous bar, then the swing line goes up connecting the high of the next bar.
3- If the next bar has a lower high (or same high) and a lower low when compared to the previous bar, then the swing line goes down connecting the low of the next bar.
4- If the next bar is an inside bar (lower high and higher low than the previous bar), ignore it and don’t plot a line on it at all – wait for the next bar.
5- If the next br is an outside bar (higher high and lower low), plot a swing line on the high of an outside bar if the following bar (one after the outside bar) has a lower low than the outside bar, OR plot a swing line on the low of an outside bar if the following bar (one after the outside bar) has a higher high than the outside bar.
However i tried to make it equal with the ploted indicator on HSI graph but some thing is missing or over the rules due these reasons i cant able to shape final.
pr:=Input("Reversal amount", 0.001,100000,.96);
pk:=PeakBars(1,H ,pr)=0;
tr:=TroughBars(1,L,pr)=0;
oHi:=Zig(H ,pr,%);
oLo:=Zig(L,pr,%);
avg:=(oHi+oLo)/2;
x:=If(pk,ohi,If(tr,olo,
If(Inside(),PREVIOUS,
If(Outside(),LOW ,If(Outside()>Ref(H,-1),LOW,If(L>Ref(Outside(),-1),HIGH, avg))))));
X1:=Zig(x,pr,%);
X1;
Regards
Asad Tirmazie
Head of Equity
Azee Securities (Pvt) Limited
drfund21@yahoo.com
0092321-8247969
|
|
|
|