extern string sym1 = "" ;
extern string sym2 = "" ;
extern double lot = 1;
double Profit;
int mode;
int result;
int ticket;
int OnInit()
{
//---
Profit=0;
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
result = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() )
{
Profit += OrderProfit();
}
}
if(Profit>1)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
result = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if (mode==OP_SELL){ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrCrimson); }
if (mode==OP_BUY) {ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrIndigo); }
}
}
}
if (OrderSend(sym1,OP_BUY,lot,MarketInfo(sym1,MODE_ASK),0,0,0,NULL,1,0,clrGreen));
else Print("OrderSent Eror Code : ",GetLastError());
if (OrderSend(sym2,OP_BUY,lot,MarketInfo(sym2,MODE_ASK),0,0,0,NULL,2,0,clrBlue));
else Print("OrderSent Eror Code : ",GetLastError());
//---
return (INIT_SUCCEEDED);
}