MQL4/MT5 Hotkeys: Keyboard Shortcuts for Experts and Indicators

MQL4/MT5 Hotkeys: Keyboard Shortcuts for Experts and Indicators
Download ALL MT4 experts (896)
YouTube Video Thumbnail



Similar MetaTrader Tools

MQL4/MT5 Hotkeys: Keyboard Shortcuts for Experts and Indicators

Info

The MQL4/MT5 Hotkeys: Keyboard Shortcuts for Experts and Indicators is a Expert Advisor for MetaTrader 4 that hotkeys provides keyboard shortcuts for your mql4 experts and indicators through a single include file with no external dependencies. The user defines each shortcut in the inputs, such as "Shift+B" or "Ctrl+Shift+1".

Usage

This tool is typically used for automated trading on major forex pairs and gold.

Platform

This Expert Advisor works exclusively on MetaTrader 4 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL4/Experts folder via File ? Open Data Folder in MetaTrader 4.


How to Install and Use MQL4/MT5 Hotkeys: Keyboard Shortcuts for Experts and Indicators

1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.

2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.

3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.

4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.

Frequently Asked Questions

Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.

Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.

Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.

What this tool does

Hotkeys provides keyboard shortcuts for your MQL4 experts and indicators through a single include file with no external dependencies.

Typical Use Case

This Expert Advisor excels in automated trading and technical analysis on MetaTrader 4.

Compatible Platform & Setup

This Expert Advisor works on MetaTrader 4. Place the file in the MQL4/Experts folder and restart the terminal.

Description & Settings

Related: Expert Advisor: Karacatica - another powerful expert for MetaTrader 4 traders.

Hotkeys provides keyboard shortcuts for your MQL4 experts and indicators through a single include file with no external dependencies.

Also recommended: lucky: a profitable trading strategy - similar expert with strong performance on MetaTrader 4.

The user defines each shortcut in the inputs, such as "Shift+B" or "Ctrl+Shift+1". Your OnChartEvent function will receive the pressed action, ready for processing.

Invalid shortcuts are detected at program startup, preventing user frustration. Reasons for refusal include:
- A key already assigned to another action.
- A Ctrl shortcut reserved by the terminal.
- Alt key combinations, which the terminal does not report.

This ensures users are informed of any issues immediately, rather than discovering a non-functional key later.

Features

User-defined shortcuts: Users can input shortcuts like "Shift+B", "ctrl + shift + 1", or simply "B" using any case or spacing. An empty input or "none" disables the shortcut.

Exact modifier matching: "Shift+B" will only trigger on the exact "Shift+B" combination, not on a plain "B" or "Ctrl+Shift+B". This prevents accidental actions by users typing on the chart.

Single press, single action: Key presses identified as auto-repeats from a held key are ignored. This stops an action from triggering repeatedly while a key is held down.

Unique actions per key: Assigning a shortcut that is already in use by another action is refused. The existing binding remains unchanged.

Clear refusal reasons: Every error message clearly states the problem and suggests a valid alternative, including the action's name for easy user reference.

Available keys: Letters A-Z and digits 0-9 can be bound individually, with Shift, or with Ctrl+Shift. Function keys (F1-F12), Esc, arrow keys, and plain Ctrl shortcuts are reserved by the terminal and cannot be used.

Up to 64 actions: An action can be any integer value, allowing compatibility with your custom enums.

Enable/Disable functionality: Use SetEnabled(false) to disable all shortcuts, for instance, when a text box in your panel has keyboard focus.

Error handling: All functions that can fail return either HOTKEYS_OK or a HOTKEYS_ERROR_* code along with a descriptive reason. The library does not produce any output on its own.

Example

enum ENUM_ACTION { ACTION_BUY, ACTION_SELL, ACTION_CLOSE_ALL };

input string InpBuyKey = "Shift+B"; // Buy
input string InpSellKey = "Shift+S"; // Sell
input string InpCloseKey = "Ctrl+Shift+X"; // Close all

CHotkeys keys;

int OnInit() {
string error;
if(keys.Bind(ACTION_BUY, "Buy", InpBuyKey, error) != HOTKEYS_OK ||
keys.Bind(ACTION_SELL, "Sell", InpSellKey, error) != HOTKEYS_OK ||
keys.Bind(ACTION_CLOSE_ALL, "Close all", InpCloseKey, error) != HOTKEYS_OK) {
Alert(error); // e.g. Sell: Shift+B is already bound to Buy
return INIT_PARAMETERS_INCORRECT;
}
return INIT_SUCCEEDED;
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
switch(keys.ChartEvent(id, lparam, dparam, sparam)) {
case ACTION_BUY:
// open a buy
break;
case ACTION_SELL:
// open a sell
break;
case ACTION_CLOSE_ALL:
// close the open orders
break;
}
}

The included HotkeysExample expert demonstrates binding four shortcuts from its inputs: Shift+H draws a horizontal line at the bid, Shift+D deletes those lines, Shift+G shows or hides the grid, and Shift+Q prints the quote. It does not place orders. Upon startup, it lists its bindings and provides reasons for five example shortcuts that could not be configured:

bound action=Line key=Shift+H
bound action=Clear key=Shift+D
bound action=Grid key=Shift+G
bound action=Quote key=Shift+Q
refused text=Shift+B reason="Sell: Shift+B is already bound to Buy"
refused text=Ctrl+B reason="Sell: Ctrl+B is a terminal shortcut, use Ctrl+Shift+B or Shift+B"
refused text=Alt+B reason="Sell: Alt is not available, the terminal reports only Shift and Ctrl"
refused text=F5 reason="Sell: F5 is a terminal key, use A to Z or 0 to 9"
refused text=Shift+Shift+S reason="Sell: "Shift+Shift+S" names a modifier twice"

The accompanying image shows a live run on a MetaTrader 4 demo account, illustrating the shortcuts being pressed on the chart.

API

Call
What it does

Bind(action, name, chord, error)
Bind an action to a text-based shortcut, or update its shortcut. Use "" or "none" to unbind.

BindKey(action, name, key, modifiers, error)
Similar to Bind, but uses a key code and HOTKEYS_SHIFT/HOTKEYS_CTRL flags.

ChartEvent(id, lparam, dparam, sparam)
Call this from OnChartEvent. Returns the pressed action ID or HOTKEYS_NO_ACTION.

Match(key, repeats, flags, modifiers)
Perform the same checks as ChartEvent with provided modifiers, useful for custom tests.

Unbind(action), Clear()
Remove a specific action's binding or clear all bindings.

SetEnabled(enabled), IsEnabled()
Enable or disable all shortcuts globally.

Count(), Action(i), Name(i), Key(i), Modifiers(i), Label(i)
Retrieve information about current bindings, useful for displaying a list.

LabelOf(action), NameOf(action)
Get the text representation of a shortcut (e.g., "Ctrl+Shift+X") or the name of an action.

HotkeyParse(text, key, modifiers, error), HotkeyLabel(key, modifiers), HotkeyCheck(key, modifiers, error)
Parse, generate a label for, or validate a single shortcut combination.

The CHotkeys class is value-type and can be safely copied using assignment.

You may also like: Time Trader Expert Advisor - excellent alternative for expert users on MetaTrader 4.

Source Code

#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.0"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#property strict
#include <Hotkeys\Hotkeys.mqh>
#define EXAMPLE_PREFIX "HotkeysExample_"
#define EXAMPLE_LINE_COLOR clrDodgerBlue
enum ENUM_EXAMPLE_ACTION
  {

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.