Cualquier pregunta de novato, para no saturar el foro. Profesionales, no pasen de largo. En ninguna parte sin ti - 6. - página 385

 
TarasBY:

Error tras error. Tal vez esto haga que funcione:

???



Por favor, señale, amablemente, dónde encontró "error tras error".
 
Roger:

Por favor, señale, amablemente, dónde encontró "error tras error".
¿Ya se te han hinchado los ojos? Sugiero: ver los precios de apertura de las órdenes (aparte del precio de cierre ya mencionado anteriormente).
 
TarasBY:
¿Ya se te han hinchado los ojos? Sugerencia: vea los precios de apertura de las órdenes (aparte del precio de cierre ya mencionado anteriormente).


Y más detalles.
 
if(prof>=Profit)
{
 for(i=OrdersTotal()-1; i>=0; i--)
 {
  OrderSelect(i,SELECT_BY_POS);
  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,0);
 }
}

double LineEA = iCustom (Symbol(), 0, "Ind_2 Line+1", 0, 1); // Первый инструмент
double LineAU = iCustom (Symbol(), 0, "Ind_2 Line+1", 1, 1); // Второй инструмент

if(NumberOfPositions("EURAUD")==0 && LineEA > 0.1 && LineAU < -0.1)
    {
       EASell = OrderSend(symEA,OP_SELL,lotEA,bidEA,3,0,0,"KVAZ_EURAUD_AUDUSD",Magic,0,Red);
    }
if(NumberOfPositions("AUDUSD")==0 && LineEA > 0.1 && LineAU < -0.1)
    {
       AUSell = OrderSend(symAU,OP_SELL,lotAU,bidAU,3,0,0,"KVAZ_EURAUD_AUDUSD",Magic,0,Red);
    }
if(NumberOfPositions("EURAUD")==0 && LineEA < -0.1 && LineAU > 0.1)
    {
       EABuy = OrderSend(symEA,OP_BUY,lotEA,bidEA,3,0,0,"KVAZ_EURAUD_AUDUSD",Magic,0,Red);
    }
if(NumberOfPositions("AUDUSD")==0 && LineEA < -0.1 && LineAU > 0.1)
    {
       AUBuy = OrderSend(symAU,OP_BUY,lotAU,bidAU,3,0,0,"KVAZ_EURAUD_AUDUSD",Magic,0,Red);
    }
 
No es "no abrir", es "no cerrar" órdenes. El código de cierre es correcto.
 



extern double Lots       = 0.1;
extern int TakeProfit    = 50;
extern int Step          = 50;
extern double Multipler  = 2;
extern int Slippage      = 5;
extern int Magic         = 123;

int ticket;
double price, TP, lastlot;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

   

   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
     if ( CountTrades()==0)
     {
       double ima = iMA(Symbol(),0,14,0,MODE_SMA,PRICE_CLOSE,1);
       
       if (Ask>ima)
       {
         ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"",Magic,0,Blue);
         if (ticket>0)
         {
            TP = NormalizeDouble (Ask+TakeProfit*Point,Digits);
            OrderModify(ticket,OrderOpenPrice(),0,TP,0); 
         }
       }
       else if (Bid<ima)
       ticket = OrderSend(Symbol(),OP_SELL,Lots,Ask,Slippage,0,0,"",Magic,0,Red);
       if (ticket>0)
         {
            TP = NormalizeDouble (Bid-TakeProfit*Point,Digits);
            OrderModify(ticket,OrderOpenPrice(),0,TP,0); 
         }
       }
       
// закрыты все скобки, кроме первой, которая начинает цикл "старт". На этот момент открыт 1й ордер, дальше в
// случае потребности доливаемся.
       else
       {
         int order_type = FindLastOrderType();
         if (order_type = OP_BUY)
         {
           price = FindLastPrice (OP_BUY);
           if (Ask <= price - Step*Point)
           {
             lastlot = FindLastLots (OP_BUY);
             lastlot = NormalizeDouble (lastlot* Multipler,2);
             ticket = OrderSend(Symbol(),OP_BUY,lastlot,Ask,Slippage,0,0,"",Magic,0,Blue);
             if (ticket>0)
               ModifyOrders (OP_BUY);
           }
         }
         else if (order_type = OP_SELL()
         {
           price = FindLastPrice (OP_SELL);
           if (Bid <= price + Step*Point)
           {
             lastlot = FindLastLots (OP_SELL);
             lastlot = NormalizeDouble (lastlot* Multipler,2);
             ticket = OrderSend(Symbol(),OP_SELL,lastlot,Bid,Slippage,0,0,"",Magic,0,Blue);
             if (ticket>0)
               ModifyOrders (OP_SELL);
           }
         }
       }  
    
   return(0);
  }
