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

Re: [amibroker] Re: ZigZag code



PureBytes Links

Trading Reference Links

Title: Re: [amibroker] Re: ZigZag code


I think this was posted by Dave, a long time ago:


 function ZigZagHL(prcnt)

{


// -------------------------------------------------------------------------

global ZigArray_HL;


WavePcnt = (1+0.01*prcnt);


End_Val_HL   = Avg[0];

Start_Val_HL = End_Val_HL;


End_Bar_HL   = 0;

Start_Bar_HL = End_Bar_HL;


Switch_HL = 0;


Hs_cnd = (Ref(H,-1) <= Ref(H,0) AND Ref(H,0) >= Ref(H,1));

Ls_cnd = (Ref(L,-1) >= Ref(L,0) AND Ref(L,0) <= Ref(L,1));


Hs_Swing = IsTrue(Hs_cnd)  AND (Ls_cnd==False);

Ls_Swing = (Hs_cnd==False) AND IsTrue(Ls_cnd);


//--------------------------------------------------------------------------


     for (i=0; i < BarCount; i++)

     {

         ZigArray_HL[i] = -1.0E10; 


         // Swing High -----------------------------------------------------


         if ( i > 0 AND i < BarCount AND Hs_Swing[i] )

              SwingHigh_HL = H[i];

         else

              SwingHigh_HL = -1;


         // Swing Low ------------------------------------------------------


         if ( i > 0 AND i < BarCount AND Ls_Swing[i] )

              SwingLow_HL = L[i];

         else

              SwingLow_HL = -1;


         // ZigZag ---------------------------------------------------------


         if ( SwingHigh_HL != -1)

         {     

              if (

                   Switch_HL[i-1] != 1 

                        AND SwingHigh_HL >= (End_Val_HL * WavePcnt) )

              {

                   Start_Bar_HL = End_Bar_HL;

                   Start_Val_HL = End_Val_HL;

                   End_Bar_HL = i;

                   End_Val_HL = SwingHigh_HL;


                   for( j = Start_Bar_HL; j <= End_Bar_HL; j++ )

                   {

                   ZigArray_HL[j] = Start_Val_HL 

                                     + (j - Start_Bar_HL)

                                       * (End_Val_HL - Start_Val_HL)

                                        / (End_Bar_HL - Start_Bar_HL );

                   }

                   Switch_HL = 1;

              }

              else

              if (Switch_HL[i-1] == 1 AND SwingHigh_HL >= End_Val_HL)

              {

                   End_Bar_HL = i;

                   End_Val_HL = SwingHigh_HL;


                   for( j = Start_Bar_HL; j <= End_Bar_HL; j++ )

                   {

                   ZigArray_HL[j] = Start_Val_HL 

                                     + (j - Start_Bar_HL)

                                       * (End_Val_HL - Start_Val_HL)

                                        / (End_Bar_HL - Start_Bar_HL );

                   }


              }

         }

         if ( SwingLow_HL != -1)

         {

              if (

                   Switch_HL[i-1] != -1 

                        AND SwingLow_HL <= (End_Val_HL * WavePcnt) )

              {

                   Start_Bar_HL = End_Bar_HL;

                   Start_Val_HL = End_Val_HL;

                   End_Bar_HL = i;

                   End_Val_HL = SwingLow_HL;


                   for( j = Start_Bar_HL; j <= End_Bar_HL; j++ )

                   {

                   ZigArray_HL[j] = Start_Val_HL 

                                     + (j - Start_Bar_HL)

                                       * (End_Val_HL - Start_Val_HL)

                                        / (End_Bar_HL - Start_Bar_HL );

                   }

                   Switch_HL = -1;

              }

              else

              if (Switch_HL[i-1] == -1 AND SwingLow_HL <= End_Val_HL)

              {

                   End_Bar_HL = i;

                   End_Val_HL = SwingLow_HL;


                   for( j = Start_Bar_HL; j <= End_Bar_HL; j++ )

                   {

                   ZigArray_HL[j] = Start_Val_HL 

                                     + (j - Start_Bar_HL)

                                       * (End_Val_HL - Start_Val_HL)

                                        / (End_Bar_HL - Start_Bar_HL );

                   }

              }

         }

    }


    return ZigArray_HL;

}


