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...
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...
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).
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.
// Пример хранения/обмена данными через Ресурсы внутри Терминала#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/ru/code/22166voidOnStart()
{
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)); // Убедились, что данных нет: 0const 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); // Вывели.// Это полное имя ресурса для обращения из другой программыconststring 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 - Ошибочный параметр при вызове системной функции.
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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...
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).
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
Thank you for your help, but
- I don't understand this code. Where the struct in it?
- I need MQL4 solution