Download MetaTrader 5
To add comments, please log in or register
Unable to find the right application? Order it!
Nikolay
170
Nikolay 2016.04.10 14:04 

I would like to 1) display on the chart a button, that 2) when clicked executes a specified function. What is the easiest way to do it?

I found:

  • the OBJ_BUTTON page, but no simple (one-liner) API and no info how to add a click method: https://docs.mql4.com/constants/objectconstants/enum_object/obj_button
  • MT4GUI, it is simple to use, but needs registration and .dll file to be added, things I want to avoid. Any other easy to use (open source) alternatives? http://www.mt4gui.com
Fernando Carreiro
1438
Fernando Carreiro 2016.04.10 14:32  

All interaction with Chart Objects is handled by the Chart Events Handler "OnChartEvent()". You can then detect the "CHARTEVENT_OBJECT_CLICK" event and have the function handle it as you see fit.

Please, note however, that Chart Events are not emulated in the Strategy Tester and you will need to handle them in a different way (have a look this thread here and my post at the end about this point).

Nikolay
170
Nikolay 2016.04.10 18:06  
great info! Thank you FMIC!
Keith Watford
Moderator
7887
Keith Watford 2016.04.10 19:36  
FMIC:

Please, note however, that Chart Events are not emulated in the Strategy Tester and you will need to handle them in a different way


Strange though that Chart Events work when testing an indicator, but not an EA. I would hope that this means that Chart Events will eventually be available for EAs in the strategy tester as well.
Fernando Carreiro
1438
Fernando Carreiro 2016.04.10 21:03  
GumRai:
Strange though that Chart Events work when testing an indicator, but not an EA. I would hope that this means that Chart Events will eventually be available for EAs in the strategy tester as well.
I would not be so sure! The thread I referenced is over 2 years old, and still it is not resolved!
Alain Verleyen
Moderator
28522
Alain Verleyen 2016.04.10 21:08  
GumRai:
Strange though that Chart Events work when testing an indicator, but not an EA. I would hope that this means that Chart Events will eventually be available for EAs in the strategy tester as well.

I don't know the underlying reason, but I don't think Metaquotes will change it.

Anyway, using an indicator is a good workaround, you just need to use iCustom() in your EA. 

Fernando Carreiro
1438
Fernando Carreiro 2016.04.10 21:25  
angevoyageur:

Anyway, using an indicator is a good workaround, you just need to use iCustom() in your EA. 

I disagree about the use of an Indicator as a workaround or general solution to the problem. Maybe for some, but definitely not for many other cases. 

In my particular case, the use of the Indicator would not achieve the desired goal. In some of my EA's I use buttons to have the EA execute certain tasks, such as placement of manual orders which the EA calculates Volume, S/L  & T/P, based on several underlying conditions and then continues to monitor and manage the orders (such as trailing or closing on signal changes) while I walk away and leave it be.

That is why, I started coding it in a way, that would work with Chart Events when live but when in Visual Mode in the Strategy Tester, it would check the state of buttons manually on every tick.

/
To add comments, please log in or register