//+------------------------------------------------------------------+
void ModifyOrder(int otype)
{
  double avgprice = 0,
         order_lots = 0;
         
         price = 0;
  for (int i = OrdersTotal()-1; i>=0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       {
          price +=OrderOpenPrice() * OrderLots();
          order_lots +=OrderLots(); 
       } 
    }
  }
  avgprice = NormalizeDouble (price / order_lots, Digits);
  if (otype == OP_BUY) TP = NormalizeDouble (avgprice + TakeProfit * Point,Digits);
  if (otype == OP_SELL) TP = NormalizeDouble (avgprice - TakeProfit * Point,Digits);
  
  for (i = OrdersTotal()-1; i>=0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       
         OrderModify(OrderTicket(), OrderOpenPrice(),0,TP,0);
       }
  }
  
}
//+------------------------------------------------------------------+
double FindLastLots (int otype)
{
  double oldopenprice,oldlots;
  int oldticket;
  
  ticket = 0;
  
  for (int i = OrdersTotal()-1; i>=0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) 
    {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
      {
         oldticket = OrderTicket();
         if (oldticket>ticket)
         {
            oldlots = OrderLots();
            ticket = oldticket; 
         } 
      }  
    }
  }
  return (oldlots);
}
//+------------------------------------------------------------------+
double FindLastPrice (int otype)
{
  double oldopenprice;
  int oldticket;
  
  ticket = 0;
  
  for (int i = OrdersTotal()-1; i>=0; i--)
  {
     if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
     {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       {
         oldticket = OrderTicket();
         if (oldticket>ticket)
         {
           oldopenprice = OrderOpenPrice();
           ticket = oldticket;
         }
       }
     } 
  }
  return (oldopenprice);
}
//+------------------------------------------------------------------+
int FindLastOrderType()
{
  for (int i = OrdersTotal()-1; i>=0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
     if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
       return (OrderType()); 
    }
  }
  return (-1);
}
//+------------------------------------------------------------------+
int CountTrades()
{
  int count = 0;
  for (int i = OrdersTotal()-1; i>=0; i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
      count++;
    }
  }
  return (count);
}
//+------------------------------------------------------------------+
Chicos, por favor ayúdenme a encontrar un error en el tablero, no compila.
 
alexey1979621:
Hecho, pero eso no resuelve el problema del búho de arriba. Creo que al cerrar, el EA simplemente no ve las órdenes en el símbolo y las mayores que necesita para cerrar.

La variante es sencilla (para pruebas) y funciona, lo ve todo.
 
TarasBY:
Gracias, he desmontado tu código. Efectivamente, hay un error al abrir (mi ojo ya está mojado). Lo he rediseñado en demo donde ya hay posiciones abiertas en nuestro Meijic con beneficio total positivo. Sin embargo, la posición no se ha cerrado.
 
Roger:

No debería ver el símbolo o el mago, su EA es correcto. Mira los registros para ver qué error produce.
Los registros son... Con tus comentarios, el código del EA queda así.
extern double lotEU=0.01;
extern double lotGU=0.01;
extern double Profit=12;
extern string Сomment           = "KVAZ_EURUSD_GBPUSD";
extern int Magic                = 1114;

int EUSell, EUBuy, GUSell, GUBuy;
double price;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
double prof;
double bidEU = MarketInfo("EURUSD",MODE_BID);
double askEU = MarketInfo("EURUSD",MODE_ASK);
double bidGU = MarketInfo("GBPUSD",MODE_BID);
double askGU = MarketInfo("GBPUSD",MODE_ASK);

string symEU = "EURUSD";
string symGU = "GBPUSD";



if(prof>=Profit)
   {
  for(int i=OrdersTotal()-1;i>=0;i--) 
      {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
     double AS=MarketInfo(OrderSymbol(), MODE_ASK);
     double BI=MarketInfo(OrderSymbol(), MODE_BID);

       if(OrderType()==OP_BUY) price=BI;
       else                    price=AS;

       OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE);
         }
      }   
   }


double LineEU = iCustom (Symbol(), 0, "Ind_2 Line+1", 0, 1); // Первый инструмент
double LineGU = iCustom (Symbol(), 0, "Ind_2 Line+1", 1, 1); // Второй инструмент

if(NumberOfPositions("EURUSD")==0 && LineEU > 0.1 && LineGU < -0.1)
    {
       EUSell = OrderSend(symEU,OP_SELL,lotEU,bidEU,3,0,0,"KVAZ_EURUSD_GBPUSD",Magic,0,Red);
    }
if(NumberOfPositions("GBPUSD")==0 && LineEU > 0.1 && LineGU < -0.1)
    {
       GUBuy = OrderSend(symGU,OP_BUY,lotGU,bidGU,3,0,0,"KVAZ_EURUSD_GBPUSD",Magic,0,Blue);
    }
if(NumberOfPositions("EURUSD")==0 && LineEU < -0.1 && LineGU > 0.1)
    {
       EUBuy = OrderSend(symEU,OP_BUY,lotEU,askEU,3,0,0,"KVAZ_EURUSD_GBPUSD",Magic,0,Blue);
    }
if(NumberOfPositions("GBPUSD")==0 && LineEU < -0.1 && LineGU > 0.1)
    {
       GUSell = OrderSend(symGU,OP_SELL,lotGU,askGU,3,0,0,"KVAZ_EURUSD_GBPUSD",Magic,0,Red);
    }
    
  return(0);
  }
//+------------------------------------------------------------------+

int NumberOfPositions(string sy="", int op=-1, int mn=1114) {      //|  Параметры:                                                                |
                                                                  //|    sy - наименование инструмента   (""   - любой символ,                   |
                                                                  //|                                     NULL - текущий символ)                 |
                                                                  //|    op - операция                   (-1   - любая позиция)                  |
                                                                  //|    mn - MagicNumber                (-1   - любой магик)                    
  int i, k=OrdersTotal(), kp=0;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) kp++;
          }
        }
      }
    }
  }
  return(kp);
}
 
Trader7777:
Chicos, por favor, ayúdenme mucho a encontrar un error en el tablero, no compila.


Mira esta línea

else if(order_type = OP_SELL()