What is the easiest way to display clickable button?

Back to topics list To post a new topic, please log in or register
avatar
62
nikolaygmt 2016.04.10 16: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
avatar
1197
FMIC 2016.04.10 16: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).

avatar
62
nikolaygmt 2016.04.10 20:06 #
 
great info! Thank you FMIC!
avatar
Moderator
3404
GumRai 2016.04.10 21: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.
avatar
1197
FMIC 2016.04.10 23: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!
avatar
Moderator
3206
angevoyageur 2016.04.10 23: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. 

avatar
1197
FMIC 2016.04.10 23: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.


Back to topics list  

To add comments, please log in or register