Errors, bugs, questions - page 1936

 
Aleksey Vyazmikin:

Not ready to show the code yet due to

But ready to show profiling results from MT5 - as I understand trading functions are out of the question.



For OHLC environment I use the following functions

Maybe I am doing something wrong?

Unfortunately you are doing it all wrong.

Instead of writing a native and efficient MQL5 code, you use a terribly inefficient MQL4 emulator that slows down the operation dozens of times.

The bad thing is that you don't even know what you are doing, since you are asking questions about speed.
 
Aleksey Vyazmikin:

the result is the following code

https://www.mql5.com/ru/code/18305

Высокопроизводительная библиотека iTimeSeries
Высокопроизводительная библиотека iTimeSeries
  • votes: 19
  • 2017.05.25
  • nicholishen
  • www.mql5.com
Эта библиотека предоставляет молниеносный доступ к таймсериям для реализации привычных методов MQL4 (например, iBarShift) в чувствительных к задержкам приложениях на MQL5.
 

Thanks - I have seen this library - the description was confusing


Most of the time is spent in the initialization phase. Unless you plan to access the timeseries data multiple times - more than a few thousand times during bar formation - you should consider alternative methods.

My Expert Advisor only works on bar opening - do you think it makes sense to try it out?
 
Renat Fatkhullin:

Unfortunately, you are doing it all wrong.

Instead of writing a native and efficient MQL5 code you use a terribly inefficient MQL4 emulator, which slows down the operation dozens of times.

The bad thing is that you don't even understand what you're doing, since you're asking questions about speed.

Of course, I was looking for a solution - how to replace MQL4 functions with MQL5, particularly referring to time series, and saw that this is one of the problems encountered by most people moving to MQL5.

Accordingly, I found the solution on the same website, where one of the articles recommended my method.

Personally, I don't understand the reason for excluding a good and handy function from the language.

So my question is, what's the correct way to receive information, and how can you take advantages of MQL5?

 
Aleksey Vyazmikin:

So my question to you is: how to correctly organize data receiving for feeling the advantages of MQL5?

To use the native, more productive functions of MQL5, and not to cling to the MQL4 code. Any MQL4 -> MQL5 converter/splitter has dozens of times slower performance, since it tries to emulate direct access microfunctions from MQL4 via MQL5 bulk operations. And the emulation is done completely without optimization and caching.

At the root of the use of a particular function (a bit of code, including other people's code), there should be an understanding of what exactly is being done. Otherwise you get "I just used somebody else's code and the speed went down! You cannot get a good result without understanding the tool and what you are doing with it.


In addition to "how to do it right", I should clarify that the task of "learning to program" is extremely difficult, as soon as you get above the most basic level of operating (not even understanding, namely operating) with a language. So I see no other way to learn except reading masses of articles, documentation, ready-made code in the library and mandatory practice for several years.
 
Renat Fatkhullin:

Use the native, more productive functions of the MQL5 language and do not cling to the MQL4 code.

At the root of the use of a particular function (a piece of code, including other people's code) should be an understanding of what is being done. Otherwise you get "I just used someone else's code, look - the speed is down! Without understanding the tool and what you are doing with it, you cannot get a good result.


In addition to "how to do it right", I should clarify that the task of "learning to program" is extremely difficult, once you get above the most basic level of operating (not even understanding, but operating) with the language. So I see no other way to learn except by reading articles, documentation, ready-made code in the library and a few years of mandatory practice.

Renat, have you looked at the code base? I've got some code with functions adapted from MQL4.

I'm asking you specifically to write how to get the right information about the environment - referring to abstract books is not productive and only strengthens my (probably wrong) idea that this is just an excuse that you can't check.

To say that I'm so dumb that I don't understand the meaning of a function, which is to copy information into an array, is to say that the documentation accompanying the programming language is low. I don't understand the benefit of this copying from one array to another and why a function that gets information from an array as needed is terrible code.

 
Aleksey Vyazmikin:

Of course, I was looking for a solution - how to replace MQL4 functions with MQL5, particularly referring to time series, and saw that this was one of the problems encountered by most people moving to MQL5.

Accordingly, I found the solution on the same website, where one of the articles recommended my method.

Personally, I don't understand the reason for excluding a good and handy function from the language.

That's why I'm asking you, what's the correct way to receive information for me to feel the advantages of MQL5?

Perhaps I've searched poorly? Here you have everything you need instead of all this code in one copy

Forum on trading, automated trading systems and strategy testing

Errors, Bugs, Questions

Aleksey Vyazmikin, 2017.07.21 01:20

Thanks - corrected it.

As a result, the code is as follows

//-------------------------------------------------------------------
//==MQL4toMQL5
//+------------------------------------------------------------------+ 
//| Получим Open для заданного номера бара                           | 
//+------------------------------------------------------------------+ 
double Open(int index)
  {
   double open=0;
   int copied=CopyOpen(Symbol(),0,index,1,Open);
   if(copied>0) open=Open[0];
   return(open);
  }
//+------------------------------------------------------------------+ 
//| Получим Low для заданного номера бара                            | 
//+------------------------------------------------------------------+ 
double Low(int index)
  {
   double low=0;
   int copied=CopyLow(Symbol(),0,index,1,Low);
   if(copied>0) low=Low[0];
   return(low);
  }
//+------------------------------------------------------------------+ 
//| Получим High для заданного номера бара                           | 
//+------------------------------------------------------------------+ 
double High(int index)
  {
   double high=0;
   int copied=CopyHigh(Symbol(),0,index,1,High);
   if(copied>0) high=High[0];
   return(high);
  }
//+------------------------------------------------------------------+ 
//| Получим Close для заданного номера бара                           | 
//+------------------------------------------------------------------+ 
double Close(int index)
  {
   double close=0;
   int copied=CopyClose(Symbol(),0,index,1,Close);
   if(copied>0) close=Close[0];
   return(close);
  }


  
//+------------------------------------------------------------------+ 
//| Получим IOpen для заданного номера бара                           | 
//+------------------------------------------------------------------+ 
double iOpen(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double open=0;
   int copied=CopyOpen(symbol,timeframe,index,1,OpenI);
   if(copied>0) open=OpenI[0];
   return(open);
  }
//+------------------------------------------------------------------+ 
//| Получим iLow для заданного номера бара                            | 
//+------------------------------------------------------------------+ 
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double low=0;
   int copied=CopyLow(symbol,timeframe,index,1,LowI);
   if(copied>0) low=LowI[0];
   return(low);
  }
//+------------------------------------------------------------------+ 
//| Получим iHigh для заданного номера бара                           | 
//+------------------------------------------------------------------+ 
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double high=0;
   int copied=CopyHigh(symbol,timeframe,index,1,HighI);
   if(copied>0) high=HighI[0];
   return(high);
  }
