double ticket, total;
int trend = 0;
int start(int trend)
{
///high-low///
total=OrdersTotal();
double lasthigh = High[iHighest(NULL,0,2,250,31)];
double lastlow = Low[iLowest(NULL,0,2,250,31)];
double high = lasthigh * 1.001;
double low = lastlow * 0.999;
//////
double ema40=iMA(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,1);
double ema80=iMA(NULL,0,80,0,MODE_EMA,PRICE_CLOSE,1);
double high30 = High[iHighest(NULL,0,3,30,1)];
double low30 = Low[iLowest(NULL,0,3,30,1)];
if(total<1)
{
if((high30<high) && (low30>low))
{
if(ema40>ema80)
{
ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"Short",0,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("sale");
}
if(ema40<ema80)
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Long",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
}
trend = 0;
return(trend);
}
if((ema80<ema40) && (high30>low))
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Long",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
trend = 1;
return(trend);
}
if((ema80>ema40) && (low30<low))
{
ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"Short",0,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("sale");
trend = 5;
return(trend);
}
return(trend);
}
/////////////
if(total>0)
{
if ((OrderType() == OP_BUY)&&(high30>high))
{
trend = 1;
return(trend);
}
if (trend ==1 && OrderType()==OP_BUY && ema40<ema80)
{
{OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
Print("sale");
}
{ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"Short",0,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("sale");
}
trend = 2;
return(trend);
}
if (trend ==2 && OrderType()==OP_SELL && ema40>ema80)
{
{OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
Print("buy");
}
{ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Long",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
}
trend = 3;
return(trend);
}
if (trend ==3 && OrderType()==OP_BUY && ema40<ema80)
{
{OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
Print("sale");
}
trend = 0;
return(trend);
}
if ((OrderType() == OP_SELL)&&(low30<low))
{
trend = 5;
return(trend);
}
if (trend ==5 && OrderType()==OP_SELL && ema40>ema80)
{
{OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
Print("buy");
}
{ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Long",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
}
trend = 6;
return(trend);
}
if (trend ==6 && OrderType()==OP_BUY && ema40<ema80)
{
{OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
Print("sale");
}
{ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0,"Short",0,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("sale");
}
trend = 7;
return(trend);
}
if (trend ==7 && OrderType()==OP_SELL && ema40>ema80)
{
{OrderClose(OrderTicket(),OrderLots(),Ask,0,Blue);
Print("buy");
}
trend = 0;
return(trend);
}
}
return (trend);
}