Discussion of article "Data Exchange between Indicators: It's Easy" - page 3

 

Wow ! It seems that the problem can be solved without writing a library - just by renaming the imported function... It's too late today, but tomorrow - let's try and try...

Документация по MQL5: Основы языка / Препроцессор / Импорт функций (#import)
Документация по MQL5: Основы языка / Препроцессор / Импорт функций (#import)
  • www.mql5.com
Основы языка / Препроцессор / Импорт функций (#import) - Документация по MQL5
 

Yeah. I was too early. GetValue for arrays other than double returns something quite different from what I would like... Alas, I can't do without MSVC... Eh, I haven't taken checkers in my hands for a long time...

 

Masters!

 

I don't understand why MQL needs pointers? If you want to do something with pointers, do it in C++.

There are no problems in passing pointers to another data type and arrays of another type! For example, here is a declaration: void setvar(int& var[]); to pass a pointer to an array of integers (guess what you need to change for other types?).

The overheads of calling dll-functions have not disappeared (build 646), say, an empty mql-function works faster than an empty dll-function, but if you add there at least an operation of selecting from an array, like s[i], then c++ will win here, nevertheless the number of calls should be minimised.

The biggest performance leak is when working with global variables - they are VERY SLOW!!!! It is much easier, if we have made a dll, to store global variables there. For all copies of Expert Advisors and indicators within one metatrader, one copy of the dll is linked, so all its global variables are global for all windows of the metatrader (this truth forces personal data of one window to be stored either in an instance of the class or in an array with access by window identifier).

 
ponter address should be unsigned int, not just int
 
Imho, it is easier to migrate to C++ or C# at once and not to return to the use of MT trading functionality. And if you need indicators, you should draw them. And the problem disappears.
 
This is most excellent! Ive adjusted the code so that the functions work with something a little more useful than a double (in my case) - a structure - specifically MqlRates.
Files:
cpp.zip  44 kb
exchng.mqh  2 kb
exchng.mq4  12 kb
 
How can modify this code so that it can be capable to exchange array having struct type element not only double?
 
JamesMQL:
How can modify this code so that it can be capable to exchange array having struct type element not only double?

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: TradeTransactions

fxsaber, 2018.09.20 16:23

// Пример хранения/обмена данными через Ресурсы внутри Терминала
#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/ru/code/22166

void OnStart()
{  
  const RESOURCEDATA<int> ResourceINT("::int"); // Ресурс для обмена int-ами. const - как доказательство, что ничего не пишется в объект класса
  
  int ArrayINT[] = {1, 2, 3};
  int Num = 5;
  
  ResourceINT = ArrayINT;  // Ресурс хранит массив.
  ResourceINT += Num;      // Добавили в ресурс еще значение.
  ResourceINT += ArrayINT; // Добавили массив.
  
  int ArrayINT2[];  
  ResourceINT.Get(ArrayINT2); // Считали данные из ресурса.
  ArrayPrint(ArrayINT2);      // Вывели: 1 2 3 5 1 2 3

  ResourceINT.Free();                // Удалили данные из ресурса
  Print(ResourceINT.Get(ArrayINT2)); // Убедились, что данных нет: 0

  const RESOURCEDATA<MqlTick> ResourceTicks("::Ticks"); // Ресурс для обмена тиками. const - как доказательство, что ничего не пишется в объект класса
  MqlTick Tick;
  
  if (SymbolInfoTick(_Symbol, Tick))
    for (int i = 0; i < 3; i++)
      ResourceTicks += Tick; // Добавили в ресурс тики

  MqlTick Ticks[];
  ResourceTicks.Get(Ticks); // Считали данные из ресурса.
  ArrayPrint(Ticks);        // Вывели.
  
  // Это полное имя ресурса для обращения из другой программы
  const string NameOut = StringSubstr(MQLInfoString(MQL_PROGRAM_PATH), StringLen(TerminalInfoString(TERMINAL_PATH)) + 5) + "::Ticks";  
  Print(NameOut); // Вывели полное имя ресурса.
  
  const RESOURCEDATA<MqlTick> Resource(NameOut); // Ресурс для доступа к данным (read-only) из другой программы
  
  MqlTick TicksOut[];
  Resource.Get(TicksOut); // Считали данные из ресурса.
  ArrayPrint(TicksOut);   // Вывели.
  
  Resource.Free();   // Не получится повлиять на данные read-only-ресурса.
  Print(_LastError); // ERR_INVALID_PARAMETER - Ошибочный параметр при вызове системной функции.
}
 
fxsaber:

Thank you for your help, but

- I don't understand this code. Where the struct in it?

- I need MQL4 solution