//+------------------------------------------------------------------+ 
//| Получим iClose для заданного номера бара                           | 
//+------------------------------------------------------------------+ 
double iClose(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double close=0;
   int copied=CopyClose(symbol,timeframe,index,1,CloseI);
   if(copied>0) close=CloseI[0];
   return(close);
  }

Time in tester has increased - tired of waiting already :)

In order to use it, you just need to understand what the structure is

struct MqlRates
  {
   datetime time;         // время начала периода
   double   open;         // цена открытия
   double   high;         // наивысшая цена за период
   double   low;          // наименьшая цена за период
   double   close;        // цена закрытия
   long     tick_volume;  // тиковый объем
   int      spread;       // спред
   long     real_volume;  // биржевой объем
  };


Документация по MQL5: Доступ к таймсериям и индикаторам / CopyRates
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyRates
  • www.mql5.com
Доступ к таймсериям и индикаторам / CopyRates - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Viktorov:

Maybe I wasn't looking hard enough? Here, in one copy you get everything you need instead of all this code

In order to use this, all you have to do is understand what the structure is



We get the same thing - in fact...

The variant you suggest suits ifle:

- The calculation takes place only at the opening of a bar.

- You know in advance how many bars are needed

I have loops in my code, the amount of calculation may be unknown beforehand.

And, what's the sense in copying information for, say, 300 bars each time we open it, if it would be more reasonable to simply add information about a new bar - why didn't the developer go this way?

 
I'm sorry, but I have absolutely no time to deal with teaching programming to every single beginner. Especially when you see that the person hasn't even gone through the basics of understanding programming and he asks trivial things.


But I'll show you the direction:

  1. MQL5 documentation
  2. Codebase
  3. Articles
  4. Forum (not in the "write for me, why don't you teach me and do my job?" mode)
  5. Freelance (they can write it correctly here)
  6. Independent work with thoughtful analysis of "why should this wrapper slow down and waste resources, maybe rewrite optimally?"
  7. Using a profiler that shows the real consumption of resources in each line of code
Профилирование кода - Разработка программ - Справка по MetaEditor
Профилирование кода - Разработка программ - Справка по MetaEditor
  • www.metatrader5.com
Профилирование — это сбор характеристик программы, таких как время выполнения отдельных ее фрагментов (функций, строк). В MetaEditor встроена...
 

I have no desire to communicate in this way. Instead of trying to understand what's being said, to work out what's going to happen, some incredible objections are thrown out.

Reason: