Erros, bugs, perguntas - página 1907

 
Erro de optimização do compilador
#define  TOSTRING(A) #A + " = " + (string)(A)

void OnStart()
{
  color Color1 = (color)ColorToARGB(clrWhite, 0xFF);
  color Color2 = -1;
  
  Print(TOSTRING(Color1 == Color2));   // Color1==Color2 = true
  Print(TOSTRING(Color1 == -1));       // Color1==-1 = false
  Print(TOSTRING((int)Color1 == -1));  // (int)Color1==-1 = true
  Print(TOSTRING((uint)Color1 == -1)); // (uint)Color1==-1 = true
}
 
CPositionInfo::A Comissão está escrita incorrectamente.
 
Pode a condição funcionar?
if (PositionGetInteger(POSITION_TICKET) != PositionGetInteger(POSITION_IDENTIFIER))
        ;
 
Ao depurar o guião, a última jogada de F11 é sair de OnStart. Mas após a saída da OnStart há mais etapas de execução - destruidores de objectos globais. Como resultado, F11 salta-os - acção errada.
 
O ambiente comercial GUI quando se depura na história (speed slider - máximo) não corresponde à realidade
#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);
}
Log no momento do 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 []
Imagem do ecrã


A última transacção na GUI não é exibida. Reproduzido em 1596-1606.

 
Erro clássico, e o compilador dá claramente os erros errados
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 não funciona no testador
void OnTick()
{
  static bool FirstRun = true;
  
  if (FirstRun)
  {
    if (HistorySelect(TimeCurrent() + 1, TimeCurrent() + 2)) // берем историю заведомо там, где ничего нет
      Print(HistoryDealsTotal()); // 1 - балансовая сделка
    
    FirstRun = false;
  }
}
 

No kodobase, os ficheiros de origem receberam o postfix __X enganador.

Por exemplo,TypeToBytes__10.mqh

TypeToBytes
TypeToBytes
  • votos: 21
  • 2016.09.13
  • fxsaber
  • www.mql5.com
Побайтовая работа со структурами, массивами и стандартными типами данных
 
fxsaber:
CPositionInfo::A Comissão está mal escrita.
O que é isso?
 
Rashid Umarov:
O que é?
double CPositionInfo::Commission(void) const
  {
   return(PositionGetDouble(POSITION_COMMISSION));
  }
POSIÇÃO_COMISSÃO há muito esperada.