From:    "Sysop" <forex@ovenstone.net>
To:    <MetaTrader_Experts_and_Indicators@yahoogroups.com>
Subject:    Re: [MT_E and I] Manual Strategy.
Date:    Sat, 19 Jan 2008 16:19:01 +0000
Content-Type: Multipart/mixed;
 boundary="NextPart_Webmail_9m3u9jl4l_6335_1200770349_2"

--NextPart_Webmail_9m3u9jl4l_6335_1200770349_2
Content-Type: application/octet-stream;
	name="Swing_ZZ_with_alert.mq4"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Swing_ZZ_with_alert.mq4"

//+------------------------------------------------------------------+
//|                                                     Swing_ZZ.mq4 |
//+------------------------------------------------------------------+

//---- Alert by FerruFx

#property copyright "onix"
#property link      =
"http://onix-trade.net/forum/index.php?s=3D&showtopic=3D118&view=3Dfindpo=
st&p=3D131476"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Blue
#property indicator_color3 Red

//---- indicator parameters
extern int    minBars =3D 2;=20
extern bool   SignalAlert    =3D false;
extern bool   SendAlertEmail =3D false;

//---- indicator buffers
double zzL[];
double zzH[];
double zz[];

//---- Alert
int up =3D0;
int down =3D0;
string Timeframe=3D"";
double time_frame;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 //  IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexArrow(2,159);
   SetIndexArrow(1,159);
//---- indicator buffers mapping
   SetIndexBuffer(0,zz);
   SetIndexBuffer(1,zzH);
   SetIndexBuffer(2,zzL);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
    =20
//---- indicator short name
   IndicatorShortName("Swing_ZZ("+minBars+")");

//---- initialization done

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
 int cbi;
 double lLast=3D0,hLast=3D0;=20
 int fs=3D0;=20
 int ai,bi,ai0,aip0,bi0,bip0;=20
 datetime tai,tbi,taip,tbip,ti;=20
=20
 // =CF=E5=F0=E5=EC=E5=ED=ED=FB=E5 =E4=EB=FF =D1=E2=E8=ED=E3=EE=E2 =
=C3=E0=ED=ED=E0
 double lLast_m=3D0, hLast_m=3D0;
 int countBarExt; // =F1=F7=E5=F2=F7=E8=EA =E2=ED=E5=F8=ED=E8=F5 =
=E1=E0=F0=EE=E2
 int countBarl,countBarh;
 int i,n;

   ArrayInitialize(zz,0.0);
   ArrayInitialize(zzL,0.0);
   ArrayInitialize(zzH,0.0);



// lLast, hLast - =EC=E8=ED=E8=EC=F3=EC =E8 =EC=E0=EA=F1=E8=EC=F3=EC =
=E0=EA=F2=E8=E2=ED=EE=E3=EE =E1=E0=F0=E0
// lLast_m, hLast_m - =EC=E8=ED=E8=EC=F3=EC =E8 =EC=E0=EA=F1=E8=EC=F3=EC =
"=EF=F0=EE=EC=E5=E6=F3=F2=EE=F7=ED=FB=F5" =E1=E0=F0=EE=E2

//   cbi=3DBars-IndicatorCounted()-1;
   cbi=3DBars-1;=20
