Trading Simulator
Trading Simulator
www.pepperstone.com
3
www.pepperstone.com
The Simulator lets you place market and pending orders, set trailing stops, alter the s/l and t/p on
orders by clicking on the chart, save complex order definitions as templates, quickly close all open
orders, plus many more features which are not available as standard in MT4.
You will need to restart any copies of MT4 which are already running. MT4’s Navigator list does not
update until the software is restarted.
4
www.pepperstone.com
• Open the MT4 strategy tester, by choosing “Strategy Tester” from the “View” menu, or by
pressing Ctrl+R.
• Choose “Trading Simulator” from the “Expert Advisor” list.
• Choose the symbol which you want to practise on from the “Symbol” list.
• Choose the chart timeframe which you want to practise on, from the “Period” list.
• Choose the date range which you want to practise on by clicking the “Use date” box and then
choosing the start and end dates.
• Turn on the “Visual mode” setting.
• Click on the “Start” button.
You can also control the size of the simulated account which you are trading by clicking on the
“Expert properties” button and changing the “Initial deposit” value on the “Testing” tab.
Once you click on “Start”, MT4 will collect the historic data for your chosen dates, and then load the
Trading Simulator.
The simulation will then pause so that you can add indicators to the chart before continuing.
5
www.pepperstone.com
When you are ready you can start the simulation using the button in the MT4 strategy tester or the
equivalent button in the Simulator itself.
For any problems in running the Simulator, please see the troubleshooting notes below.
The effect of the slider depends on how powerful your computer is, how many indicators you add to
the Simulator, how many ticks there are in each simulated bar, whether you are creating extra offline
charts etc. As a general rule:
You can experiment with the slider to find the best combination for your computer and how quickly
you want the simulation to run.
You can also control the speed of the simulation further using the EA’s SpeedFactor property. You set
this by clicking on the “Expert properties” button in the strategy tester and then altering the “Value”
property on the “Inputs” tab.
The SpeedFactor parameter slows down the simulation; the larger the value, the slower the
simulation. For example, you can create a simulation-speed between values 31 and 32 on the MT4
slider by setting the slider to 32 and then adjusting SpeedFactor to a non-zero value.
6
www.pepperstone.com
• No pausing.
• Pause when s/l or t/p is hit. The simulation will pause each time that a trade is closed at its
s/l or t/p.
• Pause after all trade closes. The simulation will pause each time that a trade closes for any
reason, including trades which you close manually. This option will also pause if a pending
order expires without being filled.
• Pause at the start of each bar. The simulation will pause at the start of each and every new
bar. (With this option, you may want to set the strategy tester to its maximum speed. You
then decide at the start of each bar whether to place a trade, and resume the simulation as a
way of skipping to the start of the next bar.)
• Pause at the start of each bar, and also at each trade close. This is a combination of the two
options above: the simulation pauses at the start of each bar, and also at any trade-closes in
the middle of bars.
MT4 will show dotted horizontal lines for each order and also draw markers showing where orders
were opened and closed. The status indicator at the top of the Simulator will show your current net
position, e.g. +0.10 if you are long 0.1 lots, or -0.10 if you are short 0.1 lots.
You can control the lot size on new orders, and set a stop-loss, take-profit, or trailing-stop using the
fields above the buy and sell buttons.
You can also open calculators for each of these fields by holding down the Ctrl key while clicking on
them. For example, if you are trading 0.25 lots, and you want a stop-loss which is equivalent to $100,
then you can Ctrl+click on the S/L field and tell the calculator to work out the number of pips which is
equivalent to a fixed cash risk of $100.
7
www.pepperstone.com
The entry price for pending orders can be defined either as a fixed price (e.g. 1.23456) or as a number
of pips. For example, if you choose a buy-limit and enter a value of 20 pips rather than a price, then
the limit order is created 20 pips below the current price.
• “OCO breakout”. You specify two prices, or two values in pips, either side of the current price,
and the Simulator places a buy-stop and a sell-stop. Once one of the pending orders is filled,
the other is automatically cancelled. You would typically use this when you are expecting a
major price movement, but you don’t know whether the move is going to be up or down. For
example, there are many trading strategies based around trading the breakout, in either
direction, of yesterday’s range.
• “OCO reversion”. In this case the Simulator places a buy-limit and sell-limit, rather than a buy-
stop and sell-stop. You would typically use this if you are expecting a move in either direction
followed by a return towards the current price – e.g. a bounce off yesterday’s high or low.
8
www.pepperstone.com
The panel shows the profitability of order for the symbol in cash terms, and also in pips. The price
underneath the profit in pips is the average entry price for the position (if there is more than one open
order).
You can use the options to close all open orders for the symbol, or all winning or losing trades, or to
hedge or reverse the open position.
You can close individual orders by opening the account info – see below.
You can click on the markers to open a pop-up window for each order, and you can use the “handle” at
the right-hand end of the marker to drag it.
9
www.pepperstone.com
4.5.1 Changing s/l, t/p and pending entry prices by dragging markers
You can change the s/l or the t/p of an order by dragging its marker, using the “handle” at the right-
hand end of the marker. You can also drag the entry price of pending orders (but you cannot move the
entry price of open positions!)
If you drag a marker to an invalid level – e.g. you drag a s/l the other side of the current market price
– then you will be asked if you want to close the order. You can cancel a drag which is in progress by
pressing the Esc key.
The current profit for the order shown in the top-right of the window can be switched between cash
and pips by clicking on it.
You can close the order using the red button, and you can change the s/l, t/p or trailing stop by
clicking on those options.
10
www.pepperstone.com
From the window which pops up, you then click on the s/l or t/p buttons and the s/l or t/p will
automatically move to the new price selected. For example, you can Ctrl+click on the high or low of a
bar to set the s/l or t/p to that price or use the cross hairs or mouse cursor to select a new price.
This shows your total net profit in the simulation so far, your current balance and equity, the profit on
all open orders, the margin usage etc.
The account info also shows a list of all pending and open orders. You can close each one of these by
clicking on the icon next to its ticket number.
5. Smart Lines
In the following example there are two converging trend-lines, one for the stop-loss and one for the
take-profit. In addition, there is a time (vertical) line which will close the open position if the price has
not already hit one of the trend lines by then.
11
www.pepperstone.com
A window such as the following will then pop up, letting you choose what action the line should take:
You can apply horizontal and trend-lines to all buy orders, or to all sell orders, or to any selection of
orders of the same type. (For example, if you have 5 open buy orders and 5 open sell orders, then you
12
www.pepperstone.com
could select any 2 buy orders or any 4 sell orders from the drop-down list, but you cannot choose a
mixture of buys and sells.)
A horizontal line or trend-line must also be either a stop-loss or a take-profit. When you create the
Smart Line, the price must be valid as your selection of stop-loss or take-profit. For example, if a line
is below the current market price then it cannot be used as a take-profit on a buy order.
Because they are not price-based, vertical lines can be applied to any selection of orders without
restriction.
Please note that the Smart Lines always round up, on the basis that it is less risky to be out of the
market than in it. For example: your order/position is 0.50 lots; the line is configured to close 25%; and
the broker’s minimum trade size is 0.10 lots. 25% of 0.50 is 0.125 lots. This will be rounded up to 0.20
rather than rounded down to 0.10.
13
www.pepperstone.com
0.50 will be closed, leaving 0.25. If the order/position is 0.10, then the entire 0.10 will be closed (and
no further action will be taken).
You can change this behaviour using the Advanced options, telling the Smart Lines to apply the rule to
each order individually.
In order to be able to keep a line, it must have the following three characteristics:
14
www.pepperstone.com
• It cannot be a vertical (time) line – for obvious reasons, this can only apply to horizontal or
trend-lines.
• It must apply to all-orders (or all buy orders etc) rather than to specific individual tickets.
• The amount to close must be 100%. It cannot be a smaller percentage or a fixed lot size.
If you do not set a line to be removed when another line is triggered then the following can happen:
• Price rises to 1.2400. 50% of the position is closed, e.g. closing 0.30 lots from a position of
0.60 lots.
• Price then falls to 1.2300. A further 50% is closed, reducing the position from 0.30 lots to 0.15
lots.
You can filter on profit, lot size, order comment, and order magic number. For example, by changing
the profit range to -9999999 to 0, you instruct the Smart Lines only to close any losing positions, and
not to touch any winning positions.
The order comment and magic number conditions can be comma-separated lists of values. For
example: 1234,2345,6789 tells the Smart Lines to close orders if their magic number is any out of
1234 or 2345 or 6789. Comment filters must match the start of the MT4 order comment, and are not
case-sensitive.
15
www.pepperstone.com
6. Multiple timeframes
You can view multiple timeframes for the Simulator using offline charts in MT4. For example: you can
set the MT4 strategy tester to do a simulation on H1 data, but also create simulated charts for M5
and D1.
The list of settings includes options such as offline_M1 and offline_D1. You simply turn on the extra
timeframes which you want. Please note that each extra timeframe will slightly reduce the Simulator’s
speed.
16
www.pepperstone.com
Once you open one of the offline charts you can add indicators to it in the usual way, and the charts
updates and pauses in line with the main simulated chart.
By default, the Simulator follows normal MT4 behaviour and lets you have buy and sell orders open at
the same time. (Please note that the MT4 strategy tester allows this even if you are using a US broker
who is prohibited from allowing hedging.) If you turn on non-hedging mode, buy orders close sell
orders, and vice versa. For example, if you are long 0.10 lots and place a sell order for 0.30 lots, then
the buy order will be closed and a sell order will be placed for the balance of 0.20 lots.
17
www.pepperstone.com
The Simulator must have the current input focus for these shortcuts to work; the most recent mouse
click must have been inside the Simulator’s window (rather than elsewhere inside the MT4 software).
If the visual-mode option in the MT4 backtesting settings is not visible, then you simply need to
increase the size of the backtesting pane: http://forum.mql4.com/70724
If the Simulator starts, but continues to display a blank white window even after waiting for a few
seconds, then please check your settings for Internet Explorer (regardless of which browser you
normally use for your web browsing). Something in the Windows settings for Internet Explorer is
preventing it from displaying and running web content.
If the backtesting/simulation is terminated immediately after you place the first trade, please look for
errors in the Journal tab of the strategy tester.
The only known cause of this problem is the message from MT4 saying "margin exchange rate
cannot be calculated", as a result of the deposit currency for the strategy tester being different to the
deposit currency of your account.
Please check that the deposit currency which is being used in the strategy tester is correct, using the
“Expert properties” button in the MT4 strategy tester pane. For another example and more information
about this problem in the MT4 strategy tester, please see http://forum.mql4.com/34736
• http://forum.mql4.com/14612
• http://forum.mql4.com/35627
• http://articles.mql4.com/83
• http://articles.mql4.com/70
19
www.pepperstone.com
• If an EA uses MQ4 functions such as iClose(), iHigh(), iCustom() etc in backtesting for a
timeframe which is different to the chart timeframe (e.g. the H1 values when running on a
M15 chart), then this is safe. The values which the EA sees are based on the latest simulated
price, not any future prices.
• But if an indicator is added manually to a visual-mode backtest, then use of iClose(), iHigh(),
iCustom() etc for a higher timeframe will see the bar-end values rather than the interim
simulated values. In other words, if an indicator is manually added to the chart, and collects
prices from a higher timeframe than its chart, then it “breaks out” of the backtesting
environment and can see what happens in the future.
20
www.pepperstone.com
Level 16, Tower One Local Call 1300 033 375 www.pepperstone.com
727 Collins Street Phone +61 3 9020 0155 [email protected]
Melbourne VIC 3008 Fax +61 3 8679 4408
AUSTRALIA
21