It's not appropriate for a moderator to start a flood. To clarify. When a user (including a moderator) adds a new post to a thread, it is common to call it a "reply". Even if it is a rejoinder of a sarcastic nature.
Therefore, once again, with a clarification: If you perceive it as a circus, feel free to delete it, or try to submit a new message on its merits. Inaccurate information, on the other hand, can mislead users.
To add. I'll be the first to thank you if it officially turns out (if you help to find out) that user events fill the queue according to the old rules.
I'll add. I'll be the first to thank you if it turns out officially (if you help to find out) that custom events fill the queue according to the old rules.
Roughly speaking, the handling of events never changed. It's just that the help was not initially written quite correctly.
The problem doesn't seem to arise any more, as if it never happened.Alex, could you please take a look in your office, if you have a spare minute. That is, how it will work now with and without your add-on.
It happens due to sending of the EventChartCustom event from the Expert Advisor to itself. It turns out that this sending of event causes the main window to update the chart (ChartRedraw).
//---
I made such an expert to test your solution and at the same time tried to solve the problem with super frequent flickering of text while editing an OBJ_EDIT object.
//---
//+------------------------------------------------------------------+//| OnChartEvent.mq5 |//+------------------------------------------------------------------+#property copyright "Copyright 2010, MetaQuotes Software Corp."#property link "http://www.mql5.com"#property version "1.00"//---long chart_id=0;
string OnOff_event_idle="On/Off event_idle++";
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
chart_id=ChartID();
//---if(!GlobalVariableCheck(OnOff_event_idle)) { GlobalVariableSet(OnOff_event_idle,1); }
//---
Create_Edit(chart_id,0,"Edit_Area","HELLO",CORNER_LEFT_UPPER,"Arial",7,clrWhite,38,18,95,4,1,clrBlack);
Create_Button(chart_id,0,"Start_event_idle","START event_idle++",ANCHOR_RIGHT_UPPER,CORNER_LEFT_UPPER,"Arial",8,clrWhite,clrFireBrick,clrNONE,130,26,4,28,1);
//---Comment("id: ",0,"\n",
"event_idle++: ",event_idle
);
//---return(0);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
Comment("");
ObjectsDeleteAll(chart_id,-1,-1);
}
//+------------------------------------------------------------------+//| ChartEvent function |//+------------------------------------------------------------------+bool bidle=false;
ushort VM_IDLE=500;
ulong event_idle=0; // счётчик событий//---voidOnChartEvent(constint id,
constlong &lparam,
constdouble &dparam,
conststring &sparam)
{
if(GlobalVariableGet(OnOff_event_idle)==1)
{
if(id==CHARTEVENT_CUSTOM+VM_IDLE)
{
// Если последнее посланное больше, чем пришедшее, то сразу выходимif(event_idle>(ulong)lparam || bidle)
{
bidle=event_idle>(ulong)lparam;
//---if(bidle) { return; }
//---
event_idle=0;
}
//---
event_idle++; // увеличили счётчик событий//---Comment("id: ",id,"\n",
"event_idle++: ",event_idle
);
//---EventChartCustom(chart_id,VM_IDLE,(long)event_idle,0,""); return; // отправили событие с указанием последнего счетчика
}
//---EventChartCustom(chart_id,VM_IDLE,(long)event_idle,0,""); // отправили событие с указанием последнего счетчика
}
//+------------------------------------------------------------------+//| СОБЫТИЕ_CHARTEVENT_CLICK |//+------------------------------------------------------------------+if(id==CHARTEVENT_CLICK)
{
Print("Reset. Event_idle: ",event_idle);
//---
event_idle=0;
//---Comment("id: ",id,"\n",
"event_idle++: ",event_idle
);
}
//+------------------------------------------------------------------+//| СОБЫТИЕ_CHARTEVENT_OBJECT_CLICK |//+------------------------------------------------------------------+if(id==CHARTEVENT_OBJECT_CLICK)
{
if(sparam=="Edit_Area")
{
if((int)GlobalVariableGet(OnOff_event_idle)==0) { GlobalVariableSet(OnOff_event_idle,1); }
if((int)GlobalVariableGet(OnOff_event_idle)==1) { GlobalVariableSet(OnOff_event_idle,0); }
}
//---if(sparam=="Start_event_idle")
{
if((int)GlobalVariableGet(OnOff_event_idle)==0) { GlobalVariableSet(OnOff_event_idle,1); ChartRedraw(); return; }
if((int)GlobalVariableGet(OnOff_event_idle)==1) { GlobalVariableSet(OnOff_event_idle,0); ChartRedraw(); return; }
}
}
//+------------------------------------------------------------------+//| CHARTEVENT_OBJECTS_ENDEDIT |//+------------------------------------------------------------------+if(id==CHARTEVENT_OBJECT_ENDEDIT)
{
if(ObjectGetInteger(chart_id,"Start_event_idle",OBJPROP_STATE)) { GlobalVariableSet(OnOff_event_idle,1); }
}
}
//+------------------------------------------------------------------+//| СОЗДАНИЕ_ОБЪЕКТА_BUTTON |//+------------------------------------------------------------------+void Create_Button(long chrt_id, // id графикаint nmb_win, // номер окнаstring lable_nm, // имя объектаstring rename, // отображаемое имяlong anchor, // точка привязкиlong corner, // угол привязкиstring font_bsc, // шрифтint font_size, // размер шрифтаcolor font_clr, // цвет шрифтаcolor bg_color, // цвет фонаcolor brd_color, // цвет рамкиint xsize, // ширинаint ysize, // высотаint x_dist, // координата по шкале Xint y_dist, // координата по шкале Ylong zorder) // приоритет
{
if(ObjectCreate(chrt_id,lable_nm,OBJ_BUTTON,nmb_win,0,0)) // создание объекта
{
ObjectSetString(chrt_id,lable_nm,OBJPROP_TEXT,rename); // установка имениObjectSetString(chrt_id,lable_nm,OBJPROP_FONT,font_bsc); // установка шрифтаObjectSetInteger(chrt_id,lable_nm,OBJPROP_COLOR,font_clr); // установка цвета шрифтаObjectSetInteger(chrt_id,lable_nm,OBJPROP_BGCOLOR,bg_color); // установка цвета фонаObjectSetInteger(chrt_id,lable_nm,OBJPROP_BORDER_COLOR,brd_color); // установка цвета фонаObjectSetInteger(chrt_id,lable_nm,OBJPROP_ANCHOR,anchor); // установка точки привязкиObjectSetInteger(chrt_id,lable_nm,OBJPROP_CORNER,corner); // установка угола привязкиObjectSetInteger(chrt_id,lable_nm,OBJPROP_FONTSIZE,font_size); // установка размера шрифтаObjectSetInteger(chrt_id,lable_nm,OBJPROP_XSIZE,xsize); // установка ширины XObjectSetInteger(chrt_id,lable_nm,OBJPROP_YSIZE,ysize); // установка высоты YObjectSetInteger(chrt_id,lable_nm,OBJPROP_XDISTANCE,x_dist); // установка координаты XObjectSetInteger(chrt_id,lable_nm,OBJPROP_YDISTANCE,y_dist); // установка координаты YObjectSetInteger(chrt_id,lable_nm,OBJPROP_SELECTABLE,false); // нельзя выделить объект, если FALSEObjectSetInteger(chart_id,lable_nm,OBJPROP_ZORDER,zorder); // Приоритет выше/нижеObjectSetString(chrt_id,lable_nm,OBJPROP_TOOLTIP,"\n"); // нет всплывающей подсказки, если "\n"
}
}
//+------------------------------------------------------------------+//| СОЗДАНИЕ_ОБЪЕКТА_EDIT |//+------------------------------------------------------------------+void Create_Edit(long chrt_id, // id графикаint nmb_win, // номер окна (подокна)string lable_nm, // имя объектаstring text, // отображаемый текстlong corner, // угол привязкиstring font_bsc, // шрифтint font_size, // размер шрифтаcolor font_clr, // цвет шрифтаint xsize, // ширинаint ysize, // высотаint x_dist, // координата по шкале Xint y_dist, // координата по шкале Ylong zorder, // приоритетcolor clr) // цвет фона
{
if(ObjectCreate(chrt_id,lable_nm,OBJ_EDIT,nmb_win,0,0)) // создание объекта
{
ObjectSetString(chrt_id,lable_nm,OBJPROP_TEXT,text); // установка имениObjectSetInteger(chrt_id,lable_nm,OBJPROP_CORNER,corner); // установка угла привязкиObjectSetString(chrt_id,lable_nm,OBJPROP_FONT,font_bsc); // установка шрифтаObjectSetInteger(chrt_id,lable_nm,OBJPROP_FONTSIZE,font_size); // установка размера шрифтаObjectSetInteger(chart_id,lable_nm,OBJPROP_COLOR,font_clr); // цвет шрифтаObjectSetInteger(chart_id,lable_nm,OBJPROP_BGCOLOR,clr); // цвет фонаObjectSetInteger(chart_id,lable_nm,OBJPROP_XSIZE,xsize); // ширинаObjectSetInteger(chart_id,lable_nm,OBJPROP_YSIZE,ysize); // высотаObjectSetInteger(chrt_id,lable_nm,OBJPROP_XDISTANCE,x_dist); // установка координаты XObjectSetInteger(chrt_id,lable_nm,OBJPROP_YDISTANCE,y_dist); // установка координаты YObjectSetInteger(chrt_id,lable_nm,OBJPROP_SELECTABLE,false); // нельзя выделить объект, если FALSEObjectSetInteger(chart_id,lable_nm,OBJPROP_ZORDER,zorder); // Приоритет выше/нижеObjectSetString(chrt_id,lable_nm,OBJPROP_TOOLTIP,"\n"); // нет всплывающей подсказки, если "\n"
}
}
//+------------------------------------------------------------------+
//---
After launching the Expert Advisor, you will see the following on the chart in the upper left corner:
//---
By clicking on the"START event_idle++" button you will access your(Alex) solution. We see the event_idle++ counter increment right on the chart.
As long as the button is pressed your code will work. But it consumes a lot of resources. CPU load (tested on dual core) ranges from ~90% to ~100%. CPU load ranges from ~5% to ~10% before start or when button is released. Clicking (left-clicking) on the graph resets the counter to zero.
Entering text in the input field doesn't cause flicker, because at the moment of input your code is disabled by the"On/Off event_idle++" global variable. It's a crutch of course, but as a temporary solution it's fine for some simple solutions.
CPU load is not the only problem. When the counter is running, windows in the trading terminal open quickly but window resizing slows down quite noticeably. Not always, but such moments are there.
CPU load is not the only problem. When the counter is running, windows in the trading terminal open quickly, but window resizing slows down quite noticeably. Not always, but there are such moments.
CPU load problem can be solved as follows. Specify that the event counter is updated once per second. We add the following code:
CHARTEVENT_OBJECT_CLICK event handler block should be edited as follows + Button state should be checked all the same, because sometimes even pressing it "wrongly" will leave it depressed, if it was like that before, but the rest of code in the block will work out and confusion will start:
1. it ' s a burden on the CPU. Remove it and it will be quiet.
2. The idle loop itself has no noticeable effect on the CPU.
3. The problem with flickering of the edith is not a problem with a single 0-chart. It is a problem with sending an event to the object-chart. This causes the main 0-chart to redraw and gives flicker.
1. it's a burden on the CPU. Remove it and it will be quiet.
2. The idle loop itself has no noticeable effect on the CPU.
3. The problem with flickering of the edith is not a problem with a single 0-chart. It is a problem with sending an event to the object-chart. This causes the main 0-chart to redraw and gives flicker.
And have you asked a new question yet?
It's not appropriate for a moderator to start a flood. To clarify. When a user (including a moderator) adds a new post to a thread, it is common to call it a "reply". Even if it is a rejoinder of a sarcastic nature.
Therefore, once again, with a clarification: If you perceive it as a circus, feel free to delete it, or try to submit a new message on its merits. Inaccurate information, on the other hand, can mislead users.
To add. I'll be the first to thank you if it officially turns out (if you help to find out) that user events fill the queue according to the old rules.
I'll add. I'll be the first to thank you if it turns out officially (if you help to find out) that custom events fill the queue according to the old rules.
Roughly speaking, the handling of events has never changed. It's just that it wasn't originally written correctly in the help.
...
I actively use the idle message created in each of my applications. Everything works.
I actively use the idle message created in each of my applications. Everything is working.
sergeev:
I have caught a bug.It happens due to sending of the EventChartCustom event from the Expert Advisor to itself. It turns out that this sending of event causes the main window to update the chart (ChartRedraw).
//---
I made such an expert to test your solution and at the same time tried to solve the problem with super frequent flickering of text while editing an OBJ_EDIT object.
//---
//---
After launching the Expert Advisor, you will see the following on the chart in the upper left corner:
//---
By clicking on the"START event_idle++" button you will access your(Alex) solution. We see the event_idle++ counter increment right on the chart.
As long as the button is pressed your code will work. But it consumes a lot of resources. CPU load (tested on dual core) ranges from ~90% to ~100%. CPU load ranges from ~5% to ~10% before start or when button is released. Clicking (left-clicking) on the graph resets the counter to zero.
Entering text in the input field doesn't cause flicker, because at the moment of input your code is disabled by the"On/Off event_idle++" global variable. It's a crutch of course, but as a temporary solution it's fine for some simple solutions.
CPU load is not the only problem. When the counter is running, windows in the trading terminal open quickly but window resizing slows down quite noticeably. Not always, but such moments are there.
CPU load is not the only problem. When the counter is running, windows in the trading terminal open quickly, but window resizing slows down quite noticeably. Not always, but there are such moments.
CPU load problem can be solved as follows. Specify that the event counter is updated once per second. We add the following code:
In OnInit():
//---
In the program body:
//---
To Alex's code (marked in red):
//---
InCHARTEVENT_CLICK event handler block(marked in red):
//---
CHARTEVENT_OBJECT_CLICK event handler block should be edited as follows + Button state should be checked all the same, because sometimes even pressing it "wrongly" will leave it depressed, if it was like that before, but the rest of code in the block will work out and confusion will start:
//---
Now it gets more interesting. :)
//---
P.S. If you have a lot of seconds, you can try fiddling with GetTickCount().
What can I say
1. it ' s a burden on the CPU. Remove it and it will be quiet.
2. The idle loop itself has no noticeable effect on the CPU.
3. The problem with flickering of the edith is not a problem with a single 0-chart. It is a problem with sending an event to the object-chart. This causes the main 0-chart to redraw and gives flicker.
What can I say
1. it's a burden on the CPU. Remove it and it will be quiet.
2. The idle loop itself has no noticeable effect on the CPU.
3. The problem with flickering of the edith is not a problem with a single 0-chart. It is a problem with sending an event to the object-chart. This causes the main 0-chart to redraw and gives flicker.