//---------------------------------
   for (i=3Dcbi; i>=3D0; i--)=20
     {
//-------------------------------------------------
      // =D3=F1=F2=E0=ED=E0=E2=EB=E8=E2=E0=E5=EC =
=ED=E0=F7=E0=EB=FC=ED=FB=E5 =E7=ED=E0=F7=E5=ED=E8=FF =
=EC=E8=ED=E8=EC=F3=EC=E0 =E8 =EC=E0=EA=F1=E8=EC=F3=EC=E0 =E1=E0=F0=E0
      if (lLast=3D=3D0) {lLast=3DLow[i]; hLast=3DHigh[i]; ai=3Di; =
bi=3Di;}
      if (ti!=3DTime[i])
        {
         ti=3DTime[i];
         if (lLast_m=3D=3D0 && hLast_m=3D=3D0)
           {
            if (lLast>Low[i] && hLast<High[i]) // =C2=ED=E5=F8=ED=E8=E9 =
=E1=E0=F0
              {
               =
lLast=3DLow[i];hLast=3DHigh[i];lLast_m=3DLow[i];hLast_m=3DHigh[i];countBa=
rExt++;
               if (fs=3D=3D1) {countBarl=3DcountBarExt; ai=3Di; =
tai=3DTime[i];}
               else if (fs=3D=3D2) {countBarh=3DcountBarExt; bi=3Di; =
tbi=3DTime[i];}
               else {countBarl++;countBarh++;}
              }
            else if (lLast<=3DLow[i] && hLast<High[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=E2=EE=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3D0;hLast_m=3DHigh[i];countBarl=3D0;countBarExt=3D0;
               if (fs!=3D1) countBarh++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; ai=3Di; tai=3DTime[i];}
              }
            else if (lLast>Low[i] && hLast>=3DHigh[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=ED=E8=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3DLow[i];hLast_m=3D0;countBarh=3D0;countBarExt=3D0;
               if (fs!=3D2) countBarl++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; bi=3Di; tbi=3DTime[i];}
              }
           }
         else  if (lLast_m>0 && hLast_m>0) // =C2=ED=E5=F8=ED=E8=E9 =
=E1=E0=F0 (=EF=F0=E5=E4=FB=E4=F3=F9=E8=E9)
           {
            if (lLast_m>Low[i] && hLast_m<High[i]) // =
=C2=ED=E5=F8=ED=E8=E9 =E1=E0=F0
              {
               =
lLast=3DLow[i];hLast=3DHigh[i];lLast_m=3DLow[i];hLast_m=3DHigh[i];countBa=
rExt++;
               if (fs=3D=3D1) {countBarl=3DcountBarExt; ai=3Di; =
tai=3DTime[i];}
               else if (fs=3D=3D2) {countBarh=3DcountBarExt; bi=3Di; =
tbi=3DTime[i];}
               else {countBarl++;countBarh++;}
              }
            else if (lLast_m<=3DLow[i] && hLast_m<High[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=E2=EE=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3D0;hLast_m=3DHigh[i];countBarl=3D0;countBarExt=3D0;
               if (fs!=3D1) countBarh++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; ai=3Di; tai=3DTime[i];}
              }
            else if (lLast_m>Low[i] && hLast_m>=3DHigh[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=ED=E8=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3DLow[i];hLast_m=3D0;countBarh=3D0;countBarExt=3D0;
               if (fs!=3D2) countBarl++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; bi=3Di; tbi=3DTime[i];}
              }
           }
         else  if (lLast_m>0)
           {
            if (lLast_m>Low[i] && hLast<High[i]) // =
=C2=ED=E5=F8=ED=E8=E9 =E1=E0=F0
              {
               =
lLast=3DLow[i];hLast=3DHigh[i];lLast_m=3DLow[i];hLast_m=3DHigh[i];countBa=
rExt++;
               if (fs=3D=3D1) {countBarl=3DcountBarExt; ai=3Di; =
tai=3DTime[i];}
               else if (fs=3D=3D2) {countBarh=3DcountBarExt; bi=3Di; =
tbi=3DTime[i];}
               else {countBarl++;countBarh++;}
              }
            else if (lLast_m<=3DLow[i] && hLast<High[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=E2=EE=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3D0;hLast_m=3DHigh[i];countBarl=3D0;countBarExt=3D0;
               if (fs!=3D1) countBarh++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; ai=3Di; tai=3DTime[i];}
              }
            else if (lLast_m>Low[i] && hLast>=3DHigh[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=ED=E8=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3DLow[i];hLast_m=3D0;countBarh=3D0;countBarExt=3D0;
               if (fs!=3D2) countBarl++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; bi=3Di; tbi=3DTime[i];}
              }
           }
         else  if (hLast_m>0)
           {
            if (lLast>Low[i] && hLast_m<High[i]) // =
=C2=ED=E5=F8=ED=E8=E9 =E1=E0=F0
              {
               =
lLast=3DLow[i];hLast=3DHigh[i];lLast_m=3DLow[i];hLast_m=3DHigh[i];countBa=
rExt++;
               if (fs=3D=3D1) {countBarl=3DcountBarExt; ai=3Di; =
tai=3DTime[i];}
               else if (fs=3D=3D2) {countBarh=3DcountBarExt; bi=3Di; =
tbi=3DTime[i];}
               else {countBarl++;countBarh++;}
              }
            else if (lLast<=3DLow[i] && hLast_m<High[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=E2=EE=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3D0;hLast_m=3DHigh[i];countBarl=3D0;countBarExt=3D0;
               if (fs!=3D1) countBarh++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; ai=3Di; tai=3DTime[i];}
              }
            else if (lLast>Low[i] && hLast_m>=3DHigh[i]) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=ED=E8=F1=F5=EE=E4=FF=F9=E0=FF
              {
               =
lLast_m=3DLow[i];hLast_m=3D0;countBarh=3D0;countBarExt=3D0;
               if (fs!=3D2) countBarl++;
               else {lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0; bi=3Di; tbi=3DTime[i];}
              }
           }

         // =CE=EF=F0=E5=E4=E5=EB=FF=E5=EC =
=ED=E0=EF=F0=E0=E2=EB=E5=ED=E8=E5 =F2=F0=E5=ED=E4=E0.=20
         if (fs=3D=3D0)
           {
            if (lLast<lLast_m && hLast>hLast_m) // =
=E2=ED=F3=F2=F0=E5=ED=ED=E8=E9 =E1=E0=F0
              {
               lLast=3DLow[i]; hLast=3DHigh[i]; ai=3Di; bi=3Di; =
countBarl=3D0;countBarh=3D0;countBarExt=3D0;
              }
             =20
            if (countBarh>countBarl && countBarh>countBarExt && =
countBarh>minBars)
              {
               lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0;
               fs=3D1;countBarh=3D0;countBarl=3D0;countBarExt=3D0;
               zz[bi]=3DLow[bi];
               zzL[bi]=3DLow[bi];
               zzH[bi]=3D0;
               ai=3Di;
               tai=3DTime[i];
              }
            else if (countBarl>countBarh && countBarl>countBarExt && =
countBarl>minBars)
              {
               lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0;
               fs=3D2;countBarl=3D0;countBarh=3D0;countBarExt=3D0;
               zz[ai]=3DHigh[ai];
               zzH[ai]=3DHigh[ai];
               zzL[ai]=3D0;
               bi=3Di;
               tbi=3DTime[i];
              }
           }
         else
           {
            if (lLast_m=3D=3D0 && hLast_m=3D=3D0)
              {
               countBarl=3D0;countBarh=3D0;countBarExt=3D0;
              }

            // =D2=E5=ED=E4=E5=ED=F6=E8=FF =
=E2=EE=F1=F5=EE=E4=FF=F9=E0=FF
            if (fs=3D=3D1)
              {
                  if (countBarl>countBarh && countBarl>countBarExt && =
countBarl>minBars) // =CE=EF=F0=E5=E4=E5=EB=FF=E5=EC =F2=EE=F7=EA=F3 =
=F1=EC=E5=ED=FB =F2=E5=ED=E4=E5=ED=F6=E8=E8.
                    {
                     // =E7=E0=EF=EE=EC=E8=ED=E0=E5=EC =
=E7=ED=E0=F7=E5=ED=E8=E5 =ED=E0=EF=F0=E0=E2=EB=E5=ED=E8=FF =
=F2=F0=E5=ED=E4=E0 fs =ED=E0 =EF=F0=E5=E4=FB=E4=F3=F9=E5=EC =E1=E0=F0=E5
                     ai0=3DiBarShift(Symbol(),0,tai);=20
                     bi0=3DiBarShift(Symbol(),0,tbi);
                     fs=3D2;
                     countBarl=3D0;

                     zz[ai]=3DHigh[ai];
                     zzH[ai]=3DHigh[ai];
                     zzL[ai]=3D0;
                     bi=3Di;
                     tbi=3DTime[i];

                     lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0;

                     for (n=3D0;countBarExt<minBars;n++)=20
                       {
                        if (lLast<Low[i+n+1] && hLast>High[i+n+1]) =
{countBarExt++; countBarh++; lLast=3DLow[i+n+1]; hLast=3DHigh[i+n+1]; =
hLast_m=3DHigh[i];}
                        else break;
                       }

                     lLast=3DLow[i]; hLast=3DHigh[i];

                    }
              }

            // =D2=E5=ED=E4=E5=ED=F6=E8=FF =
=ED=E8=F1=F5=EE=E4=FF=F9=E0=FF
            if (fs=3D=3D2)
              {
                  if (countBarh>countBarl && countBarh>countBarExt && =
countBarh>minBars) // =CE=EF=F0=E5=E4=E5=EB=FF=E5=EC =F2=EE=F7=EA=F3 =
=F1=EC=E5=ED=FB =F2=E5=ED=E4=E5=ED=F6=E8=E8.
                    {
                     // =E7=E0=EF=EE=EC=E8=ED=E0=E5=EC =
=E7=ED=E0=F7=E5=ED=E8=E5 =ED=E0=EF=F0=E0=E2=EB=E5=ED=E8=FF =
=F2=F0=E5=ED=E4=E0 fs =ED=E0 =EF=F0=E5=E4=FB=E4=F3=F9=E5=EC =E1=E0=F0=E5
                     ai0=3DiBarShift(Symbol(),0,tai);=20
                     bi0=3DiBarShift(Symbol(),0,tbi);
                     fs=3D1;
                     countBarh=3D0;

                     zz[bi]=3DLow[bi];
                     zzL[bi]=3DLow[bi];
                     zzH[bi]=3D0;
                     ai=3Di;
                     tai=3DTime[i];

                     lLast=3DLow[i]; hLast=3DHigh[i]; lLast_m=3D0; =
hLast_m=3D0;

                     for (n=3D0;countBarExt<minBars;n++)=20
                       {
                        if (lLast<Low[i+n+1] && hLast>High[i+n+1]) =
{countBarExt++; countBarl++; lLast=3DLow[i+n+1]; hLast=3DHigh[i+n+1]; =
lLast_m=3DLow[i];}
                        else break;
                       }

                     lLast=3DLow[i]; hLast=3DHigh[i];

                    }
              }
           }=20
        }=20
       if (i=3D=3D0)
         {
          if (hLast<High[i] && fs=3D=3D1) // =D2=E5=ED=E4=E5=ED=F6=E8=FF =
=ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =E2=EE=F1=F5=EE=E4=FF=F9=E0=FF
            {
             ai=3Di; tai=3DTime[i]; zz[ai]=3DHigh[ai]; =
zzH[ai]=3DHigh[ai]; zzL[ai]=3D0;
            }
          else if (lLast>Low[i] && fs=3D=3D2) // =
=D2=E5=ED=E4=E5=ED=F6=E8=FF =ED=E0 =F2=E5=EA=F3=F9=E5=EC =E1=E0=F0=E5 =
=ED=E8=F1=F5=EE=E4=FF=F9=E0=FF
            {
             bi=3Di; tbi=3DTime[i]; zz[bi]=3DLow[bi]; zzL[bi]=3DLow[bi]; =
zzH[bi]=3D0;
            }
//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

      // =CD=F3=EB=E5=E2=EE=E9 =E1=E0=F0. =D0=E0=F1=F7=E5=F2 =
=EF=E5=F0=E2=EE=E3=EE =EB=F3=F7=E0 ZigZag-a

          ai0=3DiBarShift(Symbol(),0,tai);=20
          bi0=3DiBarShift(Symbol(),0,tbi);

          if (bi0>1) if (fs=3D=3D1) {for (n=3Dbi0-1; n>=3D0; n--) =
{zzH[n]=3D0.0; zz[n]=3D0.0;} zz[ai0]=3DHigh[ai0]; zzH[ai0]=3DHigh[ai0]; =
zzL[ai0]=3D0.0;}        =20
          if (ai0>1) if (fs=3D=3D2) {for (n=3Dai0-1; n>=3D0; n--) =
{zzL[n]=3D0.0; zz[n]=3D0.0;} zz[bi0]=3DLow[bi0]; zzL[bi0]=3DLow[bi0]; =
zzH[bi0]=3D0.0;}

          if (ti<Time[1]) i=3D2;

         }
//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
      //---- Alert
      time_frame=3DPeriod();
      if(time_frame=3D=3D1) { Timeframe =3D "M1"; }
      if(time_frame=3D=3D5) { Timeframe =3D "M5"; }
      if(time_frame=3D=3D15) { Timeframe =3D "M15"; }
      if(time_frame=3D=3D30) { Timeframe =3D "M30"; }
      if(time_frame=3D=3D60) { Timeframe =3D "H1"; }
      if(time_frame=3D=3D240) { Timeframe =3D "H4"; }
      if(time_frame=3D=3D1440) { Timeframe =3D "D1"; }
      if(time_frame=3D=3D10080) { Timeframe =3D "W1"; }
      if(time_frame=3D=3D43200) { Timeframe =3D "MN"; }
     =20
      if(zzL[i] !=3D 0 && down =3D=3D0)
      {
       if (SignalAlert) Alert("Swing ZZ Down - ",Symbol()," =
",Timeframe," at ",TimeToStr(TimeCurrent(),TIME_SECONDS));
       if(SendAlertEmail) SendMail("Swing ZZ","Swing ZZ Down - =
"+Symbol()+" "+Timeframe+" at "+TimeToStr(TimeCurrent(),TIME_SECONDS)+" =
(server time)");
       up =3D 0;
       down =3D 1;
      }
      if(zzH[i] !=3D 0 && up =3D=3D0)
      {
       if (SignalAlert) Alert("Swing ZZ Up - ",Symbol()," ",Timeframe," =
at ",TimeToStr(TimeCurrent(),TIME_SECONDS));
       if(SendAlertEmail) SendMail("Swing ZZ","Swing ZZ Up - =
"+Symbol()+" "+Timeframe+" at "+TimeToStr(TimeCurrent(),TIME_SECONDS)+" =
(server time)");
       up =3D 1;
       down =3D 0;
      }
     =20
     =20
     =20
     =20
     =20
     =20
     }
//--------------------------------------------
  =20
return(0);
}
//+------------------------------------------------------------------+
--NextPart_Webmail_9m3u9jl4l_6335_1200770349_2--

