MT4 trading programming

Pat494

Legendary member
Messages
14,614
Likes
1,588
This is a plea to someone who has some skills at programming and would like to teach some duffers like me the MT4 language.

Please come forward otherwise I will have to have a go.

Anyone .............................?????
 
Would if I could...for what it's worth, easylanguage has been exceptionally easy to learn for me. I feel I can pretty much do what I want with it now and have only been messing with it for about a month. I certainly have much more to learn with it and the code I write can probably be cleaner due to this, but getting it to do what you want is most of the battle. Well...do what I want short of finding something that works strategy wise, but that is my own issue.

Probably the most useful thing I have found learning it is having a booklet of the valid programming terms that defines what the function does and gives typical usage. When I am trying to do something I can just do a search in it and read through the pages that come up. I would imagine there is something like that for the MT4 language as well. Good luck! After the first few weeks of slow going and excessive googling it gets much faster and easier!
 
Well good luck with your programming journey. Easy Language is a different system but..................There are lots of programmes out there and for sale for MT4 but on testing most of them come up short and make losses. So, I suppose it is a do it yourself situation because if anyone has a profitable system they are likely to keep it to themselves.
 
Pat,
If you know what you want, you could pay someone who has the necessary coding skills to do it for you. Yes, there's the cost, but you'll cut to the chase in double quick time and save yourself hours and hours of learning to do something that might end up being a waste of your time. I say this as you strike me as being someone who doesn't have a strong IT background and writing code isn't something you'll take to like a duck to water. If I'm wrong about that - apologies!
Tim.
 
Pat,
If you know what you want, you could pay someone who has the necessary coding skills to do it for you. Yes, there's the cost, but you'll cut to the chase in double quick time and save yourself hours and hours of learning to do something that might end up being a waste of your time. I say this as you strike me as being someone who doesn't have a strong IT background and writing code isn't something you'll take to like a duck to water. If I'm wrong about that - apologies!
Tim.

Quite right about the coding Tim and a good point about paying someone to code up one's ideas. There is however a BUT to the problem, And that is I have looked at EAs that use Macd, Stochastics, CCI etc. indicators and not come up with a profitable system except Martingale and that is only temporary before the inevitable crash. So I do not have a winning system in mind for someone to code up.
Should I give up ? I don't think so, not yet. I was really hoping someone would step forward bravely and guide us to the " promised land ". This not being so I do have a plan B.
 
. . . So I do not have a winning system in mind for someone to code up.
Should I give up ? I don't think so, not yet. I was really hoping someone would step forward bravely and guide us to the " promised land ". This not being so I do have a plan B.
Aha, the plot thickens!

If by the promised land you mean someone who can help / guide / teach you to write MT4 code, then I'm sure there are plenty of people out there with the requisite skills who could assist you. However, if you mean someone who can help / guide / teach you to write consistently profitable MT4 code - then I fear your search will be in vein. The usual reasons apply. Anyone in this position is unlikely to pass on their rare and hard won code for others to use out of the goodness of their heart. If they're charging for it, then one must question its reliability and effectiveness in the first place.

So, for me, the bottom line would be to start with an idea that I want coded up. From there, I'd make the decision either to learn to do it myself or - most likely - pay someone else to do it for me. At the end of the day, I think the initial trading idea is going to have to come from you. I suppose the only other option is to take someone else's discretionary approach and attempt to code it up - just as Dr. Toad is attempting to do with Mr. Charts' rising/falling candles strategy.
Tim.
 
So, for me, the bottom line would be to start with an idea that I want coded up. From there, I'd make the decision either to learn to do it myself or - most likely - pay someone else to do it for me.

I probably do not have enough experience doing this yet (trading or coding) to comment but I figure I will weigh in anyways. I do not think it is possible to design a profitable system by coming up with an idea and paying someone to code it. I really think that you have to do the coding yourself if you are ever going to get something that works. The reason I say this is that it is very difficult to plan for every possibility at the outset and you won't discover what you have overlooked until you code and test your idea.

Inevitably, the results of your test will produce some unexpected results...some good, but mostly bad. You then have to figure out why the unexpected results occurred and how to eliminate (or amplify) them. It is a process that is waaaaay too iterative to do a one off code this idea and done. If you have a programmer on retainer that is another story...but if someone could afford that they wouldn't be messing with this in the first place!
 
Well no one has stepped up to the proverbial so here is plan B.
I will do a page a week about MT4 and learn something along with the rest of you.

---------------------------------------------------------------------------------------------------

Scrolling the chart
Hold down the left mouse button and drag the mouse in the main chart area, to scroll left/right.
Or you can also simply roll the mousewheel down/up, or use the left/right arrow keys, to likewise scroll the chart view left/right.
To scroll a whole screen at a time, use Page Up (scroll left) and Page Down (scroll right).
To reposition to the leftmost bar on the chart, press Home.To reposition to the most recent (rightmost) bar, press End.
To step forward one bar at a time, press F12.
To step backward one bar at a time, press Shift-F12.
Scrolling a chart beyond the leftmost bar will add historical bars to the beginning of the chart, until no more are available from MT4's historical database.

Moving directly to a certain date/time
To re-position immediately to a certain date, press Enter, then type in the date in the form DD.MM.YY and press Enter again. Leading zeros can be omitted (e.g. to move to 4 July 2005, type 4.7.5). To re-position to a certain date/time, use the format HH:MM or DD.MM.YY HH:MM (e.g. to position to 8:07am TODAY on a 1-min chart, simply type 8:7).
 
Vertical zoom and re-scale
You can re-scale the chart vertically by moving the mouse into the vertical axis area at the right of the screen, and then dragging downwards (with the left button held down) to compress the chart bars, or dragging upwards to expand them.
Double click to reset the chart to its original scale.

Horizontal zoom and re-scale
Similarly, you can adjust the width of the price bars by moving the mouse into the horizontal axis area at the bottom of the screen, and then dragging right (zoom in) or left (zoom out). Or simply use the "+" and "–" keys to achieve this.


Indicators
Double-click on or near indicators with the left mouse button, to call their parameter setup windows.
Right-click to call the indicator's context menu.

If the screen is cluttered with overlapping indicators and/or objects, making it too difficult to select the desired indicator, press Ctrl-I to call up the Indicators dialog window. Double click (or click the Edit button, or Alt-E) on the indicator to edit its properties (parameters, colors, etc), or click the Delete button (or Alt-D) to remove it from the chart.
You can use the Home, End and Page/arrow Up/Down keys to navigate up/down the list.


Objects
Double-click on or near an object (line studies, texts, arrows, geometric shapes) to select the object. Once selected, you can move an object by left clicking on it (or in the case of or trendline or shape, it's centre handle) and dragging it to the desired destination. Shapes, trendlines, channels etc may be extended by dragging the handles on the relevant edges. The number "X/Y" appears, where "X" = the width of the shape in candles, and "Y" = the height of the shape in pips.
Right-click on a selected object to open its context menu.

If the screen is cluttered with overlapping indicators and/or objects, making it too difficult to select the desired object(s), press Ctrl-B to call up the Objects dialog window. Left click the check boxes on/off to select/deselect relevant object(s). Double click (or click the Edit button, or Alt-E) on an object to edit its properties (parameters, colours, etc), or click the Delete button (or Alt-D) to remove it from the chart. To quickly delete a whole block of objects, repeatedly press Alt-D or hold it down (careful, they disappear rather quickly!)
You can use the Home, End and Page/arrow Up/Down keys to navigate up/down the list.
Click on the 'Name' or 'Description' heading area to sort by name, or description, respectively.
Left-click to select an item. You can use Ctrl-click to add individual items to a selection, Shift-click to add a group of consecutive items, or press Ctrl-A to select all items. Then click the Edit button (or press Alt-E) to edit all items in the group consecutively, or the Delete button (or press Alt-D) to delete all selected items simultaneously (careful!).

Alternatively, from the chart window, press Backspace repeatedly to delete the most recently added object(s) on a last-added-first-removed basis (useful if you want to quickly check out a Fibo or regression channel, then remove it). Then press Ctrl-Z to undo any accidental deletes, in reverse order.
Or press the Delete key to remove ALL SELECTED objects.
 
Parallel Trendlines
Ctrl + left click on a selected trend line to draw a parallel trend line (create a channel). Can also be used with vertical and horizontal lines.

Duplicating objects
The 'Parallel Trendlines' concept extends to ALL objects (vertical, horizontal and trend lines; shapes - triangle, square, ellipse; text and labels; arrows and symbols; and studies like channels, Fibo, Gann, Pitchfork, etc). Here's how to duplicate any object:

-- Select the object by clicking on it**
-- While holding down the Ctrl key: move the mouse over any one of the object's handles, and, holding down the left button drag the mouse to where you want the duplicated object to be located

This shortcut also duplicates all of the proprties of the parent object, e.g. if you have red, green and blue objects, and you want to create a green one, simply duplicate it. This is quicker than creating a new object, and then changing its color to green.

** Object selection options
Press Ctrl-O and then select the 'Objects' tab.

-- "Select object by single mouse click" - if checked OFF, you must double click to select an object, and right click to modify its properties. If checked ON, single click to select an object, and double click to modify its properties.

-- "Select object after creation" - if checked ON, any object is automatically selected immediately after you create it.

-- "Show properties after creation" - if checked ON, the property modification window for the object is displayed, immediately after you create the object.

--------------------------------------------------------------------------------------------------------------------------------------------

I just tried it. Doesn't seem to work on my MT4 edition ?
 
Last edited:
Press Ctrl-B to display the objects list. Click on the checkbox (at left) for each object you want selected.

Information Bubble
Hover the mouse cursor on or over an element, object or indicator to see the prompt (help information bubble).

Crosshair mode, and ruler tool
Click the mousewheel to switch cursor to the "crosshair" mode.
This can also be achieved by pressing Ctrl-F, or selecting the crosshair icon from the toolbar. The crosshairs also display vertical (price) and horizontal (date/time) co-ordinates at the right and bottom of the chart.
Simply left-click to exit crosshair mode.

Now, here is something extremely useful that I haven’t found in the on-line help:
While in crosshair mode, hold down the left mouse button and drag the mouse to obtain a ruler-type tool that measures vertical (number of pips) and horizontal (number of bars) from the centre of the crosshairs. The tool displays counters in the form "A/B/C" where A is the number of bars right or left of the crosshair, B is the number of pips from crosshair to cursor, and C is the price at the cursor.

I find "B" extremely useful for measuring the number of pips between any two points, thus:
1) move the mouse to the point you want to measure from (the "anchor" point);
2) click the mousewheel to enter crosshair mode;
3) then hold down the left button and move the mouse to any number of destination points, to see the number of pips between the anchor point and the current mouse destination.
This saves having to calculate this distance manually, as the difference between two prices. Pretty cool!
You can also use this facility to count price bars (reading "A") between any two dates/times.


Reference and anchor points
'Fixed chart position' arrow: At the lower left of the chart there is a dark coloured** arrow. Dragging it with the mouse sets the reference (anchor) point for the chart. Now when you zoom in or out, or even change the timeframe, this point remains anchored at its existing location.

'Chart shift' arrow: At the upper right of the chart there is likewise a dark coloured** arrow. Drag it left or right with the mouse to set the location for the last (most current) bar on the chart (i.e. set the amount of empty "whitespace" at the right of the chart).
 
[** the color is actually set to the same color as the Grid color (press F8 to change the Grid color in the chart Properties window). Hence if the arrows are difficult to see, change the Grid color to a color that contrasts better with the chart background.]


Removing all indicators and objects from your chart
Load a blank chart (the pair/timeframe doesn't matter), then change the settings (press F8) to set colors, grid, etc to suit your preference. Then save this as a template named (for example) Z. (menu option: Charts > Template > Save Template……)
Then, whenever you want to instantly remove all indicators and objects from your chart, simply load template Z, by quickly using the hotkey combination: Alt-C T Z


The 'Grid' and 'Volumes' color selections (obtained by pressing F8 to summon the chart Properties window) each serve dual purposes. The Grid color doubles both as the color for the chart grid (press Ctrl-G to toggle the grid on/off), but also the color for the horizontal Bid price line. Hence if you don't want the Bid price line cluttering your chart (e.g. it's easily confused as another S/R line), and you never use the grid facility, then set the Grid color to 'None', and the Bid price line disappears. I use the Bid/Ask line indicator that I've attached to this post, instead. You can of course turn the Ask line off either by setting the 'Ask line' color to 'None', or by unchecking 'Show Ask line' on the Common tab.

The 'Volume' color selection doubles both as the color for volume bars (press Ctrl-L to toggle these on/off) and also as the color for the order entry level lines. Hence if you don't want these lines cluttering your chart, and you don't use the Volume facility, then set the 'Volume' color to 'None', and the order entry level lines will disappear. Of course you can suppress the displaying of SL and TP level lines by changing the 'Stop Levels' color to 'None'.


List of hotkeys

There are many other useful hotkeys. Here is a comprehensive list:

Left arrow — scroll chart to the left;
Right arrow — scroll chart to the right;
Up arrow — quickly scroll chart to the left or (if the scale is defined), scroll chart upwards;
Down arrow — quickly scroll chart to the right or (if the scale is defined), scroll chart downwards;

Numpad 5 — restores chart vertical scale to its original default. If the scale was defined, this returns the chart back to its visible range;

Page Up — scroll a whole screen to the left;
Page Down — scroll a whole screen to the left;
Home — move the chart to the start point (first bar);
End — move the chart to the end point (last, i.e. most current) bar;

"–" — zoom out (there are 6 levels of zoom available);
"+" — zoom in;

Delete — delete all selected objects;
Backspace — delete most recently added objects, on a last-added-first-removed basis;

Enter — open/close the fast navigation window;
Esc — close any dialog window;

F1 — open the on line help "Userguide";
F2 — open the "History Center" window;
F3 — open the "Global Variables" window;
F4 — open MetaEditor;
F5 — switch to the next profile;
F6 — call the "Tester" dialog window for testing the expert attached to the chart window;
F7 — call the properties dialog window of the expert attached to their chart window, in order to change its settings;
F8 — call the chart setup dialog window, allowing basic chart parameters, colors, etc to be changed;
F9 — call the "New Order" window, allowing the entry of market, limit, stop orders;
F10 — open the "Popup prices" window;
F11 — enable/disable full screen mode;
F12 — scroll the chart one bar to the left;

Shift+F12 — scroll the chart one bar to the right;
Shift+F5 — switch to the previous profile;

Alt+1 — display the chart as OHLC bars;
Alt+2 — display the chart as OHLC candlesticks;
Alt+3 — display the chart as a line (closing prices only);

Alt+A — copy all test/optimization results onto the clipboard;
Alt+W — call the chart management window;
Alt+F4 — exit the program;

Ctrl+A — arrange all indicator window heights by default;
Ctrl+B — call the "Objects List" dialog window;
Ctrl+C or Ctrl+Insert — copy to the clipboard;
Ctrl+D — open/close the "Data Window";
Ctrl+E — enable/disable the attached expert advisor;
Ctrl+F — switch to "Crosshair" mode;
Ctrl+G — show/hide the vertical/horizontal grid;
Ctrl+H — show/hide the OHLC line;
Ctrl+I — call the "Indicators List" dialog window;
Ctrl+L — show/hide volume data on the main chart;
Ctrl+M — open/close the "Market Watch" window;
Ctrl+N — open/close the "Navigator" window;
Ctrl+O — open the "Setup" window;
Ctrl+P — print the chart;
Ctrl+R — open/close the "Tester" window;
Ctrl+S — save the chart prices (OHLCV) in a file having extensions: "CSV", "PRN" or "HTM";
Ctrl+T — open/close the "Terminal" window;
Ctrl+W or Ctrl+F4 — close the chart window that's currently in focus;
Ctrl+Y— show/hide date (period) separators;
Ctrl+Z or Alt+Backspace — undo object deletions in the reverse order they occurred;

Ctrl+F6 — switch to the next chart window;
Ctrl+F9 — open the "Terminal — Trade" window and switch the focus into it, allowing trading operations to be entered via the keyboard.
 
Really useful thread Pat.(y)
Just wondering if a screen shot per post might help new users orientate themselves more easily to the descriptions.
 
Really useful thread Pat.(y)
Just wondering if a screen shot per post might help new users orientate themselves more easily to the descriptions.

Glad to see someone else is following. I am sorta doing it by paragraph chunks. Do you think I should do bigger chunks or more often ?
 
Glad to see someone else is following. I am sorta doing it by paragraph chunks. Do you think I should do bigger chunks or more often ?

Smaller chunks grouped into a particular subject matter.

For example:
1: if you were describing the ability of users to annotate their charts:

2: example of changing settings on indicators:
put cursor over the indicator area: double-left-click and and the indicator settings box appears:

(just an idea; you ideally need feedback from other users, but I think a visual aid helps users to quickly orient themselves to the subject in hand)
 

Attachments

  • 2016-01-03_10h40_54.png
    2016-01-03_10h40_54.png
    128.1 KB · Views: 371
  • 2016-01-03_10h41_30.png
    2016-01-03_10h41_30.png
    149.6 KB · Views: 338
Attaching indicators to indicators outside of the main price chart
You can attach moving averages and other indicators to indicators on other than the main chart. For example, if you want to use a moving average to smooth RSI, do the following:
1) Create a lower window with RSI in the normal manner.
2) Open the navigator window (press Ctrl-N).
3) Click on the "Indicators" heading in the Navigator window, if necessary, to expand it.
4) Move the mouse to the "Moving Average" item, then (holding down the left button), drag it (a rectangle appears under the arrow cursor) into the RSI window.
5) In the ensuing dialog box, got to the "Apply to" drop down, and set this to "First indicator's data". This will cause the MA to be attached to the first indicator in this window, i.e. the RSI.
6) Adjust other parameters as desired, and press Enter.

NOTE:
-- To create an indicator in a separate window, right-click on its name in the Navigator, and select "Attach to a chart".
-- To create an indicator in the same window as another, drag it's name into the relevant window.


Adding custom-defined indicators to MT4
One of the most powerful MT4 features is that it has a comprehensive but friendly programming language that allows custom-defined indicators, scripts and expert advisors to be written. Here's how to import an already written indicator into MT4's charting facility:

1) Go to a web resource that has the source code for the indicator. A good one is http://www.xeatrade.com/trading/11.html
Note the "# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" index.
So if you want to add (for example) the PPCI indicator to your charts, click on "P" to see all the custom-developed indicators starting with a "P".
Left-click on the PPCI hyperlink. The source code for PPCI appears in the middle of the screen. Left-click inside this window, then press Ctrl-A to select all of the text, then Ctrl-C to copy it.

2) Return to MT4, and press F4 to load the MetaEditor, a tool which allows to create and compile your own indicators, scripts and experts.

3) In MetaEditor, press Ctrl-N to create a new indicator using the Expert Advisor Wizard.
Select the "Custom Indicator" radio button, and click Next.
Type in the name (e.g. PCCI) that you want to use to reference your indicator in MT4, ignore the other fields, and click Next.
On the final dialog window, ignore all fields, and click Finish.

4) Now left-click in the body of the screen, press Ctrl-A to select all the text, and then press Ctrl-V to paste the text you copied back in step 1, completely overwriting the previous text.

5) Then press F5 to save and compile your indicator.

Hopefully, the message "0 error(s), 0 warning(s)" will appear, indicating a "clean compile", i.e. that the programmer wrote the source code correctly, without syntax errors. Press Esc to close the dialog box.

Presto! If you now return to MT4, the new custom indicator should automatically appear both in the Navigator, and also under the menu option "Insert > Indicators > Custom" if you prefer to add it to your chart in this manner.

You can also add scripts and experts in the same way.
In step (1), select the "MQ4 Scripts" or "MQ4 Experts" hyperlink in the left menu.
In step (3), select the appropriate radio button.

Note that these objects are stored in the following folders:
Experts: c:/program files/<mt4 broker name>/experts
Scripts: c:/program files/<mt4 broker name>/experts/scripts
Custom indicators: c:/program files/<mt4 broker name>/experts/indicators
Include (program code, e.g. .MQH) files: c:/program files/<mt4 broker name>/experts/include
Templates: c:/program files/<mt4 broker name>/templates
Data files: c:/program files/<mt4 broker name>/experts/files

NOTE: As an alternative to the above, if you simply copy the .MQ4 file into the relevant folder, and then (exit and) re-start MT4, the expert, script or indicator will automatically be recompiled, and appear in the Navigator.
 
Top