แนบ EA ไม่ได้
int start()
{
double openticket=0;
double openlot=0;
double openprice=0;
double opentype;
double opentp=0;
double limitticket=0;
double limitlot=0;
double limitprice=0;
double limittype;
//----
for (int order=0;order<OrdersTotal();order++)
{
OrderSelect(order,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY)
{
opentype=OrderType();
openticket=OrderTicket();
openlot=OrderLots();
openprice=OrderOpenPrice();
opentp=OrderTakeProfit();
}
if (OrderType()==OP_SELL)
{
opentype=OrderType();
openticket=OrderTicket();
openlot=OrderLots();
openprice=OrderOpenPrice();
opentp=OrderTakeProfit();
}
if (OrderType()==OP_BUYLIMIT)
{
limittype=OrderType();
limitticket=OrderTicket();
limitlot=OrderLots();
limitprice=OrderOpenPrice();
}
if (OrderType()==OP_SELLLIMIT)
{
limittype=OrderType();
limitticket=OrderTicket();
limitlot=OrderLots();
limitprice=OrderOpenPrice();
}
}
if ((openticket==0)&&(limitticket==0))
{
if (iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1)>iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1)) OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",0,0,Green);
if (iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1)<iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1)) OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+25*Point,Bid-25*Point,"My order #2",0,0,Red);
}
if ((openticket!=0)&&(limitticket==0))
{
if (opentype==0) OrderSend(Symbol(),OP_BUYLIMIT,openlot*2,opentp,3,opentp-25*Point,opentp+25*Point,"My order #2",0,0,Green);
if (opentype==1) OrderSend(Symbol(),OP_SELLLIMIT,openlot*2,opentp,3,opentp-25*Point,opentp+25*Point,"My order #2",0,0,Green);
}
if ((openticket==0)&&(limitticket!=0))
{
clear();
}
//----
return(0);
}
//+------------------------------------------------------------------+
void clear()
{ while(OrdersTotal()>0)
{
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
int type = OrderType();
bool result = false;
switch(type)
{
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Pink);
break;
case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Pink);
break;
case OP_BUYSTOP : result = OrderDelete(OrderTicket());
break;
case OP_SELLSTOP : result = OrderDelete(OrderTicket());
break;
case OP_BUYLIMIT : result = OrderDelete(OrderTicket());
break;
case OP_SELLLIMIT : result = OrderDelete(OrderTicket());
}
}
}
}