
//+------------------------------------------------------------------+
//|                                 panelektrik@yandex.ru            |
//|                                 Starigin Konstantin              |
//+------------------------------------------------------------------+
#property show_inputs


extern int EquityCLOSE=100000;


int objekt1()
   {
    ObjectCreate("EquityCLOSE",OBJ_LABEL,0,0,0);
    ObjectSetText("EquityCLOSE","ÐÀÁÎÒÀÅÒ ÑÊÐÈÏÒ! EquityCLOSE = "+EquityCLOSE, 10,"Times New Roman",RosyBrown);
    ObjectSet("EquityCLOSE", OBJPROP_CORNER, 1);
    ObjectSet("EquityCLOSE", OBJPROP_XDISTANCE, 20);
    ObjectSet("EquityCLOSE", OBJPROP_YDISTANCE, 10);
   } 
   
int start()
{
 objekt1();
 PlaySound("Wait.wav");
  while(!IsStopped())
  {
  if(AccountEquity()>=EquityCLOSE)
  static string close="allclose";
  if(close=="allclose")
  {
  allclose();
  if(OrdersTotal()==0){PlaySound("Wait.wav");break;}
  }
  Sleep(1000);
 }
}
//+------------------------------------------------------------------+
void allclose()
  {
   for(int i=OrdersTotal(); i+1>=0; i--)
   {
    RefreshRates();
    if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderType()==OP_BUY))
    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(Symbol(),MODE_SPREAD));
    if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderType()==OP_SELL))
    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(Symbol(),MODE_SPREAD));
    if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)&&(OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT||OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP))
    OrderDelete(OrderTicket());
   }
  }
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("EquityCLOSE");
}