Erreurs, bugs, questions - page 1907

 
CPositionInfo::Commission est écrit de manière incorrecte.
 
Cette condition peut-elle fonctionner ?
if (PositionGetInteger(POSITION_TICKET) != PositionGetInteger(POSITION_IDENTIFIER))
        ;
 
Lors du débogage du script, la dernière action de F11 est de quitter OnStart. Mais après la sortie de OnStart, il y a d'autres étapes d'exécution - les destructeurs d'objets globaux. Par conséquent, F11 les ignore - mauvaise action.
 
L'interface graphique de l'environnement de négociation lors du débogage sur l'historique (curseur de vitesse - maximum) ne correspond pas à la réalité
#include <Trade\Trade.mqh>

input int Interval = 3600;
input int AmountLastDeals = 5;
input double Lots = 1;

double CorrectLot( const double Lot )
{
  static const double StepVol = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
  static const double MaxVol = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
  static const double MinVol = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
  
  const double Vol = StepVol * (int)(Lot / StepVol + 0.5);
  
  return((Vol < MinVol) ? MinVol : ((Vol > MaxVol) ? MaxVol : Vol));
}

void OnTick()
{
  static CTrade Trade;
  static CDealInfo Deal;
  static CPositionInfo Position; 

  if (!Position.Select(_Symbol))
  {
    if (HistorySelect(0, TimeCurrent()))
    {
      const int Total = HistoryDealsTotal() - 1;

      double SumProfit = 0;
      double SumLots = 0;

      for (int i = Total, Count = 0; (i >= 0) && (Count < AmountLastDeals); i--)
        if (Deal.SelectByIndex(i) && (Deal.Entry() == DEAL_ENTRY_OUT))
        {        
          SumProfit += Deal.Profit() * (AmountLastDeals - Count) / AmountLastDeals;
          SumLots += Deal.Volume() * (AmountLastDeals - Count) / AmountLastDeals;
          
          Count++;
        }

      if (Total == 2)
      {
        string Str;
        
        for (int i = Total; i >= 0; i--)
          if (Deal.SelectByIndex(i))
            Print(Deal.FormatDeal(Str));
        
        DebugBreak();
      }

      if ((Total >= 0) && Deal.SelectByIndex(Total) && (Deal.DealType() == DEAL_TYPE_SELL))
        Trade.Sell((SumProfit >= 0) ? Lots : CorrectLot(SumLots));
      else
        Trade.Buy((SumProfit >= 0) ? Lots : CorrectLot(SumLots));
    }       
  }
  else if (TimeCurrent() - Position.Time() >= Interval)
    Trade.PositionClose(_Symbol);
}
Journal au moment du DebugBreak
2017.06.07 23:29:03.554 EURUSD : real ticks begin from 2017.04.10 00:00:00
2017.06.07 23:29:03.564 2017.04.10 00:00:00   instant buy 1.00 EURUSD at 1.05918 (1.05885 / 1.05918)
2017.06.07 23:29:03.564 2017.04.10 00:00:00   deal #2 buy 1.00 EURUSD at 1.05918 done (based on order #2)
2017.06.07 23:29:03.564 2017.04.10 00:00:00   deal performed [#2 buy 1.00 EURUSD at 1.05918]
2017.06.07 23:29:03.564 2017.04.10 00:00:00   order performed buy 1.00 at 1.05918 [#2 buy 1.00 EURUSD at 1.05918]
2017.06.07 23:29:03.566 2017.04.10 00:00:00   CTrade::OrderSend: instant buy 1.00 EURUSD at 1.05918 [done at 1.05918]
2017.06.07 23:29:03.569 2017.04.10 01:00:00   instant sell 1.00 EURUSD at 1.05833 (1.05833 / 1.05845 / 1.05831)
2017.06.07 23:29:03.569 2017.04.10 01:00:00   deal #3 sell 1.00 EURUSD at 1.05833 done (based on order #3)
2017.06.07 23:29:03.569 2017.04.10 01:00:00   deal performed [#3 sell 1.00 EURUSD at 1.05833]
2017.06.07 23:29:03.569 2017.04.10 01:00:00   order performed sell 1.00 at 1.05833 [#3 sell 1.00 EURUSD at 1.05833]
2017.06.07 23:29:03.570 2017.04.10 01:00:00   CTrade::OrderSend: instant sell 1.00 EURUSD at 1.05833 [done at 1.05833]
2017.06.07 23:29:03.570 2017.04.10 01:00:00   #3 sell 1.00 EURUSD at 1.05833
2017.06.07 23:29:03.570 2017.04.10 01:00:00   #2 buy 1.00 EURUSD at 1.05918
2017.06.07 23:29:03.570 2017.04.10 01:00:00   CSymbolInfo::CheckMarketWatch: Unknown symbol ''
2017.06.07 23:29:03.570 2017.04.10 01:00:00   #1 balance 100000.00 []
Capture d'écran


La dernière transaction n'est pas affichée dans l'interface graphique. Reproduit à 1596-1606.

 
Erreur classique, et le compilateur donne clairement les mauvaises erreurs
struct STRUCT
{
  string Str;

  void operator =( STRUCT& ) {}

  void operator =( int& ) {}
};

STRUCT Func()
{
  STRUCT Res = {0};
  
  return(Res); // OK

  return(true ? Res : Res); // Неадекватные ошибки компилятора
//  'operator=' - no one of the overloads can be applied to the function call
//  could be one of 2 function(s)
//    void STRUCT::operator=(int&)
//    void STRUCT::operator=(STRUCT&)
//  'operator=' - structure have objects and cannot be copied  
}
 
HistorySelect ne fonctionne pas dans le testeur
void OnTick()
{
  static bool FirstRun = true;
  
  if (FirstRun)
  {
    if (HistorySelect(TimeCurrent() + 1, TimeCurrent() + 2)) // берем историю заведомо там, где ничего нет
      Print(HistoryDealsTotal()); // 1 - балансовая сделка
    
    FirstRun = false;
  }
}
 

Dans kodobase, les fichiers sources ont reçu le postfix trompeur __X.

Par exemple,TypeToBytes__10.mqh

TypeToBytes
TypeToBytes
  • votes : 21
  • 2016.09.13
  • fxsaber
  • www.mql5.com
Побайтовая работа со структурами, массивами и стандартными типами данных
 
fxsaber:
CPositionInfo::Commission est mal orthographié.
Lequel est quoi ?
 
Rashid Umarov:
Laquelle ?
double CPositionInfo::Commission(void) const
  {
   return(PositionGetDouble(POSITION_COMMISSION));
  }
LaPOSITION_COMMISSION est attendue depuis longtemps.
 
Il y a plusieurs dizaines de demandes ouvertes (en attente/ non résolues) dans le SR. J'écris un message dans la 20e application (dans la liste d'affichage), mais l'application reste la 20e de la liste. Pourquoi les applications de la liste sont-elles triées par heure de création et non par heure du dernier message dans le CD ?
Raison: