mt4/mt5 shortcuts extensions
Info
The mt4/mt5 shortcuts extensions is a Script for MetaTrader 4 that this script provides various keyboard shortcuts to enhance your trading experience on mt4 and other platforms. it utilizes idlelib.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Script works exclusively on MetaTrader 4 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL4/Scripts folder via File ? Open Data Folder in MetaTrader 4.
How to Install and Use mt4/mt5 shortcuts extensions
1. Installation: Move your script file into the MQL/Scripts directory and restart the platform.
2. Execution: Drag the script onto a chart; it will perform a one-time action, such as closing all open orders or clearing chart objects.
3. Editing: Use MetaEditor (F4) to modify code, click "Compile," and verify no errors appear in the terminal before running.
4. Removing: Scripts stop automatically, but you can remove them manually by right-clicking the chart and choosing "Remove Script."
Frequently Asked Questions
Q: How are scripts different from EAs? A: Scripts execute a single action and then stop; EAs monitor the market and trade continuously.
Q: Can I assign a hotkey to a script? A: Yes, right-click the script in the Navigator, select "Set Hotkey," and define your preferred keyboard shortcut.
Q: Why did my script stop? A: Scripts are designed to stop immediately after finishing their programmed command; this is normal behavior.
What this tool does
this script provides various keyboard shortcuts to enhance your trading experience on mt4 and other platforms.
Typical Use Case
This Script excels in automated trading and technical analysis on MetaTrader 4.
Compatible Platform & Setup
This Script works on MetaTrader 4. Place the file in the MQL4/Scripts folder and restart the terminal.
Description & Settings
Related: investing.com news calendar for mt4/mt5 - another powerful script for MetaTrader 4 traders.
this script provides various keyboard shortcuts to enhance your trading experience on mt4 and other platforms. it utilizes idlelib.dll, available in the libraries section of the codebase.Also recommended: Angulation Indicator for MT4/MT5 - similar script with strong performance on MetaTrader 4.
key features include:
- changing the size of trend lines, horizontal lines, and vertical lines.
- excluding specific objects from processing.
- displaying market information.
- drawing expansion objects from a designated line (_exp).
- reversing the direction of the _exp line if drawn incorrectly.
- quickly deleting lines of a particular type.
- measuring distances (swing) with a simple line (_lp).
- providing an in-script help feature.
- exiting the script with the 'x' key.
- changing and cycling through line colors.
- shortcut for screenshot saving.
customizable keys:
- 1-5: change trendline size.
- d: delete all line types.
- t: change object type (trendlines, vertical lines, horizontal lines).
- e: draw a fibo expansion object from the _exp line.
- w: convert the expansion object back to a line.
- o: delete all objects.
- s: work on selected/deselected objects (identified by the prefix '_').
- ?: print help.
- p: measure distance of the _lp line for target and stop-loss calculations.
- s: save a screenshot.
to ensure optimal functionality, place the dll file in the experts\libraries directory and the mq4 file in the experts\script directory. mt4's lack of a function to identify objects by code requires a workaround using two types of line names: those with and without an underscore prefix. remember to exit the script with the 'x' key when finished.
for further insights, feel free to explore the script's capabilities. you can also connect with the author on twitter @emiliostefano or facebook as emilio reale, and engage with the community through voting, commenting, and sharing improvements.
You may also like: Camel Modify Script for MT4/MT5 - excellent alternative for script users on MetaTrader 4.
Source Code
#property copyright "robotfx"
#import "idlelib.dll"
int getlastkeywp();
int getlastmousewp();
int idlelibinit();
int idlelibuninit();
string getactivewndname();
#import
#include <stdlib.mqh>
extern color default_color = blue;
extern string droppedlinename = "linedropped";
extern string expansionlinename = "_exp";
extern string linepointsname = "_lp";
extern bool deletelinepoints = true;
extern bool exitafterlinepoints = true;
extern string exclusionprefix = "_";
extern bool deleteexpansionline = true;
extern bool exitafterexpansion = true;
extern bool clearcommentsonexit = true;
extern color expansionlevelcolor = blue;
extern color expansioncolor = red;
extern int expansionlevelstyle = style_dot;
extern int expansionlinewidth = 2;
extern int expansionlinestyle = style_solid;
extern color expansionlinecolor = red;
double explevels[];
string expdescriptions[];
int objecttypes[];
string objecttypedescriptions[];
int objecttype = obj_trend;
bool keydown = false;
int _lastkey = 0;
int current_color_index = 0;
int sleep = 100;
int colors[];
bool selected = false;
bool color_mode = false;
string s_color = "";
bool label_mode = false;
string s_label = "";
color getcolor(int inc) {
int s = arraysize(colors) - 1;
if (current_color_index + inc > s ) current_color_index = 0;
else if (current_color_index + inc < 0) current_color_index = s;
else current_color_index += inc;
return (colors[current_color_index]);
}
int nextobjecttype () {
int size = arraysize(objecttypes);
for (int i = 0; i < size; i++) {
if (objecttypes[i] == objecttype) {
if (i + 1 == size) { objecttype = objecttypes[0]; break;}
else { objecttype = objecttypes[i+1]; break; }
}
}
return(objecttype);
}
string objecttypedescription() {
int size = arraysize(objecttypes);
for (int i = 0; i < size; i++) {
if (objecttype == objecttypes[i]) return (objecttypedescriptions[i]);
}
return ("--- undef ---");
}
bool checkobjecttype(int type) {
return (type == objecttype);
}
void setselected() {
selected = !selected;
string s = "non selezionato";
if (selected) s = "selezionato";
comment("su oggetti: ", s);
}
void r() {
windowredraw();
}
bool isvalidobjectname(string name) {
bool r = true;
if (stringfind(name, droppedlinename) != -1 || stringfind(name, exclusionprefix) == 0 ) r = false;
if (!selected) return(r);
return (!r);
}
int init() {
comment("shortcut key trapping");
arrayresize(colors,26);
colors[0] = black;
colors[1] = darkgreen;
colors[2] = darkslategray;
colors[3] = olive;
colors[4] = teal;
colors[5] = navy;
colors[6] = purple;
colors[7] = maroon;
colors[8] = indigo;
colors[9] = midnightblue;
colors[10] = darkblue;
colors[11] = darkolivegreen;
colors[12] = saddlebrown;
colors[13] = forestgreen;
colors[14] = olivedrab;
colors[15] = seagreen;
colors[16] = darkgoldenrod;
colors[17] = darkslateblue;
colors[18] = sienna;
colors[19] = mediumblue;
colors[20] = brown;
colors[21] = darkturquoise;
colors[22] = dimgray;
colors[23] = lightseagreen;
colors[24] = darkviolet;
colors[25] = firebrick;
int lev = 9;
arrayresize(explevels, lev); arrayresize(expdescriptions, lev);
explevels[0] = -0.618; expdescriptions[0] = "sl -61.8 @%$";
explevels[1] = 0; expdescriptions[1] = "fe 0 @%$";
explevels[2] = 0.5; expdescriptions[2] = "fe 50 @%$";
explevels[3] = 1.0; expdescriptions[3] = "fe 100 @%$";
explevels[4] = 1.618; expdescriptions[4] = "fe 161.8 @%$";
explevels[5] = 2.618; expdescriptions[5] = "fe 261.8 @%$";
explevels[6] = 3.618; expdescriptions[6] = "fe 361.8 @%$";
explevels[7] = 4.618; expdescriptions[7] = "fe 461.8 @%$";
explevels[8] = 5.618; expdescriptions[8] = "fe 561.8 @%$";
arrayresize(objecttypes, 3); arrayresize(objecttypedescriptions, 3);
objecttypes[0] = obj_trend;
objecttypes[1] = obj_hline;
objecttypes[2] = obj_vline;
objecttypedescriptions[0] = "obj_trend";
objecttypedescriptions[1] = "obj_hline";
objecttypedescriptions[2] = "obj_vline";
idlelibinit();
return(0);
}
void trendlinewidth(int w) {
comment("sizing trendlines width: ", w);
for(int k=objectstotal()-1; k>=0; k--) {
string name = objectname(k);
if (checkobjecttype(objecttype(name))) {
if (isvalidobjectname(name)) objectset(name, objprop_width, w);
}
}
r();
}
void trendlinecolor(color clr) {
comment("colorizing trendlines: ");
int c = arraysize(colors);
for(int k=objectstotal()-1; k>=0; k--) {
string name = objectname(k);
if (checkobjecttype(objecttype(name))) {
if (isvalidobjectname(name)) objectset(name, objprop_color, clr);
}
}
r();
}
void trendlinecolorrot() {
comment("colorizing trendlines: ");
int c = arraysize(colors);
int n = 0;
for(int k=objectstotal()-1; k>=0; k--) {
string name = objectname(k);
if (checkobjecttype(objecttype(name))) {
if (n == c) n = 0;
if (isvalidobjectname(name)) objectset(name, objprop_color, colors[n]);
n++;
}
}
r();
}
void linedroppedstyle(int style) {
comment("cambiamento stile a line dropped: ");
int c = arraysize(colors);
int n = 0;
for(int k=objectstotal()-1; k>=0; k--) {
string name = objectname(k);
if (checkobjecttype(objecttype(name))) {
if (n == c) n = 0;
if (stringfind(name, droppedlinename) == 0) {
linestyle(name, style);
}
n++;
}
}
r();
}
void linestyle(string name, int style) {
if (checkobjecttype(objecttype(name))) {
objectset(name, objprop_style, style);
}
}
void trendlinecolordefault() {
comment("colorizing trendlines with default: ");
for(int k=objectstotal()-1; k>=0; k--) {
string name = objectname(k);
if (checkobjecttype(objecttype(name))) {
if (isvalidobjectname(name)) objectset(name, objprop_color, default_color);
}
}
r();
}
void linesblack() {
comment("colorizing trendlines with black: ");
for(int k=objectstotal()-1; k>=0; k--) {
string name = objectname(k);
if (checkobjecttype(objecttype(name))) {
if (isvalidobjectname(name)) objectset(name, objprop_color, black);
}
}
r();
}
void rotatetext() {
int lastobj = objectstotal();
string name = objectname(lastobj);
comment("text rotatation obj: ", name);
double ang = objectget(name, objprop_angle);
if (isvalidobjectname(name)) objectset(name, objprop_angle, ang+ 10);
r();
}
void deletetrendlines() {
comment("delete all trendline");
for(int k=objectstotal()-1; k>=0; k--) {
string obj_name = objectname(k);
if (checkobjecttype(objecttype(obj_name))) {
if (isvalidobjectname(obj_name)) objectdelete(obj_name);
}
}
r();
return(0);
}
void ss() {
comment("screenshot");
screenshot("screenshot.gif",1024,1078,1,1,1);
}
string s (double v) {
return (doubletostr(v, digits));
}
void linepoints() {
string line = linepointsname;
int l = objectfind(line);
if (l > -1 && objecttype(line) == obj_trend) {
double p1 = objectget(line, objprop_price1);
double p2 = objectget(line, objprop_price2);
comment("start: ", s(p1), " end: ", s(p2), " - points of line: ", s(mathabs(p1-p2)));
if (deletelinepoints) exec(objectdelete(line));
}
else
comment ("line with name : \"", line, "\" not found.");
}
void help() {
comment("elenco tasti\n====================\n\n",
"0 : colora trendlines con colore di default\n",
"1-5 : dimensione linea\n",
"d : cancella trendlines\n",
"s : seleziona / deseleziona _\n",
"b : tutte le linee di colore nero\n",
"c : colora trendlines\n",
"e : espansione su linea\n",
"h : salva screenshot\n",
"j : line dropped con stile a puntini\n",
"o : cancella tutti gli oggetti\n",
"p : numeri linea (start, end, points)\n",
"t : cambia tipo di oggetto\n",
"k : line dropped con stile solido\n",
"а : trendline con colore (-)\n",
"щ : trendline con colore (+)\n",
"u : inverte coordinate linea di espansione\n",
"w : coverte expansion in linea\n",
"e : disegna expansion \n",
"x : uscita\n\n",
"note:\n",
"quando una line inizia per _ viene ignorata negli stili altrettanto la line che inizia con linedropped\n",
"la linea di espansione si chiama: [", expansionlinename, "]"
);
}
void deleteallobjects() {
objectsdeleteall(0);
}
string d(double v) {
return (doubletostr(v, digits));
}
string key_to_char(int key) {
string char = "";
switch (key) {
case 20: char = " "; break;
case 48: char = "0"; break;
case 49: char = "1"; break;
case 50: char = "2"; break;
case 51: char = "3"; break;
case 52: char = "4"; break;
case 53: char = "5"; break;
case 54: char = "6"; break;
case 55: char = "7"; break;
case 56: char = "8"; break;
case 57: char = "9"; break;
case 65: char = "a"; break;
case 66: char = "b"; break;
case 67: char = "c"; break;
case 68: char = "d"; break;
case 69: char = "e"; break;
case 70: char = "f"; break;
case 71: char = "g"; break;
case 72: char = "h"; break;
case 73: char = "i"; break;
case 74: char = "j"; break;
case 75: char = "k"; break;
case 76: char = "l"; break;
case 77: char = "m"; break;
case 78: char = "n"; break;
case 79: char = "o"; break;
case 80: char = "p"; break;
case 81: char = "q"; break;
case 81: char = "r"; break;
case 81: char = "s"; break;
case 81: char = "t"; break;
case 81: char = "u"; break;
case 81: char = "v"; break;
case 81: char = "w"; break;
case 81: char = "x"; break;
case 81: char = "y"; break;
case 81: char = "z"; break;
default: break;
}
return (char);
}
int info() {
double t = marketinfo(symbol(), mode_tickvalue);
double p = point;
double spread = marketinfo(symbol(), mode_spread) * p;
string s = stringconcatenate("mercato: ", symbol(), "\n----------------------\n",
"mode_digits: ", digits,
"\nmode_spread: ", d(spread),
"\nmode_point: ", d(marketinfo(symbol(), mode_point)),
"\nmode_lotsize: ", marketinfo(symbol(), mode_lotsize),
"\nmode_tickvalue: ", d(t),
"\nmode_ticksize: ", d(marketinfo(symbol(), mode_ticksize)),
"\nmode_swaplong: ", marketinfo(symbol(), mode_swaplong),
"\nmode_swapshort: ", marketinfo(symbol(), mode_swapshort),
"\nmode_tradeallowed: ", marketinfo(symbol(), mode_tradeallowed),
"\nmode_minlot: ", marketinfo(symbol(), mode_minlot),
"\nmode_lotstep: ", marketinfo(symbol(), mode_lotstep),
"\nmode_maxlot: ", marketinfo(symbol(), mode_maxlot),
"\nmode_profitcalcmode: ", marketinfo(symbol(), mode_profitcalcmode),
"\nmode_margincalcmode: ", marketinfo(symbol(), mode_margincalcmode),
"\nmode_margininit: ", marketinfo(symbol(), mode_margininit)
);
comment(s);
}
void outerr(string msg, bool detailed = false) {
if (detailed) comment(msg, " [ ", errordescription(getlasterror()), " ]");
else comment (msg);
}
void exec(bool exec)
{
if (!exec) comment(errordescription(getlasterror()));
}
void expansion() {
string err = stringconcatenate("line with name : \"", expansionlinename, "\" not found.");
if (objectfind(expansionlinename) == 0) {
if (objecttype(expansionlinename) == obj_trend) {
outerr("creating expansion");
double p1 = objectget(expansionlinename, objprop_price1);
double p2 = objectget(expansionlinename, objprop_price2);
datetime t1 = objectget(expansionlinename, objprop_time1);
datetime t2 = objectget(expansionlinename, objprop_time2);
if (objectfind("expansion") > -1) objectdelete("expansion");
exec(objectcreate("expansion", obj_expansion, 0, t1, p1, t2, p2, t2, p2));
exec(objectset("expansion", objprop_color, expansioncolor));
exec(objectset("expansion", objprop_levelcolor, expansionlevelcolor));
exec(objectset("expansion", objprop_levelstyle, expansionlevelstyle));
int j = arraysize(explevels);
exec(objectset("expansion", objprop_fibolevels, j));
for (int i = 0; i < j; i++) {
exec(objectset("expansion", objprop_firstlevel + i, explevels[i]));
exec(objectsetfibodescription("expansion",i, expdescriptions[i]));
string msg = "target 100% = " + doubletostr(mathabs(p1-p2), digits);
outerr(msg);
}
if (deleteexpansionline ) exec(objectdelete(expansionlinename));
}
else outerr("line is not a trendline");
}
else outerr (err);
}
void invertcexp() {
string err = stringconcatenate("line with name : \"", expansionlinename, "\" not found.");
if (objectfind(expansionlinename) == 0) {
if (objecttype(expansionlinename) == obj_trend) {
double p1 = objectget(expansionlinename, objprop_price1);
double p2 = objectget(expansionlinename, objprop_price2);
datetime t1 = objectget(expansionlinename, objprop_time1);
datetime t2 = objectget(expansionlinename, objprop_time2);
exec(objectmove(expansionlinename, 0, t2, p2));
exec(objectmove(expansionlinename, 1, t1, p1));
}
else outerr("line is not a trendline");
}
else outerr (err);
outerr ("coordinate changed correctly");
}
void expansion2line() {
string err = ("expansion with name : expansion not found.");
string exp = "expansion";
if (objectfind(exp) == 0) {
if (objecttype(exp) == obj_expansion) {
double p1 = objectget(exp, objprop_price1);
double p2 = objectget(exp, objprop_price2);
datetime t1 = objectget(exp, objprop_time1);
datetime t2 = objectget(exp, objprop_time2);
if (objectfind(expansionlinename) > -1) exec(objectdelete(expansionlinename));
exec(objectcreate(expansionlinename, obj_trend, 0, t1, p1, t2, p2));
exec(objectset(expansionlinename, objprop_color, expansionlinecolor));
exec(objectset(expansionlinename, objprop_ray, false));
exec(objectset(expansionlinename, objprop_width, expansionlinewidth));
exec(objectset(expansionlinename, objprop_style, expansionlinestyle));
exec(objectdelete(exp));
}
else outerr("line is not an expansion");
}
else outerr (err);
outerr ("expansion converted.");
}
void label_mode_on() {
label_mode = true;
s_label = "";
outerr("label mode activated.");
}
void label_mode_off() {
if (label_mode) color_mode = false;
outerr("label mode deactivated.");
}
void color_mode_on() {
color_mode = true;
s_color = "";
outerr("color mode activated.");
}
void color_mode_off() {
if (color_mode) color_mode = false;
outerr("color mode deactivated.");
}
void applylabel(int key )
{
s_label = stringconcatenate(s_label, key_to_char(key));
string msg = stringconcatenate("label: { " , s_label, " }");
outerr(msg);
}
void changeobjecttype() {
nextobjecttype();
outerr(stringconcatenate("object type active: ", objecttypedescription()));
}
int start() {
bool needloop=true;
bool needcomments = false;
while(needloop) {
bool keyup = false;
int lastkey=getlastkeywp();
int lastmouse=getlastmousewp();
string lastwnd=getactivewndname();
refreshrates();
if (lastkey == 0) {keydown = false; keyup = false; _lastkey = 0; }
if (_lastkey == lastkey && keydown) { keyup = true; _lastkey = 0; }
else { keyup = false; keydown = true;_lastkey = lastkey; }
if (keyup) {
if ((lastkey!=0) && (lastwnd!="")) print("lastkey=",lastkey," lastwindow=",lastwnd);
if ((lastmouse!=0) && (lastwnd!="") && (lastmouse!=512)) print("lastmouse=",lastmouse," lastmousewindow= ",lastwnd);
if (color_mode) {
if (lastkey > 47 && lastkey < 58) s_color = "";
if (lastkey == 190) color_mode_off();
}
else {
if (lastkey == 48) trendlinecolordefault();
if (lastkey == 49) trendlinewidth(1);
if (lastkey == 50) trendlinewidth(2);
if (lastkey == 51) trendlinewidth(3);
if (lastkey == 52) trendlinewidth(4);
if (lastkey == 53) trendlinewidth(5);
if (lastkey == 68) deletetrendlines();
if (lastkey == 66) linesblack();
if (lastkey == 67) trendlinecolorrot();
if (lastkey == 69) {
expansion();
needcomments = true;
if (exitafterexpansion) break;
}
if (lastkey == 72) ss();
if (lastkey == 73) info();
if (lastkey == 74) linedroppedstyle(style_dot);
if (lastkey == 75) linedroppedstyle(style_solid);
if (lastkey == 77) { label_mode_on(); }
if (lastkey == 79) { deleteallobjects(); break; }
if (lastkey == 80)
{
linepoints();
if (exitafterlinepoints) {
needcomments = true;
break;
}
}
if (lastkey == 84) changeobjecttype();
if (lastkey == 85) invertcexp();
if (lastkey == 82) rotatetext();
if (lastkey == 83) setselected();
if (lastkey == 86) color_mode_on();
if (lastkey == 87) expansion2line();
if (lastkey == 88) break;
if (lastkey == 219) help();
if (lastkey == 192) trendlinecolor(getcolor(1));
if (lastkey == 222) trendlinecolor(getcolor(-1));
}
}
sleep(sleep);
}
if (clearcommentsonexit && !needcomments) comment("");
deinit();
return(0);
}
void deinit() {
idlelibuninit();
}
.......
⚠ 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.