What do the pros have to say: How to get mouse scroll values in MQL? [repost from the fifth forum]. - page 7

 
Artyom Trishkin:

What will help him? Your eulogy? You haven't shown a solution. You showed yourself. Which is very, very much to be expected.

Why not? A bit of thought process and everyone will find a solution. I gave a hint where to look for it. In which direction to explore. It's not interesting to have everything on a silver platter. )) If you need, I can help the man and lead him to a solution. But you seem to want to just argue with me.)
 
Vitaly Muzichenko:

Is that what it is?

You have the wrong tendency. You first shout things at me (like "your code is crap", "necroposter"), and then ask and discuss the solution to the problem. So, think for yourself.

Or wait for me to help those who deserve it.

 
Artyom Trishkin:

What will help him? Your eulogy? You haven't shown a solution. You showed yourself. Which is very, very much to be expected.

You are remarkably inattentive.

Look, at the bottom of the post to which I responded, the man is asking for "pointers". He's not asking for a solution. So I tried to push him. Now do you see how inappropriate and ridiculous your interference is? It entails nothing but useless rubbish. You'd be better off communicating on the merits. You'd be doing yourself and others more good.

 
Реter Konow:

You have the wrong tendency. You first shout things at me (like "your code is crap", "necroposter"), and then ask and discuss the solution to the problem. So, think for yourself.

Or wait for me to help those who deserve it.

I wasn't asking, I was stating a fact.

 
Vitaly Muzichenko:

I wasn't asking, I was stating a fact.

What fact?
 

Here, many people do not see the content behind the form. They cannot understand that if there is no idea and no ability to realise it, their insistence on form will not produce quality content.

The essence can have many forms of its embodiments and only an incompetent person can judge it by the language of its expression.

 
Vitaly Muzichenko:

I wasn't asking, I was stating a fact.

I, too, will state a fact.

your "products" are a talentless and ridiculous effort.

This is the most rubbish I have seen in a long time!


Don't take truthful criticism to heart. :)

 
Реter Konow:
Why? A little thought process and everyone will find a solution. I gave you a hint where to look for it. In what direction to investigate. It's not interesting to have everything on a silver platter. )) If you need, I can help the man and lead him to a solution. But it seems that you just want to argue with me).

Hello, Peter!
Don't you want to say you have a practical solution, how to scroll the mouse wheel by means of MQL? And not with keyboard arrows or mouse buttons - it's not that difficult to understand. Of course, we can use event CHARTEVENT_CHART_CHANGE to determine whether the chart is scrolling with wheel, if no keys are pressed, but only probabilistically, because this event can occur just with a new bar coming or a sharp price change, leading to a change of vertical scale. Also, with this method it is not possible to always get the wheel scrolling event, for example when the chart has reached the extreme left or right position, and how to achieve this without scrolling the chart. Maybe you mean to use ChartNavigate function to move the chart back, but that would be a very crooked implementation and it is unlikely to filter out correctly all other reasons for chart changes, other than scrolling the mouse wheel. In my mind, it can only be done by hacking MT or knowing some undocumented commands and/or events. Anyway, I don't believe that you have an example of such implementation.

And you have a strange hint, though. Almost to the question "How to get scrolling event via mouse wheel?", you give the answer"Use scrolling event and a function that moves the graph."

Maybe I'm wrong, and you actually have an example. You're a cool guy then! )) Well, then at least drop the ex4 (ex5) file, not the code.

 
Nikolai Semko:

Hi Peter!
Don't you want to say that you have a practical solution of how to scroll with the mouse wheel in MQL? And not with keyboard arrows or mouse buttons - it's not that difficult to understand. Of course, we can use event CHARTEVENT_CHART_CHANGE to determine whether the chart is scrolling with wheel, if no keys are pressed, but only probabilistically, because this event can occur just with a new bar coming or a sharp price change, leading to a change of vertical scale. Also, with this method it is not possible to always get the wheel scrolling event, for example when the chart has reached the extreme left or right position, and how to achieve this without scrolling the chart. Maybe you mean to use ChartNavigate function to move the chart back, but that would be a very crooked implementation and it is unlikely to filter out correctly all other reasons for chart changes other than mouse wheel scrolling. In my mind, it can only be done by hacking MT or knowing some undocumented commands and/or events. Anyway, I don't believe that you have an example of such implementation.

And you have a strange hint, though. Almost to the question "How to get scrolling event via mouse wheel?", you give the answer"Use scrolling event and a function that moves the graph."

Maybe I'm wrong, and you actually have an example. You're a cool guy then! )) Well, then at least drop the ex4 (ex5) file, not the code.

Hi Nikolay!

Believe it or not, the solution is very simple. It takes 15-20 lines of code. There is one subtle point, though - the specifics of implementation of the scrolling mechanism. My implementation differs a bit from the standard one. It scrolls canvas, not objects. There is a similar implementation in Anatoly's library.

I do scroll with the wheel and by "clinging" to the motion of the chart I get an energizing effect. Of course, the chart twitches but always comes back to its initial position. That is what the chart shift function is for. The chart shift direction is also obtained from the mql-function. Thus, I don't have to hack anything). MQ has tried to give the widest possible functionality to implement almost any task. This is even surprising. Maybe they themselves did not know all the features they open for developers).

 
Nikolai Semko:

Anyway, I don't believe you have an example of such an implementation.

And you have a strange hint, though. Practically to the question "How to get scrolling event via mouse wheel?", you give answer "Use scrolling event and function which moves graph."

Maybe I'm wrong, and you actually have an example. You're a cool guy then! )) Well, at least drop the ex4 (ex5) file, not the code.

Here's the situation. The person to whose post I replied, asked me to give him an idea, how to implement a scrolling mechanism with a wheel. I gave him a hint. Immediately local ill-wishers flared up and started accusing me of bragging and some other nonsense.

From their point of view, if I give a solution, then I'm either advertising my products, or just bragging, and if not, then I'm cheating and I have nothing.

I can give you the code, but firstly, it will be detached from the implementation of the scrolling mechanism, and secondly, it will be in Russian. But maybe you can adapt it to your scrolling mechanism. I can not put eh4, because I can not "tear" a single mechanism from the graphical environment in which it operates.

The best option, would be to give you the solution in general terms, but not with the aim of proving anything, but on the basis of friendship.

And so:

The CHARTEVENT_CHART_CHANGE event is generated, among other things, on the mouse wheel movement event if the cursor is over the graph. The chart offset option must be enabled. Thus, from the chart offset, we can know exactly when we spin the wheel. We can generate a custom event. For example "SCROLLER_EVENT".

Next, our task is to determine the direction of the offset. We use ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR); at each "SCROLLER_EVENT" event we get the number of the first visible bar and determine whether it is more or less than the number of the previous bar that we recorded. If it is more, then it moves in one direction; if it is less, then it moves in the opposite direction. At the same time, our chart will also scroll and can reach the very end. To prevent this, we correct its position using the ChartNavigate function and set the chart at its initial position. This call also generates the CHARTEVENT_CHART_CHANGE event and it will disable our scrolling. So, at the time of chart position correction we must skip the CHARTEVENT_CHART_CHANGE event and not react to it. This requires the use of a flag system.

This is what my code looks like:

//=====================================================================================================================================    
 if(id == CHARTEVENT_CHART_CHANGE && !n)
   {
    if(СОБЫТИЕ_ИНТЕРФЕЙСА != _SCROLLER_EVENT)
      {
       СОБЫТИЕ_ИНТЕРФЕЙСА = _SCROLLER_EVENT; 
      } 
    //------------------------------------  
    if(!Номер_первого_бара){ChartNavigate(0,CHART_END,-100); Номер_первого_бара = ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR);}
    //------------------------------------    
    Номер_этого_бара = ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR);
    //------------------------------------
    int Основание_выпадающего_списка = КАНВАС - 1;
    int Ползунок_                    = КАНВАС + 4;
    int Вертикальная_полоса          = КАНВАС + 2;
    //------------------------------------
    if(Номер_этого_бара > Номер_первого_бара)
      {
       Прокрутка_вниз = 1;
       Прокрутка_вверх = 0;
       Сдвиг = 25;
       n = 1;
      }
    if(Номер_этого_бара  < Номер_первого_бара) 
      {
       Прокрутка_вниз = 0;
       Прокрутка_вверх = 1;
       Сдвиг = -25;
       n = 1;
      }//Alert(__FUNCTION__," Номер_первого_бара   ",Номер_первого_бара,"  Номер_этого_бара  ",Номер_этого_бара);  
    //------------------------------------
    if(КАТЕГОРИЯ_КАНВАСА_ОБЪЕКТА == _SCROLL_BAR_CANVAS && !G_CORE[ОКНО][Вертикальная_полоса][_OBJECT_HIDE])
      {
       int Поле_обзора = G_CORE[ОКНО][КАНВАС][_VIEW_SQUARE];
       //Элемент которому принадлежит сам канвас.
       int Элемент_прокручиваемого_канваса =  G_CORE[ОКНО][КАНВАС][_MAIN_ELEMENT];
       //Канвас элемента, которому принадлежит прокручиваемый канвас.
       int Канвас_того_элемента = G_CORE[ОКНО][Элемент_прокручиваемого_канваса][_DROWING_CANVAS];
       int Группа_элемента_прокручиваемого_канваса = G_CORE[ОКНО][Элемент_прокручиваемого_канваса][_OBJECT_GROUP];

       //------------------------------------
       G_CORE[ОКНО][КАНВАС][_IMAGE_VIRTUAL_Y] -= Сдвиг;
       //------------------------------------
       if(G_CORE[ОКНО][КАНВАС][_IMAGE_VIRTUAL_Y] > G_CORE[ОКНО][Поле_обзора][_Y])
        {          
         G_CORE[ОКНО][КАНВАС][_IMAGE_VIRTUAL_Y] = G_CORE[ОКНО][Поле_обзора][_Y];
        } 
       if((G_CORE[ОКНО][КАНВАС][_IMAGE_VIRTUAL_Y] + G_CORE[ОКНО][КАНВАС][_Y_SIZE]) < (G_CORE[ОКНО][Поле_обзора][_Y] + G_CORE[ОКНО][Поле_обзора][_Y_SIZE]))
         {
          G_CORE[ОКНО][КАНВАС][_IMAGE_VIRTUAL_Y] = (G_CORE[ОКНО][Поле_обзора][_Y] + G_CORE[ОКНО][Поле_обзора][_Y_SIZE]) - G_CORE[ОКНО][КАНВАС][_Y_SIZE];
         }
       //------------------------------------  
       G_CORE[ОКНО][КАНВАС][_FIELD_TO_VIEW_Y_DISTANCE] = G_CORE[ОКНО][Поле_обзора][_Y] - G_CORE[ОКНО][КАНВАС][_IMAGE_VIRTUAL_Y];  
       //------------------------------------
       ObjectSetInteger(0,G_CORE[ОКНО][КАНВАС][_NAME],OBJPROP_YOFFSET,G_CORE[ОКНО][КАНВАС][_FIELD_TO_VIEW_Y_DISTANCE]);
       //------------------------------------ 
       G_CORE[ОКНО][Ползунок_][_Y] = G_CORE[ОКНО][Вертикальная_полоса][_Y] + ((double)G_CORE[ОКНО][КАНВАС][_FIELD_TO_VIEW_Y_DISTANCE] / ((double)G_CORE[ОКНО][Ползунок_][_V_SCROLL_BAR_HANDLE_STEP] / 10000));
       //------------------------------------ 
       if(Группа_элемента_прокручиваемого_канваса == VIEW_BOX)
         {
          Нарисовать_элемент(ОКНО,Канвас_того_элемента,Элемент_прокручиваемого_канваса);
         } 
       //------------------------------------
       if(Группа_элемента_прокручиваемого_канваса == DROP_LIST)
         {
          Нарисовать_элемент(ОКНО,Поле_обзора,Элемент_прокручиваемого_канваса);
         } 
      }    
  }
//------------------------------------------------------
if(qw){n = 0; qw = 0;} 
if(n == 1){ChartNavigate(0,CHART_END,-100);  qw = 1;} 
//------------------------------------------------------
//Alert(__FUNCTION__,"  Прокрутка_вниз  ",Прокрутка_вниз,"  Прокрутка_вверх  ",Прокрутка_вверх);
//=====================================================================================================================================   



Added:

As for other causes of chart shifts, of course, they can introduce errors into our system. However, these errors are so insignificant that we should not pay much attention to them. So if the new bar moves our canvas a few pixels... It's not a big deal. And that's only if the cursor will be over the scroll bar at that time.

Of course, the implementation is an attempt to find a way out of a hopeless situation. With the complete lack of scrolling with the wheel, this is the simplest and most "native" solution. For a full-fledged solution, I've already contacted servicedesk. Whether it is or not depends on the developers.
Reason: