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

RE: [amibroker] Zig-zag based on High and low possible ?



PureBytes Links

Trading Reference Links

Hello,

 

The function below is based on a code posted to this group last year by another AB user.

I solely converted the code to a function (...see below), with a unique parameter,

so it can be used in more efficient manner.

In this way the formula can be stored in the “include” folder so You can easily call it all the times You need.

 

 

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;

}

 

//=========================================================================

 

prcnt = Param("% Val",5,1,100,0.5);

 

Plot(ZigZagHL(prcnt),"ZigZag HiLo("+WriteVal(prcnt,1.2)+"%)",colorYellow,styleLine);

Plot(C,"Last",colorBlack,styleCandle);

 

 

I hope that this is what You are searching for.

 

Regards,

      Antonio

 

 

 

 

 

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Thomas Z
Sent: Thursday, September 01, 2005 11:23 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Zig-zag based on High and low possible ?

 

Hello,

 

By default the zig chart can only be used by o,h,l or close.

But I want to have it based on Low at a down swing and high on up swing.

So it should change between low and high automatically.

Is there any trick here ?

 

Graph0 = Zig(Close,5);

 

Regards

 

Thomas

www.tradingbasis.com

 

 




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS