Hi all. I'm trying to make simple indi which will speed up placing sup/res lines on the chart.
It will place Hline on mouse click only while holding (ctrl for Blue or shift for Red line) but I don't know how to combine CHARTEVENT_KEYDOWN & CHARTEVENT_CLICK or I'm doing it the wrong way?
Can someone help me with this please.
Hi Jack
It's a bit of a pain in native MQL as there is no KEYUP event. Also, if the user is say holding down CTRL, then they hold down and release SHIFT, you'll get no more KEY events. And thirdly, whilst the dparam is supposed to hold the repeat count of a key being pressed, it doesn't seem to work (in MQL4 at least, not sure about MQL5). So all this makes it very difficult to track keydown & up events.
You will also have an issue with your statement
if (id==CHARTEVENT_KEYDOWN && id==CHARTEVENT_CLICK)
I don't believe you will ever get this statement to be true. The chart event will be called once for the keydown and once for the click, each with a different lparam and more importantly, different "EVENT" type
One work around would be to set a global bool like CTRL_DOWN & SHIFT_DOWN & set it to true when you capture a key event. Then when the chart event captures a click, check the state of those vars. Of course, you could run into the problem where say the CTRL key was pressed, then released but the bool would not reset. So you would also have to come up with a solution for reseting those events.
The final option would be to use windows DLLs which is fine if the program is only going to be yours, but can't be used if you want to sell it on the market in MQL5.com
Hope that points you in the right direction mate.
Hi Jack
It's a bit of a pain in native MQL as there is no KEYUP event. Also, if the user is say holding down CTRL, then they hold down and release SHIFT, you'll get no more KEY events. And thirdly, whilst the dparam is supposed to hold the repeat count of a key being pressed, it doesn't seem to work (in MQL4 at least, not sure about MQL5). So all this makes it very difficult to track keydown & up events.
You will also have an issue with your statement
I don't believe you will ever get this statement to be true. The chart event will be called once for the keydown and once for the click, each with a different lparam and more importantly, different "EVENT" type
One work around would be to set a global bool like CTRL_DOWN & SHIFT_DOWN & set it to true when you capture a key event. Then when the chart event captures a click, check the state of those vars. Of course, you could run into the problem where say the CTRL key was pressed, then released but the bool would not reset. So you would also have to come up with a solution for reseting those events.
The final option would be to use windows DLLs which is fine if the program is only going to be yours, but can't be used if you want to sell it on the market in MQL5.com
Hope that points you in the right direction mate.
Thanks anyway.
This is a very old thread. But hope someone may find it helpful. To check the CTRL key status you use the following code within the OnChartEvent() block.
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id == CHARTEVENT_CLICK) { if(TerminalInfoInteger(TERMINAL_KEYSTATE_CONTROL) != 0) { // Your code } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It will place Hline on mouse click only while holding (ctrl for Blue or shift for Red line) but I don't know how to combine CHARTEVENT_KEYDOWN & CHARTEVENT_CLICK or I'm doing it the wrong way?
Can someone help me with this please.