Can you tell me what could be the reason for [Too many trade requests] error on the second call of the OrderSend routine (after starting the terminal) ?
Looked through logs from Monday to Thursday. I have seen the same thing in every log: First limit order is sent successfully and all next orders will have error [Too many trade requests]. Then they start to pass. The only criminal action is frequent call of CopyTickRange in OnInit().
BCS Broker MetaTrader 5 Terminal x64 build 2170 started
From dll, pointer to string const wchar_t* copies an even string, with these parameters
memcpy( out, data, wcslen(data) * sizeof(int) );
wcsncpy( out, data, wcslen(data) * 2 );
With these parameters, of course, it leaks.
2019.10.1104:32:37.857 ExampleDll M 7392019.10.1104:32:37.857 ExampleDll 6602019.10.1104:32:37.857 ExampleDll 701
But the string turns out even, not a single extra character slips through. And after terminating the program, the Expert Advisor log displays a message
2019.10.1103:44:39.202 ExampleDll 1 leaked strings left
The char character ' ' returns two bytes instead of one. Probably because it's in Unicode. And the string returns twelve bytes each instead of two bytes when compared to wchar_t.
As a possible way, maybe upper-type alignment distorts the string's size somewhere?
From dll, pointer to string const wchar_t* copies an even string, with these parameters
With these parameters, of course, it leaks.
But the string turns out even, not a single extra character slips through. And after terminating the program, the Expert Advisor log displays a message
And there is such a test.
It shows the following
The char character ' ' returns two bytes instead of one. Probably because it's in Unicode. And the string returns twelve bytes each instead of two bytes when compared to wchar_t.
As a possible way, maybe upper-type alignment distorts the string's size somewhere?
string is an object that has something besides a pointer to a string.
Hello all! It seems that ResourceReadImage() function doesn't work correctly when getting data from BMP files! I made a script to draw a picture as a background on canvas. If we take out a picture from file located on a hard drive and just fill it on canvas, everything works fine, but if we take out pixels from BMP resource which is located in ex5 file itself using ResourceReadImage() function, the resulting image will look like a tiny and greatly enlarged slice of source picture. What is the reason?
//+------------------------------------------------------------------+//| BMP_Background_X.mqh |//| Copyright 2009-2017, MetaQuotes Software Corp. |//| http://www.mql5.com |//+------------------------------------------------------------------+#property copyright"2009-2017, MetaQuotes Software Corp."#property link"http://www.mql5.com"//#property description "Создание фоновой подложки с картиной из BMP файла"//+------------------------------------------------------------------+#include <Canvas\Canvas.mqh>
#include <\Canvas\Charts\ChartCanvas.mqh>
#include <Arrays\ArrayObj.mqh>
#resource "\\Files\\bmp_resource_002.bmp"// bmp_resource_002.bmp находится в каталог_данных_терминала\MQL5\Files\ //+------------------------------------------------------------------+//| inputs |//+------------------------------------------------------------------+inputint X=10; //координата Xinputint Y=60; //координата Yinputcolor Color=clrMagenta; //цвет заливкиinputuchar BackgroundTransparentLevel=150; //прозрачность ценового графика и его фона//input string FileName="bmp_resource_001.bmp"; //имя BMP рисунока из папки \MQL5\Fileinputstring ResName="CanvasBackground"; //имя создаваемого графического ресурса
CChartCanvas canvas; //создание канвы//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+intOnStart(void)
{
//--- Создадим канвуint width=50;
int height=50;
//--- COLOR_FORMAT_ARGB_RAW - Компоненты цвета не обрабатываются терминалом (должны быть корректно заданы пользователем)//--- COLOR_FORMAT_ARGB_NORMALIZE - Компоненты цвета обрабатываются терминалом//--- COLOR_FORMAT_XRGB_NOALPHA - Компонента альфа-канала (прозрачность) игнорируетсяif(!canvas.CreateBitmapLabel(ResName,X,Y,width,height,COLOR_FORMAT_ARGB_NORMALIZE))
{
Print("Error creating canvas: ",GetLastError());
return(false);
}
//--- Грузим фон на канву из файла на жёстком диске (делаем фоновый рисунок из BMP файла)
canvas.LoadFromFile("bmp_resource_002.bmp"); //грузим рисунок из папки \MQL5\Files
canvas.Update(); //фон нарисован Sleep(10000); //пауза десять секунд //--- стираем полученный результат и обновляем график
canvas.Erase(ColorToARGB(clrBlack,0));
canvas.Update();
Sleep(3000); //пауза три секунды//--- Грузим фон на канву из данного ex5 файла скрипта (делаем фоновый рисунок из ресурса)string path="::Files\\bmp_resource_002.bmp";
uint bmp_data[]; //массив для получения пикселовResourceReadImage(path,bmp_data,width,height); // получаем массив пикселей Print("Итоговый размер массива с пикселами: "+string(ArraySize(bmp_data)));
Print("Разрешение полученного изображения: "+string(width)+" X "+string(height));
//--- меняем размер канвы
canvas.Resize(width,height);
//--- заливаем фон из массива на канвуfor(int x1=0; x1<width && !IsStopped(); x1++)
for(int y1=0; y1<height && !IsStopped(); y1++)
{
canvas.PixelSet(x1,y1,bmp_data[x1+y1]);
}
canvas.Update();
Sleep(5000); //пауза пять секунд//--- стираем полученный результат и обновляем график
canvas.Erase(ColorToARGB(clrBlack,0));
canvas.Update();
//--- завершение работы кода по созданию подложкиObjectDelete(0,ResName);
ResourceFree(path);
canvas.Destroy();
//----ChartRedraw(0);
return(0);
}
//+------------------------------------------------------------------+
From the dll, the const wchar_t* string pointer copies a plain string, with these parameters
With these parameters, of course, it leaks.
But the string turns out to be an even one, with no extra character missing. And after terminating the program, the Expert Advisor log displays a message
And such a test
It shows the following
The char character ' ' returns two bytes instead of one. Probably because it's in Unicode. And the string returns twelve bytes each instead of two bytes when compared to wchar_t.
As a possible way, maybe upper-type alignment distorts the string's size somewhere?
1. in MQL only Unicode, that's why the character size is 2 bytes
2. string is a structure (4 bytes buffer size and 8 bytes pointer size)
The copy to string should be
wcscpy(out,data);
If this does not work, the error must be found elsewhere
Nikolay Kositsin: Hello all! It seems that ResourceReadImage() function doesn't work correctly when getting data from BMP files! I made a script to draw a picture as a background on canvas. If we take out a picture from file located on a hard drive and just fill it on canvas, everything works fine, but if we take out pixels from BMP resource which is located in ex5 file itself using ResourceReadImage() function, the resulting image will look like a tiny and greatly enlarged slice of source picture. What is the reason?
The copy point cycle is wrong, replace it with
//--- заливаем фон из массива на канвуfor(int y1=0; y1<height && !IsStopped(); y1++)
for(int x1=0; x1<width; x1++)
{
canvas.PixelSet(x1,y1,bmp_data[y1*width+x1]);
}
And this question - how to get a list of input variables, the same as comes inFrameInputs() function, but only in one pass, without optimization ?
Yes, quite recently such a question had come up, I've somehow lost sight of it, and now I've got such a task myself (I want to make set-files automatically).
In what direction to dig ? And if anyone remembers that discussion - where is it (I can't find it) ?
Of course, in each Expert Advisor I could write a function, which would create such a list, but it would be better to have a universal library function.
Can you tell me what could be the reason for [Too many trade requests] error on the second call of the OrderSend routine (after starting the terminal) ?
Looked through logs from Monday to Thursday. I have seen the same thing in every log: First limit order is sent successfully and all next orders will have error [Too many trade requests]. Then they start to pass. The only criminal action is frequent call of CopyTickRange in OnInit().
BCS Broker MetaTrader 5 Terminal x64 build 2170 started
@Ilyas
From dll, pointer to string const wchar_t* copies an even string, with these parameters
wcsncpy( out, data, wcslen(data) * 2 );With these parameters, of course, it leaks.
But the string turns out even, not a single extra character slips through.
And after terminating the program, the Expert Advisor log displays a message
And there is such a test.
It shows the following
The char character ' ' returns two bytes instead of one. Probably because it's in Unicode.
And the string returns twelve bytes each instead of two bytes when compared to wchar_t.
As a possible way, maybe upper-type alignment distorts the string's size somewhere?
@Ilyas
From dll, pointer to string const wchar_t* copies an even string, with these parameters
With these parameters, of course, it leaks.
But the string turns out even, not a single extra character slips through.
And after terminating the program, the Expert Advisor log displays a message
And there is such a test.
It shows the following
The char character ' ' returns two bytes instead of one. Probably because it's in Unicode.
And the string returns twelve bytes each instead of two bytes when compared to wchar_t.
As a possible way, maybe upper-type alignment distorts the string's size somewhere?
@Ilyas
From the dll, the const wchar_t* string pointer copies a plain string, with these parameters
With these parameters, of course, it leaks.
But the string turns out to be an even one, with no extra character missing.
And after terminating the program, the Expert Advisor log displays a message
And such a test
It shows the following
The char character ' ' returns two bytes instead of one. Probably because it's in Unicode.
And the string returns twelve bytes each instead of two bytes when compared to wchar_t.
As a possible way, maybe upper-type alignment distorts the string's size somewhere?
1. in MQL only Unicode, that's why the character size is 2 bytes
2. string is a structure (4 bytes buffer size and 8 bytes pointer size)
The copy to string should be
If this does not work, the error must be found elsewhere
Hello all! It seems that ResourceReadImage() function doesn't work correctly when getting data from BMP files! I made a script to draw a picture as a background on canvas. If we take out a picture from file located on a hard drive and just fill it on canvas, everything works fine, but if we take out pixels from BMP resource which is located in ex5 file itself using ResourceReadImage() function, the resulting image will look like a tiny and greatly enlarged slice of source picture. What is the reason?
The copy point cycle is wrong, replace it with
And this question - how to get a list of input variables, the same as comes inFrameInputs() function, but only in one pass, without optimization ?
Yes, quite recently such a question had come up, I've somehow lost sight of it, and now I've got such a task myself (I want to make set-files automatically).
In what direction to dig ? And if anyone remembers that discussion - where is it (I can't find it) ?
Of course, in each Expert Advisor I could write a function, which would create such a list, but it would be better to have a universal library function.You could, of course, write a single function in each EA that would create such a list, but a universal library function would be better.
Take a look here.
Have a look here.
That's right, that's it !
Thank you very much.
1. in MQL only Unicode, that's why the character size is 2 bytes
2. string is a structure (4 bytes buffer size and 8 bytes pointer size)
The copy to string should be
If this doesn't work, the error must be looked for elsewhere
And what happens if the size of the string to be copied is larger or smaller than the size of the allocated buffer?