Toute question des nouveaux arrivants sur MQL4 et MQL5, aide et discussion sur les algorithmes et les codes. - page 541

 
Rustam Bikbulatov:

Vu et essayé. Cela m'a déjà beaucoup aidé, mais il y a une limite à ma compréhension.

Vous ne voulez donc pas le nombre de commandes mais le volume en lots ?

//+------------------------------------------------------------------+
int fMarketOrdersOpenVolume(const ENUM_ORDER_TYPE order_type)
  {
   int total=OrdersTotal();
   double lots=0;
   for(int i=total-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS))
        {
         if(OrderType()!=order_type) continue;
         if(OrderMagicNumber()==123 && OrderSymbol()==Symbol())
            lots+=OrderLots();
        }
     }
   return lots;
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin:

Vous ne voulez donc pas le nombre de commandes, mais le volume en lots ?

double fMarketOrdersOpenVolume(const ENUM_ORDER_TYPE order_type)
 
Konstantin Nikitin:

Ahrinet !!!!!! Ce dont j'avais besoin !!!!!! Je n'aurais jamais pensé à cela !!!!! Merci beaucoup !!!!!

 
Konstantin Nikitin:

Oui, je l'ai manqué dans mes soucis.

 
Merci les gars de nous aider ! !! Bravo à vous tous ! !!
 

Cependant, bonjour !

Pouvez-vous me conseiller sur cette situation : sur la base de TMA_Fair, j'ouvre sur la frontière et je ferme sur la frontière opposée, mais elle ne ferme pas sur l'autre frontière ! Où se trouve le bug dans le code ?

void OnTick()
{
  PriceHigh = iCustom(NULL, 0, "ExtremeTMALine st2050 v1", TimeFrame, TMAPeriod, Price, ATRMultiplier, ATRPeriod, TrendThreshold, ShowCenterLine, alertsOn, alertsMessage, alertsSound, alertsEmail, MaxBars, ShowInfo, ShowInfo_WindowNo, ShowInfo_X, ShowInfo_Y, ShowInfo_ColorLabel, ShowInfo_ColorSwing, ShowInfo_ColorUp, ShowInfo_ColorDown, 1, 0);
  PriceLow  = iCustom(NULL, 0, "ExtremeTMALine st2050 v1", TimeFrame, TMAPeriod, Price, ATRMultiplier, ATRPeriod, TrendThreshold, ShowCenterLine, alertsOn, alertsMessage, alertsSound, alertsEmail, MaxBars, ShowInfo, ShowInfo_WindowNo, ShowInfo_X, ShowInfo_Y, ShowInfo_ColorLabel, ShowInfo_ColorSwing, ShowInfo_ColorUp, ShowInfo_ColorDown, 2, 0);
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+  
  if (CountSell() == 0 && Bid >= PriceHigh)
  {
      ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "ExtremeTMALine_Robot", Magic, 0, Red);
      if (ticket>0)
      {
       SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
       
       if(OrderSelect(ticket, SELECT_BY_TICKET))
          if(!OrderModify (ticket, OrderOpenPrice(), SL, 0, 0))
          Print ("Ошибка модификации ордера на продажу!!!"); 
      } else Print ("Ошибка открытия ордера на продажу!!!");
        
  }
//+------------------------------------------------------------------+  
  if(Ask <= PriceLow && CountSell() > 0)
  {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
      if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
      {
        if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
            if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))
            Print ("Ошибка закрытия ордера на продажу!!!");  
      } else Print ("Ошибка открытия ордера на продажу!!!");
    }
  }  
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+  
  
  if (CountBuy() == 0 && Ask <= PriceLow)
  {
      ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "ExtremeTMALine_Robot", Magic, 0, Blue);
      if (ticket>0)
      {
       SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
       
       if(OrderSelect(ticket, SELECT_BY_TICKET))
          if (!OrderModify (ticket, OrderOpenPrice(), SL, 0, 0))
          Print ("Ошибка модификации ордера на покупку!!!");  
      } else Print ("Ошибка открытия ордера на покупку!!!");
        
  }
//+------------------------------------------------------------------+  
   if(Bid >= PriceHigh && CountBuy() > 0)
  {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
      if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
      {
        if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
           if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Green))
           Print ("Ошибка закрытия ордера на покупку!!!"); 
      } else Print ("Ошибка открытия ордера на покупку!!!");
    }
  }
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CountSell()
{
 int count = 0;
     for (int trade = OrdersTotal()-1; trade>=0; trade--)
     {
          if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
          {
             if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
             count++;
          }
     }
     return (count);
}
//+------------------------------------------------------------------+
int CountBuy()
{
 int count = 0;
     for (int trade = OrdersTotal()-1; trade>=0; trade--)
     {
          if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
          {
             if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
             count++;
          }
     }
     return (count);
}
//+------------------------------------------------------------------+
 
Domovoi44:

Cependant, bonjour !

Pouvez-vous me conseiller sur cette situation : sur la base de TMA_Fair, j'ouvre sur la frontière et je ferme sur la frontière opposée, mais elle ne ferme pas sur l'autre frontière ! Où se trouve le bug dans le code ?

Si vous suivez l'indicateur de près, vous pouvez voir qu'il redessine 10 barres ou plus en arrière. C'est toute la raison.

 
Alexey Viktorov:

Si vous suivez l'indicateur de près, vous remarquerez qu'il redessine 10 barres ou plus en arrière. C'est toute la raison.

Ehhhhhhh mec ! !! Je vais continuer à creuser) Merci pour l'aide ! !!
 
Pouvez-vous me dire s'il existe un indicateur de divergence de volume de puits pour MT-4 ?
 

Bonjour, aidez-nous ! J'essaie d'écrire beaucoup de contrôle de compte. Si mon compte devient +10% de profit, le lot est doublé. Si +20%, alors lot*4. Si mon compte diminue, alors la taille du lot diminue respectivement. Je ne comprends pas comment faire pour que Lots_New prenne une nouvelle valeur à chaque nouvelle transaction.

double Bal= AccountBalance();
double GetLots()
{
double Lots_New;
double Lots = 0.1;
   
   if(Bal <=AccountBalance()+0.1*AccountBalance()){
   Lots_New=Lots*2;
   }
   if(Bal >=AccountBalance()+0.1*AccountBalance()){
   Lots_New=Lots/2;
   }
   if(Bal ==AccountBalance()){
   Lots_New=Lots;
   }

Alert("Lot new= ",Lots_New);
return (Lots_New);
}
Raison: