When the mouse wheel scroll event occurs, the code is executed.
The mouse wheel can be scrolled for several clicks at a time, and we will get not one event with dparam = number of clicks, but several events with dparam = +/-120.
The code is executed for some time, which is much longer than the time between clicks when scrolling the mouse wheel.
As a result, it turns out that nobody is scrolling the mouse wheel anymore, and the programme continues to recalculate for some more time.
//+------------------------------------------------------------------+voidOnInit()
{
ChartSetInteger(0, CHART_EVENT_MOUSE_WHEEL, 0, true);
}
//+------------------------------------------------------------------+voidOnChartEvent(constint id, constlong & lparam, constdouble & dparam, conststring & sparam)
{
staticdouble delta = 0;
if(id == CHARTEVENT_MOUSE_WHEEL)
{
//--- какой то код
delta += dparam / 120;
Sleep(1000);
//---Print(delta);
}
}
//+------------------------------------------------------------------+15:12:22.820 test (EURUSD,H1) 0.015:12:23.821 test (EURUSD,H1) 1.015:12:24.811 test (EURUSD,H1) 2.015:12:25.823 test (EURUSD,H1) 3.015:12:26.817 test (EURUSD,H1) 4.015:12:27.814 test (EURUSD,H1) 5.0
The mouse wheel scrolled at 15:12:22.820 and then the programme was executed 5 more times, for 5 whole seconds.
Question: how to execute the programme code once instead of several times.
That is, the wheel scrolled for 5 clicks, delta = dparam / 120 * 5.
When the mouse wheel scroll event occurs, the code is executed.
The mouse wheel can be scrolled for several clicks at a time, and we will get not one event with dparam = number of clicks, but several events with dparam = +/-120.
The code is executed for some time, which is much longer than the time between clicks when scrolling the mouse wheel.
As a result, it turns out that nobody is scrolling the mouse wheel anymore, and the programme keeps recalculating for some more time.
The mouse wheel scrolled at 15:12:22.820 and then the programme was executed 5 more times, for 5 whole seconds.
Question: how to execute the programme code once instead of several times.
That is, the wheel scrolled for 5 clicks, delta = dparam / 120 * 5.
Try this
//+------------------------------------------------------------------+voidOnInit()
{
ChartSetInteger(0, CHART_EVENT_MOUSE_WHEEL, 0, true);
}
//+------------------------------------------------------------------+voidOnChartEvent(constint id, constlong & lparam, constdouble & dparam, conststring & sparam)
{
staticdouble delta = 0;
bool flag = true;if(id == CHARTEVENT_MOUSE_WHEEL)
{
//--- какой то код
delta += dparam / 120;
Sleep(1000);
//---if(flag)
{
Print(delta);
flag = false;
}
}
}
//+------------------------------------------------------------------+
I didn't check it, if anything, it's not my fault...)))))) I'll have to do something with the flag... and maybe I'll have to put the code into a custom function and mess with the flag there.
On 03 June I published my script for MT5(https://www.mql5.com/ru/code/44732).... It is still in the status of "being checked by moderator". Who knows how long to wait for checking?
I didn't check it, if it's not my fault...)))))) I'll have to mess with the flag somehow... and maybe I'll have to put the code into a custom function and mess with the flag there.
The problem is that custom functions are run only inside event functions, and I have only two such functions OnInit and OnChartEvent in my EA.
In general, I managed to do it, though not quite ace, but still better than it was.
23:48:28.853 test (EURUSD,H1) 1.023:48:29.857 test (EURUSD,H1) 1.023:48:30.856 test (EURUSD,H1) 4.023:48:31.881 test (EURUSD,H1) 2.023:48:32.880 test (EURUSD,H1) 4.023:48:33.887 test (EURUSD,H1) 11.023:48:34.914 test (EURUSD,H1) 15.023:48:35.926 test (EURUSD,H1) 7.023:48:36.936 test (EURUSD,H1) 9.023:48:46.477 test (EURUSD,H1) 6.023:48:47.479 test (EURUSD,H1) -1.0
The problem is that custom functions are run only inside event functions, and I have only two such functions OnInit and OnChartEvent in my EA.
In general, I managed to do it, although not quite a good idea, but still better than it was.
You can also call custom functions from OnChartEvent without any problems.
The flag is declared at the global level. Inserting OnTick solely to reset the flag is not a problem and will not delay code execution.
If the flag is open, a custom function is called. Internally, the flag was closed. In OnTick, the flag is opened again and waits for the next execution of the user function.
I think it's easier than getting stuck on execution time.
You can call custom functions from OnChartEvent too, no problem.
The flag is declared at the global level. Inserting OnTick solely to reset the flag is not a problem and will not delay code execution.
If the flag is open, a custom function is called. Internally, the flag was closed. In OnTick the flag is opened again and waits for the next execution of the user function.
I think it's easier than getting tied to the execution time.
I don't quite get it, or rather I don't get it at all :)
And if there are no ticks, OnTick doesn't work without ticks, what should I do?
Actually I call custom functions from OnChartEvent anyway. It was just a problem to track the last mouse click when scrolling the wheel.
The task was to delay the execution of the custom function until the moment of stopping the wheel scrolling, while counting the number of clicks during scrolling.
On 03 June I published my script for MT5(https://www.mql5.com/ru/code/44732).... It is still in the status of "being checked by moderator". Who knows how long to wait for checking?
Just published the code. Verification took less than a minute.
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.
I can't figure out how to do it.
When the mouse wheel scroll event occurs, the code is executed.
The mouse wheel can be scrolled for several clicks at a time, and we will get not one event with dparam = number of clicks, but several events with dparam = +/-120.
The code is executed for some time, which is much longer than the time between clicks when scrolling the mouse wheel.
As a result, it turns out that nobody is scrolling the mouse wheel anymore, and the programme continues to recalculate for some more time.
The mouse wheel scrolled at 15:12:22.820 and then the programme was executed 5 more times, for 5 whole seconds.Question: how to execute the programme code once instead of several times.
That is, the wheel scrolled for 5 clicks, delta = dparam / 120 * 5.
I can't figure out how to do it.
When the mouse wheel scroll event occurs, the code is executed.
The mouse wheel can be scrolled for several clicks at a time, and we will get not one event with dparam = number of clicks, but several events with dparam = +/-120.
The code is executed for some time, which is much longer than the time between clicks when scrolling the mouse wheel.
As a result, it turns out that nobody is scrolling the mouse wheel anymore, and the programme keeps recalculating for some more time.
The mouse wheel scrolled at 15:12:22.820 and then the programme was executed 5 more times, for 5 whole seconds.Question: how to execute the programme code once instead of several times.
That is, the wheel scrolled for 5 clicks, delta = dparam / 120 * 5.
Try this
I didn't check it, if anything, it's not my fault...)))))) I'll have to do something with the flag... and maybe I'll have to put the code into a custom function and mess with the flag there.
On 03 June I published my script for MT5(https://www.mql5.com/ru/code/44732).... It is still in the status of "being checked by moderator". Who knows how long to wait for checking?
Try this
I didn't check it, if it's not my fault...)))))) I'll have to mess with the flag somehow... and maybe I'll have to put the code into a custom function and mess with the flag there.
The problem is that custom functions are run only inside event functions, and I have only two such functions OnInit and OnChartEvent in my EA.
In general, I managed to do it, though not quite ace, but still better than it was.
The problem is that custom functions are run only inside event functions, and I have only two such functions OnInit and OnChartEvent in my EA.
In general, I managed to do it, although not quite a good idea, but still better than it was.
You can also call custom functions from OnChartEvent without any problems.
The flag is declared at the global level. Inserting OnTick solely to reset the flag is not a problem and will not delay code execution.
If the flag is open, a custom function is called. Internally, the flag was closed. In OnTick, the flag is opened again and waits for the next execution of the user function.
I think it's easier than getting stuck on execution time.
You can call custom functions from OnChartEvent too, no problem.
The flag is declared at the global level. Inserting OnTick solely to reset the flag is not a problem and will not delay code execution.
If the flag is open, a custom function is called. Internally, the flag was closed. In OnTick the flag is opened again and waits for the next execution of the user function.
I think it's easier than getting tied to the execution time.
I don't quite get it, or rather I don't get it at all :)
And if there are no ticks, OnTick doesn't work without ticks, what should I do?
Actually I call custom functions from OnChartEvent anyway. It was just a problem to track the last mouse click when scrolling the wheel.
The task was to delay the execution of the custom function until the moment of stopping the wheel scrolling, while counting the number of clicks during scrolling.
In principle, it worked.
On 03 June I published my script for MT5(https://www.mql5.com/ru/code/44732).... It is still in the status of "being checked by moderator". Who knows how long to wait for checking?
Just published the code. Verification took less than a minute.
Most likely you made a mistake while publishing.
Just published the code. Checking it took less than a minute.
Most likely you made a mistake when publishing it.
Tried publishing again... and it's the same thing:
under "5. Test" it says"Thetest was completed without errors" and offers to publish it, but when you click on the "Publish" button you get an error
404. This page does not exist
In the subsection "My Codes" there are now two codes and on both of them "checked by moderator".
In general, I'll ask a question in the general thread, maybe the moderators will still notice.
Tried publishing again... and it's the same thing:
under "5. Test" it says"Thetest was completed without errors" and offers to publish it, but when I click on the "Publish" button I get an error
404. This page does not exist
There are now two codes in the "My Codes" subsection and both of them have "being checked by moderator".
In general, I will ask a question in the general thread, maybe moderators will still notice.
So they see everything here. You can rest assured.