static double high ;
static double low ;
static double lasthigh;
static double lastlow;
static int direct;
double ticket, total, pc;
int start()
{
int amount=0;
double temp[4];
double tem;
for(int i=0 ;i<500;i++)
{
tem=iCustom(NULL, 0, "ZigZag",8,0,i);
if(tem>0)
{Print("temp 1",tem);
temp[amount]=tem;
amount++;
if(amount>4)
{
i=501;
}
}
}
///last=buttom///
///price>lasthigh=breakup///
if(temp[2]>temp[1])
{lasthigh=temp[2];
lastlow=temp[1];
direct=1;
}
///last=top///
///price<lastlow=breakdown///
if(temp[2]<temp[1])
{lasthigh=temp[1];
lastlow=temp[2];
direct=2;
}
pc = iClose(NULL,0,1);
total=OrdersTotal();
//----
//Print("temp 2",temp[2]);
// Print("temp 1",temp[1]);
///short///
if(direct==2)
{
if (pc<lastlow)
{
if((total>0)&&(OrderType() == OP_BUY))
{OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
Print("sale");
return(0);
}
if(total<1)
{ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"Short",0,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("sale");
}
}
///else///
else
{if((total>0)&&(OrderType() == OP_SELL))
{
OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
Print("buy");
return(0);
}
if((total>0)&&(OrderType() == OP_BUY))
{
OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
Print("sale");
return(0);
}
}
}
////////////////////////////////
///long///
if(direct==1)
{Print("aaa");
if (pc>lasthigh)
{
if((total>0)&&(OrderType() == OP_SELL))
{OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
Print("buy");
return(0);
}
if(total<1)
{ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Long",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
}
}
/////else/////
else
{
if((total>0)&&(OrderType() == OP_SELL))
{
OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
Print("buy");
return(0);
}
if((total>0)&&(OrderType() == OP_BUY))
{
OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
Print("sale");
return(0);
}
}
}
//----
return(0);
}