![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I found that scripts are not aware of OnChartEvent(),
The only way I found was to create an expert advisor, as it's aware of OnChartEvent()
As it's the first time I wrote an expert advisor, I don't know what exactly it does, but it appears it waits for a new tick,
so when I give it click events, they will fire up when a new tick comes in,
apparently, but I maybe wrong about this, more testing needed (or reading in docs :) )
Anyway,
I would love to know if it's possible to get two, three or multiple click events from scripts some other way.
Scripts can't catch events. Expert advisors and indicators can.
OnChartEvent() is independent from the OnTick() function.
Create a simple EA with OnChartEvent() and put a print inside - it will activate each time you move mouse or do some other thing on the chart.
Yeah, I tried exactly that,
even with mouse move event (saw an example in docs)
It triggers immediately actually, which is great.
(There was a sleep() or something else, but now it runs fast)
Thank you for responses,
It would be useful if we could use OnChartEvent() in scripts.
Right now I'm not aware of the issues that can appear, probably they had good reasons to not permit scripts to receive events
One line in docs, made me raise an eyebrow though:
"It is not recommended to use infinite loops to handle events. The exception to this rule may be only scripts that process only a single Start event"
( https://www.mql5.com/en/docs/runtime/running )
So that means it's possible to handle events from Start event inside scripts? I don't get it, but maybe they refer to something else...
You can test it easy way -
Other option would be to make expert advisor that will unload itself at some point with ExpertRemove() function. This way you can emulate script behaviour - do something and finish, and you will have OnChartEvent() without infinite loop.
You can test it easy way -
Other option would be to make expert advisor that will unload itself at some point with ExpertRemove() function. This way you can emulate script behaviour - do something and finish, and you will have OnChartEvent() without infinite loop.
I tested it.
OnChartEvent() doesn't work for script... at least up to this date :)
But many thanks for the idea with ExpertRemove(), I was not aware I could do that => great!