Home Forex EA's Robots Forex MT4 EA Chart Event Test Example Expert Advisor for MetaTrader 4 Platform

Chart Event Test Example Expert Advisor for MetaTrader 4 Platform



ChartEvent Test Example Expert Advisor For MetaTrader4 Platform.

The “Test_ChartEvent.mq4″ Expert Advisor is an example demonstrating the various types of ChartEvent: keyboard keys events, mouse click & move events, custom events. You can press the ‘H’ key for help and press the ‘M’ key to enter the MOUSE_MOVE event mode.

The source code works both in MetaTrader 4 and MetaTrader 5.

Function Prototype
bool Obj_Create()
bool Obj_Delete()
bool Obj_Move(int hSens,int vSens) – moves an object.
void Print_Info() – prints information about the objects.
int MouseMove(int aXX,int aYY,string sState) – handles the mouse move event.
Global Variables
int gChartNo=0
int gSubWinNo=0
string gsObj_Name_selected=”” – the name of currently selected object.
Custom Events
Three types of custom events are defined:

#define cMyEvent_1 0
#define cMyEvent_2 1
#define cMyEvent_3_broadcast 2
OnTimer() Function
This function creates the custom ChartEvent periodically. And the function randomly generates these three custom events (cMyEvent_1, cMyEvent_2 and cMyEvent_3_broadcast). In particular, the cMyEvent_3_broadcast event is generated for all open chart windows.

Example of class
Class “CObjectMan” is created to handle the functionality for objects on a chart. Two instances (variables) of the class are declared: gObjectMan1 and gObjectMan2.

The names of the Graphic Objects linked to these two instances are respectively: “Green Button” and “Yellow Button”.

Event Processing
void OnChartEvent():


4 directional keys (arrows) or the 4 directional keys on the digital panel to move the selected object.
‘H’: print the Help information (in expert log window).
‘I’: print the positions information of two Objects.
‘M’: active the MOUSE_MOVE event.
Custom Events
Print information about these events. Especially for the MyEvent_3_broadcast event.

Object Events
CHARTEVENT_OBJECT_CLICK – print the name of object being clicked, select its name for moving by the direction keys.
Mouse Events
CHARTEVENT_CLICK – print the clicked bar’s information: the prices (open, close) and the bar time.
CHARTEVENT_MOUSE_MOVE (see: CHART_EVENT_MOUSE_MOVE) – print the information of the covered interval: number of bars, price variation.
ChartEvent Test Example

You can perform the following tests:

Click on one of the two objects (Buttons) to select and use the arrow keys to move the selected object.
Click on graphic bar and see the information of the bar in the log tab (message).
Press the ‘M’ key to enter the MOUSE_MOVE event mode. Press Ctrl+F to show the crosshair, then perform a drag’n’drop operation. If you do not see the log message, please change the input parameter: “iLogLevel”.

1. Copy “ChartEvent Test Example.mq4” file to C:/Program Files/MetaTrader4/experts folder
and restart your MetaTrader.
2. Open Navigator/Custom Expert Advisors panel and drag the Expert Advisor named “ChartEvent Test Example.mq4” to the
chart of any currency pair.
3. Click On “Enable Automated Trading” On Metatrader Platform.

Click to Download: Test_ChartEvent

Forex Buy and Sell Indicator is better and safe strategy Indicator for Forex trading.
Its very important to understand forex news and market movement.
Please read Installation And User Guide Of “Forex Pips Magnet Indicator” carefully do not skip any single page.
Before using indicators first use it on demo account , keep update yourself and analysis it to use live account (Micro).

Download Now: Forex Buy and Sell Arrow Indicator! Click Here!!

We Dont Lock download link for any kind of subscriptions or social sharing,
but if you like our system then please subscribe and social share from below social sharing button link.


Please enter your comment!
Please enter your name here