in Search

ZigZag (Swing lines) indicator

Last post 12-31-2009, 1:24 by Asad. 14 replies.
Sort Posts: Previous Next
  •  09-04-2009, 19:12 30611

    ZigZag (Swing lines) indicator

    Hello,

    Could you please assist me with writng a custom indicator that will plot swing lines, with the following rules: 

    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), 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) 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 30615 in reply to 30611

    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 30617 in reply to 30615

    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 30618 in reply to 30615

    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 30619 in reply to 30618

    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 30623 in reply to 30619

    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 30628 in reply to 30623

    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 30635 in reply to 30628

    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 30638 in reply to 30635

    Re: ZigZag (Swing lines) indicator

    Where can I upload it?
  •  09-09-2009, 0:23 30640 in reply to 30638

    Re: ZigZag (Swing lines) indicator

    http://imageshack.us/
  •  09-09-2009, 0:34 30641 in reply to 30619

    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 30642 in reply to 30641

    Re: ZigZag (Swing lines) indicator

    http://img179.imageshack.us/i/swingline.jpg/

    If you go to the link above, you'll see what the swing lines should look like (in blue)...it's easier to understand it from a picture.

    Rgds

    Damien

  •  09-09-2009, 20:54 30649 in reply to 30642

    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 30658 in reply to 30649

    Re: ZigZag (Swing lines) indicator

    Thanks. I tried, but it's just not working for me...
  •  12-31-2009, 1:24 31567 in reply to 30611

    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
View as RSS news feed in XML