Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 6. - pagina 385

 
TarasBY:

Errore su errore. Forse questo lo farà funzionare:

???



Vi prego di indicare, gentilmente, dove avete trovato "errori su errori".
 
Roger:

Per favore, mi indichi, gentilmente, dove ha trovato "errore su errore"?
Ti si sono già gonfiati gli occhi? Suggerimento: vedere i prezzi di apertura degli ordini (oltre al prezzo di chiusura già menzionato prima).
 
TarasBY:
Ti si sono già gonfiati gli occhi? Suggerimento: vedere i prezzi di apertura degli ordini (oltre al prezzo di chiusura già menzionato prima).


E altri dettagli.
 
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);
    }
 
Non è "non aprire", è "non chiudere" gli ordini. Il codice di chiusura è corretto.
 



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);
}
//+------------------------------------------------------------------+
Ragazzi, vi prego davvero di aiutarmi a trovare un bug nella scheda, non si compila.
 
alexey1979621:
Fatto, ma questo non risolve il problema del gufo di cui sopra. Penso che quando si chiude, l'EA semplicemente non vede gli ordini sul simbolo e le major di cui ha bisogno per chiudere.

La variante è semplice (per i test) e funziona, vede tutto.
 
TarasBY:
Grazie, ho smontato il tuo codice. C'è effettivamente un errore all'apertura (il mio occhio è già bagnato). L'ho ridisegnato su demo dove ci sono già posizioni aperte sul nostro Meijic con totale profitto positivo. Tuttavia, la posizione non è stata chiusa.
 
Roger:

Non dovrebbe vedere il simbolo o il mago, il tuo EA lo dice correttamente. Guardate i log per vedere quale errore produce.
I registri sono... Con i vostri commenti, il codice EA è così.
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:
Ragazzi, per favore aiutatemi molto a trovare un bug nella scheda, non si compila.


Guarda questa linea

else if(order_type = OP_SELL()