Toute question de débutant, afin de ne pas encombrer le forum. Professionnels, ne passez pas à côté. Nulle part sans toi - 6. - page 385

 
TarasBY:

Erreur sur erreur. Peut-être que ça va le faire fonctionner :

? ??



Veuillez indiquer, gentiment, où vous avez trouvé "erreur sur erreur".
 
Roger:

Veuillez indiquer, gentiment, où vous avez trouvé "erreur sur erreur" ?
Vos yeux ont-ils déjà gonflé ? Indice : voir les prix d'ouverture des ordres (autres que le prix de clôture déjà mentionné plus haut).
 
TarasBY:
Vos yeux ont-ils déjà gonflé ? Conseil : voir les prix d'ouverture des ordres (autres que le prix de clôture déjà mentionné plus haut).


Et plus de détails.
 
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);
    }
 
Ce n'est pas "ne pas ouvrir", c'est "ne pas fermer" les commandes. Le code de fermeture est correct.
 



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);
}
//+------------------------------------------------------------------+
Les gars, vraiment s'il vous plaît aidez-moi à trouver un bug dans le conseil, il ne sera pas compiler.
 
alexey1979621:
C'est fait, mais cela ne résout pas le problème de la chouette ci-dessus. Je pense que lors de la fermeture, l'EA ne voit tout simplement pas les ordres sur le symbole et les majors qu'il doit fermer.

La variante est simple (pour les tests) et fonctionne, elle voit tout.
 
TarasBY:
Merci, j'ai démonté votre code. Il y a effectivement une erreur à l'ouverture (mon œil est déjà mouillé). Je l'ai redessiné sur la démo où il y a déjà des positions ouvertes sur notre Meijic avec un profit positif total. Cependant, le poste n'a pas été fermé.
 
Roger:

Il ne devrait pas voir le symbole ou le magicien, votre EA le dit correctement. Regardez les journaux pour voir quelle erreur elle produit.
Les journaux sont... Avec vos commentaires, le code EA est comme ceci.
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:
Les gars, s'il vous plaît aidez-moi beaucoup à trouver un bug dans le conseil, il ne compile pas.


Regardez cette ligne

autre si(order_type = OP_SELL()