- OnStart
- OnInit
- OnDeinit
- OnTick
- OnCalculate
- OnTimer
- OnTrade
- OnTradeTransaction
- OnBookEvent
- OnChartEvent
- OnTester
- OnTesterInit
- OnTesterDeinit
- OnTesterPass
OnChartEvent
The function is called in indicators and EAs when the ChartEvent event occurs. The function is meant for handling chart changes made by a user or an MQL5 program.
void OnChartEvent()
|
Parameters
id
[in] Event ID from the ENUM_CHART_EVENT enumeration.
lparam
[in] long type event parameter
dparam
[in] double type event parameter
sparam
[in] string type event parameter
Return Value
No return value
Note
There are 11 types of events that can be handled using the predefined OnChartEvent() function. 65535 IDs from CHARTEVENT_CUSTOM to CHARTEVENT_CUSTOM_LAST inclusive are provided for custom events. To generate a custom event, use the EventChartCustom() function.
Short event description from the ENUM_CHART_EVENT enumeration:
- CHARTEVENT_KEYDOWN — pressing a key on the keyboard when a chart window is in focus;
- CHARTEVENT_MOUSE_MOVE — moving the mouse and mouse button clicks (if CHART_EVENT_MOUSE_MOVE=true for a chart);
- CHARTEVENT_OBJECT_CREATE — create a graphical object (if CHART_EVENT_OBJECT_CREATE=true for a chart);
- CHARTEVENT_OBJECT_CHANGE — change object properties via the properties dialog;
- CHARTEVENT_OBJECT_DELETE — delete a graphical object (if CHART_EVENT_OBJECT_DELETE=true for a chart);
- CHARTEVENT_CLICK — clicking on a chart;
- CHARTEVENT_OBJECT_CLICK — mouse click on a graphical object belonging to a chart;
- CHARTEVENT_OBJECT_DRAG — dragging a graphical object with a mouse;
- CHARTEVENT_OBJECT_ENDEDIT — finish editing text in the Edit input box of a graphical object (OBJ_EDIT);
- CHARTEVENT_CHART_CHANGE — change a chart;
- CHARTEVENT_CUSTOM+n — custom event ID, where n is within the range from 0 to 65535. CHARTEVENT_CUSTOM_LAST contains the last acceptable custom event ID (CHARTEVENT_CUSTOM+65535).
All MQL5 programs work in threads other than the main thread of the application. The main application thread is responsible for handling all Windows system messages and, in its turn, generates Windows messages for its own application as a result of this handling. For example, moving the mouse on a chart (WM_MOUSE_MOVE event) generates several system messages for subsequent rendering of the application window, and also sends internal messages to experts and indicators launched on the chart. A situation may occur, where the main application thread has not yet processed the WM_PAINT system message (and therefore has not yet rendered the modified chart), while an EA or an indicator has already received the mouse movement event. In this case, the chart property CHART_FIRST_VISIBLE_BAR will be changed only after the chart is rendered.
For each event type, the inputs of the OnChartEvent() function have certain values necessary for handling that event. The table lists events and values passed via the parameters.
Event |
'id' parameter value |
'lparam' parameter value |
'dparam' parameter value |
'sparam' parameter value |
---|---|---|---|---|
Keystroke event |
CHARTEVENT_KEYDOWN |
pressed button code |
The number of keypresses generated while the key was held in the pressed state |
String value of the bit mask, which describes the status of the keyboard keys |
Mouse events (if CHART_EVENT_MOUSE_MOVE=true for a chart) |
CHARTEVENT_MOUSE_MOVE |
X coordinate |
Y coordinate |
String value of the bit mask, which describes the status of the mouse keys |
Mouse wheel event (if CHART_EVENT_MOUSE_WHEEL=true for the chart) |
CHARTEVENT_MOUSE_WHEEL |
Flags of states of keys and mouse buttons, X and Y coordinates of the cursor. See the description in the example |
The Delta value of the mouse wheel scroll |
— |
Creating a graphical object (if CHART_EVENT_OBJECT_CREATE=true for a chart) |
CHARTEVENT_OBJECT_CREATE |
— |
— |
Name of a created graphical object |
Changing object properties via the properties dialog |
CHARTEVENT_OBJECT_CHANGE |
— |
— |
Name of a changed graphical object |
Removing a graphical object (if CHART_EVENT_OBJECT_DELETE=true for a chart) |
CHARTEVENT_OBJECT_DELETE |
— |
— |
Name of a removed graphical object |
Mouse click on a chart |
CHARTEVENT_CLICK |
X coordinate |
Y coordinate |
— |
Mouse click on a graphical object |
CHARTEVENT_OBJECT_CLICK |
X coordinate |
Y coordinate |
Name of a graphical object the event has occurred on |
Moving a graphical object with mouse |
CHARTEVENT_OBJECT_DRAG |
— |
— |
Name of a moved graphical object |
Finishing a text editing in the "Input field" graphical object input box |
CHARTEVENT_OBJECT_ENDEDIT |
— |
— |
Name of the "Input field" graphical object, in which text editing completed |
Resizing the chart or modifying the chart properties via the properties dialog window |
CHARTEVENT_CHART_CHANGE |
— |
— |
— |
Custom event with N number |
CHARTEVENT_CUSTOM+N |
Value defined by the EventChartCustom() function |
Value defined by the EventChartCustom() function |
Value defined by the EventChartCustom() function |
Sample chart event listener:
//+------------------------------------------------------------------+
|
See also
EventChartCustom, Types of chart events, Event handling functions, Program running, Client terminal events