Features of the mql5 language, subtleties and tricks - page 125

 
Nikita Chernyshov:

Thank you!

And this is an older code, but in pictures:TrailingStop

 
The EventSetTimer in OnInit in the Tester does not count down from the beginning of the day of the first tick, but from the start date of the test interval - the balance transaction.
 
fxsaber:
EventSetTimer in OnInit in Tester counts down not from beginning of day of first tick, but from initial date of testing interval - balance transaction.
EventSetTimer always starts timer countdown from the moment of EventSetTimer call. Both in the tester and in the terminal
 

Forum on trading, automated trading systems and trading strategies testing

Features of mql4 language, tips and tricks

fxsaber, 2019.02.12 13:12

Features of ArrayResize for multidimensional arrays
void OnStart()
{
  int Array[][2];
  
  Print(ArrayResize(Array, 7)); // MQL5 - 7, MQL4 - 14
  Print(ArraySize(Array));      // 14
}
 

How nice it would be to see Kim's functions for the five. Can you give me a hint, please? There was a function like this in Kim's

//+------------------------------------------------------------------+
//|  Проверяет был ли открыт последний ордер на этой же свече        |
//|  Checks whether the opened last the order on the same candle     |
//+------------------------------------------------------------------+
bool IfOrdOpClSelfBar(int magik = 0, int bar = 0, int typ = -1,string sy = "",int per = 0){
   if(sy == ""){sy = Symbol();}
   if(per==0){per=Period();}
   for(int i = OrdersTotal(); i>=0; i--){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderSymbol()!=sy){continue;}
         if(OrderType()==typ||typ==-1){
            if(OrderMagicNumber()==magik||magik==0){
               if(OrderOpenTime()>=iTime(sy,per,bar)){return(true);}
            }
         }
      }
   }
   for(i = OrdersHistoryTotal(); i>=0; i--){
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
         if(OrderSymbol()!=sy){continue;}
         if(OrderType()==typ||typ==-1){
            if(OrderMagicNumber()==magik||magik==0){
               if(OrderOpenTime()>=iTime(sy,per,bar)){return(true);}
            }
         }
      }
   }   
   return(false);
}

I am trying to rewrite it on mql5. But it does not want to work. How to force it? :)

//+------------------------------------------------------------------+
//|  Проверяет был ли открыт последний ордер на этой же свече        |
//|  Checks whether the opened last the order on the same candle     |
//+------------------------------------------------------------------+
bool IfOrdOpClSelfBar(ENUM_ORDER_TYPE type)
{

   for(int i = OrdersTotal(); i>=0; i--){
      if(OrderSelect(OrderGetTicket(i)) >0)
        {
         if(OrderGetString(ORDER_SYMBOL)!=_Symbol){continue;}
         if(OrderGetInteger(ORDER_TYPE)==type)
           {
            if(OrderGetInteger(ORDER_MAGIC) == magicN)
             {
               if(OrderGetInteger(ORDER_TIME_SETUP) >= iTime(NULL,Period(),0)){return(true);}
             }
           }
        }
      }
      
   for(int i = HistoryOrdersTotal(); i>=0; i--){
     if(HistoryOrderSelect(OrderGetTicket(i)) >0)
          {
         if(OrderGetString(ORDER_SYMBOL)!=_Symbol){continue;}
         if(OrderGetInteger(ORDER_TYPE)==type)
           {
            if(OrderGetInteger(ORDER_MAGIC) == magicN)
             {
               if(OrderGetInteger(ORDER_TIME_SETUP) >= iTime(NULL,Period(),0)){return(true);}
             }
           }
          }
    }
   
   return(false);
}
 
Nikita Chernyshov:

How nice it would be to see Kim's functions for the five. Can you give me a hint, please? There was a function like this in Kim's

I am trying to rewrite it on mql5. But it does not want to work. How to force it? :)

Forum on trading, automated trading systems and strategy tester

Libraries: MT4Orders

fxsaber, 2019.01.13 17:23

Kim's features under MT4 are quite popular, so downloaded all the sources from his site and wrote a simple "converter" for them under MT5.
#include <KimIVToMT5.mqh> // https://c.mql5.com/3/263/KimIVToMT5.mqh

#include "e-Trailing.mq4" // http://www.kimiv.ru/index.php?option=com_remository&Itemid=13&func=fileinfo&id=14

void OnTick() { start(); }
 
fxsaber:

Thanks for the crutch, very good :) But I'm learning a fiver for understanding, getting into it, so it's important to handle it by hand, fundamentally sorting out the knuckles.

 

While parsing millions of ticks, I decided to periodically look at memory consumption.

I noticed that after making changes the execution speed has dropped many times.


Reason: some variants of TerminalInfoInteger use take very long time to execute

#define  BENCH(A)                                                              \
{                                                                             \
  const ulong StartTime = GetMicrosecondCount();                              \
  A;                                                                          \
  Print("Time[" + #A + "] = " + (string)(GetMicrosecondCount() - StartTime)); \
}  

void OnStart()
{
  BENCH(TerminalInfoInteger(TERMINAL_MEMORY_USED)); // 28220
}
Be careful.
 
TerminalInfoInteger(TERMINAL_MEMORY_USED)

A very expensive function.

Also TERMINAL_MEMORY_AVAILABLE

TERMINAL_MEMORY_PHYSICAL and TERMINAL_MEMORY_TOTAL are cached after the first request. Subsequent queries will return the cached values

 
Some (*.bat, etc.) files are not seen by FileIsExists, butFileFindNext finds them.
Reason: