
//+------------------------------------------------------------------+
//| WW.mq4 |
//| Copyright © 2011, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, AM2"
#property link "http://www.forexsystems.biz"
#define MAGIC 20120225
extern double StopLoss=450;
extern double TakeProfit=800;
extern int ExtDepth=10;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern double Lots=0.1;
double mzz1;
bool one=true;
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double zz1,zz2,zz3,zz4,zz5;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Extremum ZigZag Price
zz1=GetExtremumZZPrice(NULL,0,4,ExtDepth,ExtDeviation,ExtBackstep);
zz2=GetExtremumZZPrice(NULL,0,3,ExtDepth,ExtDeviation,ExtBackstep);
zz3=GetExtremumZZPrice(NULL,0,2,ExtDepth,ExtDeviation,ExtBackstep);
zz4=GetExtremumZZPrice(NULL,0,1,ExtDepth,ExtDeviation,ExtBackstep);
zz5=GetExtremumZZPrice(NULL,0,0,ExtDepth,ExtDeviation,ExtBackstep);
Comment("\n","ZZ1 = ",zz1,"\n",
"ZZ2 = ",zz2,"\n",
"ZZ3 = ",zz3,"\n",
"ZZ4 = ",zz4,"\n",
"ZZ5 = ",zz5,"\n");
if(zz1!=mzz1) one=true;
mzz1=zz1;
//---- buy conditions
if(zz1>zz3 && zz1<zz2 && zz1<zz4 && zz5<=zz3 && one)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
one=false;
return;
}
//---- sell conditions
if(zz1<zz3 && zz1>zz2 && zz1>zz4 && zz5>=zz3 && one)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
one=false;
return;
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
double zz1;
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(OrdersTotal()<1) CheckForOpen();
//----
}
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
if (sy=="" || sy=="0") sy=Symbol();
double zz;
int i, k=iBars(sy, tf), ke=0;
for (i=1; i<k; i++) {
zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
if (zz!=0) {
ke++;
if (ke>ne) return(zz);
}
}
Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
return(0);
}
//+----------------------------------------------------------------------------+
AM2