Errori, bug, domande - pagina 1857

 

E come sovraccaricare gli operatori [] e =, in modo da poter scrivere così:

class A
{
private:
   int arr[5];
};

A *obj = new A();

for(int i = 0; i < 5; ++i)    obj[i] = i;

 
Konstantin:

E come sovraccaricare gli operatori [] e =, in modo da poter scrivere così:

class A
{
   int arr[5];
   
   int CurrentPos;
   
public:
  A* operator []( const int Pos )
  {
    this.CurrentPos = Pos;
    
    return(&this);
  }

  void operator =( const int Value )  
  {
    this.arr[this.CurrentPos] = Value;
  }
};
 
fxsaber:


Grazie, ma come faccio a sovraccaricare di nuovo l'operatore [] in modo da poter scrivere in aggiunta a quello che ho scritto sopra?

class A
{
   int arr[5];
   
   int CurrentPos;
   
public:
  A* operator []( const int Pos )
  {
    this.CurrentPos = Pos;
    
    return(&this);
  }

  void operator =( const int Value )  
  {
    this.arr[this.CurrentPos] = Value;
  }
};

for(int i = 0; i < 5; ++i)

   int _value = obj[i];

 
Konstantin:

Grazie, ma come faccio a sovraccaricare di nuovo l'operatore [] in modo da poter scrivere in aggiunta a quello che ho scritto sopra?

class A
{
   int arr[5];
   
   int CurrentPos;
   
public:
  A* operator []( const int Pos )
  {
    this.CurrentPos = Pos;
    
    return(&this);
  }

  void operator =( const int Value )  
  {
    this.arr[this.CurrentPos] = Value;
  }

  int operator []( const uint Pos ) const
  {
    return(this.arr[Pos]);
  }
};

void OnStart()
{
  A obj;

  for (int i = 0; i < 5; ++i)  
    obj[i] = i;
    
  for (uint i = 0; i < 5; ++i)  
    int _value = obj[i];
}
 
fxsaber:

Grazie ancora, non sapevo cosa fare con questi sovraccarichi, farli separatamente funziona, ma non insieme ))
 

errore di battitura nella documentazione?

https://www.mql5.com/ru/docs/series/copyticksrange

int  CopyTicks(
   const string     symbol_name,           // имя символа
   MqlTick&         ticks_array[],         // массив для приёма тиков
   uint             flags=COPY_TICKS_ALL,  // флаг, определяющий тип получаемых тиков
   ulong            from_msc=0,            // дата, начиная с которой запрашиваются тики
   ulong            to_msc=0               // дата, по которую запрашиваются тики
   );
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyTicksRange
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyTicksRange
  • www.mql5.com
Доступ к таймсериям и индикаторам / CopyTicksRange - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Il tester entra in una terribile modalità di frenata dopo 25K transazioni.

Running 1585, su ticks, RTS-6.17, Metaquotes-Demo

#include <MT4Orders.mqh>

void OnTick()
{  
  static bool Error = false;  
  static int Type = OP_BUY;
  
  if (Error)
    return;
  
  MqlTick Tick;    

  if (OrderSelect(0, SELECT_BY_POS) && (OrderType() <= OP_SELL))
    OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);    
  else if ((OrdersTotal() == 0) && SymbolInfoTick(_Symbol, Tick) && (Tick.bid != 0) && (Tick.ask != 0))
  {
    Error = (OrderSend(_Symbol, Type + OP_BUYLIMIT, 1, (Type == OP_BUY) ? Tick.ask : Tick.bid, 0, 0, 0, "", 0, 0, INT_MAX) == -1);        
    
    if (!Error)
    {
      OrderSend(_Symbol, Type + OP_BUYLIMIT, 1, (Type == OP_BUY) ? Tick.ask : Tick.bid, 0, 0, 0);
      
      Type = OP_SELL - Type;
    }    
  }
}

Non vedo alcuna ragione per i ritardi. Sembra che sia stato scritto ArrayResize(Orders, ArraySize(Orders) + 1). Cioè Reserve_Size non è usato.

 
Non c'è tempo nel log del tester quando la registrazione Expired è in corso
2017.04.19 10:46:15.165 2017.04.06 23:09:37   sell limit 1.00 RTS-6.17 at 114300 (114290 / 114300 / 114300)
2017.04.19 10:46:15.168 order expired [#284  sell limit 1.00 RTS-6.17 at 114300]
2017.04.19 10:46:15.168 2017.04.07 09:45:04   buy limit 1.00 RTS-6.17 at 114170 (114140 / 114180)
 
Si prega di aggiungere i millisecondi al log del tester oltre al tempo storico.
 

Forum sul trading, sistemi di trading automatico e test di strategie di trading

Bug, bug, domande

fxsaber, 2017.04.19 08:58

Il tester va in modalità freno strisciante dopo 25K transazioni.

Running 1585, su ticks, RTS-6.17, Metaquotes-Demo

#include <MT4Orders.mqh>

void OnTick()
{  
  static bool Error = false;  
  static int Type = OP_BUY;
  
  if (Error)
    return;
  
  MqlTick Tick;    

  if (OrderSelect(0, SELECT_BY_POS) && (OrderType() <= OP_SELL))
    OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);    
  else if ((OrdersTotal() == 0) && SymbolInfoTick(_Symbol, Tick) && (Tick.bid != 0) && (Tick.ask != 0))
  {
    Error = (OrderSend(_Symbol, Type + OP_BUYLIMIT, 1, (Type == OP_BUY) ? Tick.ask : Tick.bid, 0, 0, 0, "", 0, 0, INT_MAX) == -1);        
    
    if (!Error)
    {
      OrderSend(_Symbol, Type + OP_BUYLIMIT, 1, (Type == OP_BUY) ? Tick.ask : Tick.bid, 0, 0, 0);
      
      Type = OP_SELL - Type;
    }    
  }
}

Funziona? Le impostazioni del tester sono le seguenti

Risultato

Tester  RTS-6.17,M1: 254907 ticks, 785 bars generated. Test passed in 0:15:54.180 (including ticks preprocessing 0:00:00.047).

Vale a dire 250K tick eseguiti in 16 minuti.


Come è possibile misurare il degrado delle prestazioni nel tester? Ho provato GetTickCount e le variabili globali, ma non funziona.