P = Param("Percent",3,-0,5,0.01);

Z = ZigZagHL( P );

Plot(C,"Close",1,128);

Plot(Z,"ZigZagHL",4,1);



Friday, June 19, 2009, 2:30:06 PM, you wrote:


> Thanks guys, but I'm looking for the code for the ZigZag function itself (not

> a strategy that uses the Zig function).




> --- In amibroker@xxxxxxxxxxxxxxx, "corvidsystems" <corvidsys@xxx> wrote:


>> Hope this helps:

>> --------------------------------------------

>> Opt1  =  Param("%Zig(Change)",0.1,0,1,0.05);

>> Opt2 = Param("Min.AllowableDuration",1,1,20,1);

>> Z = Zig(C,Opt1);

>> Buy = Z < Ref(Z,1) AND Z < Ref(Z,-1);

>> Sell = Z > Ref(Z,1) AND Z > Ref(Z,-1);

>> Buy = Buy AND BarsSince(Sell) > Opt2;

>> Sell = Sell AND BarsSince(Buy) > Opt2;

>> Short = Sell;

>> Cover = Buy;

>> Eq = Equity(1);

>> Plot(C,"",colorBlack,styleBar);

>> Plot(z,"",colorWhite,styleLine);

>> ShowTriangles = ParamToggle("Arrows","HIDE|SHOW",1);

>> if(showTriangles)

>> {

>> PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone),5,0,BuyPrice,0);

>> PlotShapes(IIf(Sell,shapeHollowDownTriangle,shapeNone),4,0,SellPrice,0);

>> PlotShapes(IIf(Cover,shapeHollowUpTriangle,shapeNone),5,0,CoverPrice,0);

>> PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),4,0,ShortPrice,0);

>> }


>> Title = "{{NAME}} - {{INTERVAL}} {{DATE}} "+_DEFAULT_NAME()+" : {{VALUES}}"+"\n"+

>> " BarsSinceBuy: "+BarsSince(Buy)+"\n"+

>> " BarsSinceSell: "+BarsSince(Sell)+"\n" +

>> " NextSiganl: "+(BarsSince(Buy)-BarsSince(Sell))+"\n";




>> --- In amibroker@xxxxxxxxxxxxxxx, "lucianomt" <lucianomt@> wrote:

>> >

>> > I tried this but only got this:

>> > 

>> > P = ParamField( "Price field" );

>> > change = Param("% change",5,0.1,25,0.1);

>> > Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

>> > 

>> > 

>> > 

>> > 

>> > 

>> > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:

>> > >

>> > > It's built in....see charts >> indicators >> Zig

>> > > 

>> > > --- In amibroker@xxxxxxxxxxxxxxx, "lucianomt" <lucianomt@> wrote:

>> > > >

>> > > > Could somebody post the code for the ZigZag indicator? Thanks!

>> > > >

>> > >

>> >






> ------------------------------------


> **** IMPORTANT PLEASE READ ****

> This group is for the discussion between users only.

> This is *NOT* technical support channel.


> TO GET TECHNICAL SUPPORT send an e-mail directly to 

> SUPPORT {at} amibroker.com


> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at

> http://www.amibroker.com/feedback/

> (submissions sent via other channels won't be considered)


> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:

> http://www.amibroker.com/devlog/


> Yahoo! Groups Links


> <*> To visit your group on the web, go to:

>     http://groups.yahoo.com/group/amibroker/


> <*> Your email settings:

>     Individual Email | Traditional


> <*> To change settings online go to:

>     http://groups.yahoo.com/group/amibroker/join

>     (Yahoo! ID required)


> <*> To change settings via email:

>     mailto:amibroker-digest@xxxxxxxxxxxxxxx 

>     mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx


> <*> To unsubscribe from this group, send an email to:

>     amibroker-unsubscribe@xxxxxxxxxxxxxxx


> <*> Your use of Yahoo! Groups is subject to:

>     http://docs.yahoo.com/info/terms/





__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___