Hotkeys gives your MQL5 expert or indicator keyboard shortcuts. It is one include file with no other dependencies. The user sets each shortcut as text in the inputs, such as Shift+B or Ctrl+Shift+1, and your OnChartEvent gets back the action that was pressed, ready for a switch.
A shortcut that cannot work is refused when the program starts, with the reason: a key another action already uses, a Ctrl shortcut the terminal keeps for itself, or Alt, which the terminal never reports. The user finds out at start instead of pressing a key that does nothing.
#include <Hotkeys\Hotkeys.mqh>
#include <Hotkeys\Hotkeys.mqh> 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 positions break; } }
The attached HotkeysExample expert binds 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 places no orders. At start it prints its bindings and the reasons Hotkeys gives for five shortcuts that cannot work:
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 picture is a real run on a demo account, with each shortcut pressed on the chart.
| Call | What it does |
|---|---|
| Bind(action, name, chord, error) | Bind an action to a shortcut written as text, or replace its shortcut; "" or "none" leaves it with no key |
| BindKey(action, name, key, modifiers, error) | The same with a key code and the HOTKEYS_SHIFT and HOTKEYS_CTRL bits |
| ChartEvent(id, lparam, dparam, sparam) | Call from OnChartEvent; returns the action pressed or HOTKEYS_NO_ACTION |
| Match(key, repeats, flags, modifiers) | The same check with the modifiers given, for your own tests |
| Unbind(action), Clear() | Remove one action or all of them |
| SetEnabled(enabled), IsEnabled() | Turn every shortcut off or on |
| Count(), Action(i), Name(i), Key(i), Modifiers(i), Label(i) | Read the bindings, for example to list them on a panel |
| LabelOf(action), NameOf(action) | The shortcut ("Ctrl+Shift+X") and name of one action |
| HotkeyParse(text, key, modifiers, error), HotkeyLabel(key, modifiers), HotkeyCheck(key, modifiers, error) | Read, write or check a single shortcut |
CHotkeys owns no pointers, so it can be copied by assignment.
Daily loss and max loss guard - prop firm rules in one include
Watches the equity like a prop firm does: daily loss limit and max loss limit, static or trailing, floating profit included. Stops new trades at a warning level, closes everything on a breach and remembers it after a restart.
Return-to-Mean Clock: How Many Bars Does Price Take to Come Back to the Moving Average
Measures how long price takes to come back to its moving average. The histogram shows the distance of the close from an EMA in ATR. Every time that distance first reaches a stretch level (1, 2 and 3 ATR by default), the indicator follows the stretch until the close is back at the average, runs further, or the wait is over. A panel shows, for each level, how often price came back, how often it ran further first, and the median and 80th-percentile number of bars the return took. One line can be pasted into a comment to compare symbols. It is a statistics tool and gives no trade signals.
Inside Bar Engulfing Scanner
Engulfing and inside bar scanner for Gold (XAUUSD) and any symbol on MT5. Marks bullish and bearish engulfing candles and inside bars on closed bars, draws the mother bar range as a box and can alert on each pattern. Arrow buffers for iCustom. Open source code.
Multi Timeframe Trend Dashboard
Multi timeframe trend dashboard for Gold (XAUUSD) and any symbol on MT5. Shows up, down or flat for up to 6 timeframes from a fast and slow EMA on the last closed bar, with the distance in points and an alert when all line up. Open source code.