Testing Visualization: Manual Trading

18 January 2007, 17:21
Andrey Khatimlianskii
14 317


A function of testing visualization has now appeared in the MetaTrader 4 Client Terminal. The function allows controlling of Expert Advisors' testing. But not every strategy can be programmed, not every trader can code a good Expert Advisor.

This article describes how to use visualizing function to test manual strategies that are not programmed in form of an Expert Advisor. Only basic knowledge of the terminal and no knowledge of programming are needed to trade on Manual Strategy Tester, so every trader will be able to use it.

The article mentions programs that realize 'Trade' and 'Account History' tabs during visualization. The use of these programs is described in more details in articles named Testing Visualization: Functionality Enhancement and Testing Visualization: Trade History.

If you have never worked with visualizer, you have to read the article named Testing of Expert Advisors in the MetaTrader 4 Client Terminal: An Outward Glance.

Preparation for Use

So you can use testing visualizer and would like to start testing your strategy immediately. What should be done for this?

First of all, download all necessary files from CodeBase to your PC:

  • Expert Advisor vHandsTrade.mq4 to the directory of \MetaTrader 4 Work\experts\;
  • the included file VisualTestingTools.mq4to the directory of \MetaTrader 4 Work\experts\include\; and
  • 2 indicators - vTerminal.mq4 and vHistory.mq4 - to the directory of \MetaTrader 4 Work\experts\indicators\.

Note that file VisualTestingTools.mq4 mentioned in the preceding articles has been changed, so it is the version from the above source (CodeBase) where you should download it from.

After that, open Expert Advisor vHandsTrade.mq4 in MetaEditor and compile it (use F5). Message in the "Tools" window will confirm that the EA has been successfully compiled:

Now, when the program is ready, we can start preparing the chart template. To do it, open a chart, set it up according to your taste, attach indicators vTerminal.mq4 and vHistory.mq4, and save the template as vHandsTrade.tpl:

Please keep in mind that there must be enough space in the right part of the chart to work with Tester of Manual Strategies - the controls will be placed there. So the "Chart shift" option must be enabled when creating the template:

Now we can go to the EA's setting as such.

Setting of the Expert Advisor

Every trader has his or her own trading habits. To make the use of Manual Strategy Tester most comfortable for yourself, spend about five minutes on adjusting the Expert Advisor to your preferences.

In your trading, you will open and close positions, place pending orders, move Stop Loss and Take Profit levels of positions. You will be able to choose the lot size for positions to be opened, expiration time and date for pending orders and so on. Each of adjustable characteristics corresponds with a line on the control panel:

and two lines in the Expert Advisor's code:

Their function is intuitive:
- RISK (Risk) -
% of the deposit to be used for opening a position;
- LOT (Lot) -
lot size to be used for opening a position if RISK = 0;
StopLoss value for positions to be opened, if the StopLoss line does not move when opening;
TakeProfit value for positions to be opened, if the TakeProfit line does not move when opening;
size of the TrailingStop that will follow all the positions;
pending order expiration time in hours.

You can change values of any predefined characteristic directly in the code. For example, if you usually open positions with volumes of 1.0, 2.0, 5.0, 10.0 or 50.0 lots, replace the line indicating lot size for such a line:

     double LOT[] = { 1.0, 2.0, 5.0, 10.0, 50.0 };

After you have compiled and restarted it, you will see the following:

If you want 5.0 lots to be selected by default at startup, replace "int SELECTED_LOT = 1;" with:


Now, the 3rd дще will be selected by default:

Values of any other characteristics can be changed in the same way. The rule is common: in the array, in braces, there must be 5 numbers separated by commas, value of variables SELECTED_*** must range from 1 to 5.

External Variables and Starting

Now we can start our Manual Strategy Tester. Let us open the Tester window, select the vHandsTrade in the Expert Advisors list, select a currency pair and a timeframe, and enable modelling on "Every tick" for testing to be as real as possible:

Before pressing the "Start" button, let us look at the Expert Advisor's properties window. In this way, we will complete adjusting the Expert using external variables:

Actually, the Expert has only four external variables, it inherited other ones from the included file VisualTestingTools.mq4. All variables must be set up for normal and convenient working:
- CommentsCount -
maximal amount of messages to be displayed by the Expert;
- SelectedColor -
color of the selected value of Risk, Lot, SL, TP, etc.;
- ModifyColor -
color of the order modification icon to be used for manual modification;
- TrailingColor -
color of the order modification icon to be used for TrailingStop;
- TerminalRows -
maximal amount of the 'Terminal' tab lines to be displayed. If you set TerminalRows = 0, the terminal will not be updated;
- HistoryRows -
maximal amount of the 'Account History' tab lines to be displayed. If you set HistoryRows = 0, the account history will not be updated;
- BigText -
set true if you want to enlarge the font size;
- SignalPoints -
the distance in points, starting from which the Stop Loss, Take Profit and Open Price fields for pending orders will be highlighted. For example, for SignalPoints = 10, the Stop Loss field will change its color when the price is at the 10-point distance from the Stop Loss of the position;
- ShowCancelled -
set true if you want to see cancelled orders in the trade history;
- ShowExpired -
set true if you want to see expired pending orders in the trade history;
- MainColor -
color of headlines of "Terminal" and "Account History" and of the Terminal account information line (Balance, Equity, ...).
- BuyColor -
color of information about Buy positions;
- BuyOPColor -
color of the Open Price field in the Terminal tab; this color will replace the main color when the current price approaches to the open level of Buy Stop and Buy Limit;
- BuySLColor -
in the "Terminal" tab: color, which will replace the main color when the price approaches to the Stop Loss of Buy positions; for the "Account History" tab: color, which will replace the main color if the Buy position has been closed by Stop Loss;
- BuyTPColor -
the same as for BuySLColor, but applied to the Take Profit of positions;
- SellOPColor, SellSLColor и SellTPColor -
the same for Sell positions.

It must be noted that the Expert Advisor was created to be used on a chart with black background, this is why many default colors are light. If you use white background, set dark colors. This is what I have done when testing the Expert for this article.


Well, finally, we press the Start button. The first thing we see in the chart is the Toolbox mentioned before:

It helps to open positions, place pending orders and choose values of predefined characteristics. We will study each of the actions listed before in the corresponding section. Now, I would only remark that all operations with the Toolbox are safer to be performed in the pause mode. Any action will be understood by the Expert as a command and cannot be cancelled. Since the Expert is intended for testing only, inaccuracy will not cause material losses for you, but you can ruin in this way the results obtained in your long-term and diligent testing.

The "Terminal" anf "Account History" windows are below in the chart. they remain empty until we start trading:

We can close and modify positions using the "Terminal" window, while the "Account History" window brings us information.

Position Opening

Let us try to open a position. First of all, it is necessary to define the lot size and the distances to StopLoss and to TakeProfit since we don't want to waste our time on modifications later.

As it was said before, the values are set using the toolbox: We must select the object containing the desired value and move it to any point in the screen. Any amounts og objects can be moved simultaneously, i.e., if we want to set lot size for 1 and TakeProfit for 100, we have to drag the corresponding values to a random point:

Now press F12 - the next tick incomes, and the Expert Advisor checks the selected values:

When opening a position, the Expert will use the selected value of the characteristic:
- the lot size is calculated according to the following formula: Free Margin * Risk * 0.01 * Leverage / Contract Size. If Risk=0, the selected Lot value is used;
distance to the Stop Loss is defined by the corresponding line (to be described below). If the StopLoss line has not moved, the selected value of SL will be used;
- distance to the Take Profit is defined by the corresponding line. If the TakeProfit line has not moved, the selected value of TP will be used;
- expiration time (for pending orders only) - the selected value of Exp will be used.

Positions are opened in a very simple way - it is sufficient just to drag the corresponding line to the chart. there are 3 lines for each order type:
- Open Price line
(solid for positions Buy and Sell, dashed for pending orders) is in the center, between Stop Loss and Take Profit lines;
- Stop Loss line
(dash-and dot) is located below the OpenPrice line for Buy positions and above it for Sell positions;
- Take Profit line
(dashed) - above for Buy positions, below for Sell positions.

Pending orders placed above the current price (Buy Stop and Sell Limit) are in the upper row. Those to be placed below the price (Buy Limit and Sell Stop) - in the lower row.

So if you want to open a Buy position with the selected values of Stop Loss and Take Profit (as for now, 50 and 100, respectively), just drag the Buy open line of the position to the chart:

Then press F12 and admire the results:

Since positions Buy and Sell are opened solely at current prices, there is no need to place the line exactly onto the price: the Expert will substitute proper values by itself. But it is very important to specify correct prices for pending orders, otherwise the order will not be placed.

Let us now set the Sell Stop order:
- lot size - 10% of the deposit;
- Open Price and Stop Loss to be set manually;
- Take Profit disabled;
- expiry time 30 minutes (0.5 hour).

Let's take all necessary objects and place them in the chart:

Press F12 and see:

Everything seems to be ok.

Order Closing

Closing of positions and deletion of pending orders are much simpler tasks. All what we have to do is just to select the ticket of the order to be closed and move it:

The result will not keep us waiting: the Expert will have already closed the position by the next tick:

Pending orders will be deleted in the same way.

Position Modification

Copntrolling order modification combines position closing and opening elements: To select a characteristic to be changed (Open Price, Stop Loss or Take Profit), it is necessary to move the corresponding field.

After the next tick has income, the Expert Advisor will create the Modifying Line that will help in changing the value of the corresponding characteristic:

After we have moved the line to its new position, we press F12 and see the result:

If you want to absolutely delete Stop Loss or Take Profit, just delete the corresponding field:

After deletion of the Open Price field, one can close the position (delete the order) - some traders may consider this method to be more convenient.

There are no limitations on the amount of parameters to be modified simultaneously - you can even modify all open positions within one tick.


After having read the article, you will see that it is not necessary to be a programmer in order to test your strategy on historical data. Using the manual testing mode, you can trade on historical data manually.

The Expert Advisor, library and indicators given in the article allow simulation of the real trading terminal.

At the end of my article, I would like to remind you that the Expert Advisor is not intended for real trading. Do not trust you money to a test program.

To simplify controlling of orders in the real-time mode, the online complex AutoGraf was created. It is this complex that produced some ideas and code parts for this present article (by courtesy of the creator). Many thanks to the creator for this!

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/1425

Attached files |
vHandsTrade.mq4 (51.49 KB)
vHistory.mq4 (0.56 KB)
vTerminal.mq4 (0.56 KB)
Last comments | Go to discussion (24)
MQL4 Comments
MQL4 Comments | 1 May 2013 at 21:01

firstly many thanks to those behind the development of vHands - its a great program for the like of myself who likes to manually trade.

i would be very grateful if you could tell me if it is possible to partially close an open order whist vHands testng?  this would be most beneficial for strategies such as close half at break even etc.

alternatively if you could point out there in the coding this might best be added i would be happy to attempt to program and repost


kind regards




PS: apologies for multiple posts - i thought my post hadn;t take to the board (blush) lol 

Andrias Johanson
Andrias Johanson | 24 May 2014 at 14:11
This is a great tools but doesn't work on the MT4 build 600+, any one can fix the issue?
Rahima | 28 Aug 2014 at 06:32

Dear all,

Does anyone know if it is possible to download the sample of rearranged (bootstrapped) forex rates to MetaTrader 4 and apply testing on those samples rather than applying it on historical data?


leinnash | 28 Dec 2019 at 18:50
I want to say thank you alot for this Vhand trading sims..

but there is still some problems with my mt4, it become like this..

Andrey Khatimlianskii
Andrey Khatimlianskii | 30 Dec 2019 at 07:03
I want to say thank you alot for this Vhand trading sims..

but there is still some problems with my mt4, it become like this..

vHandsTrade is very very old solution and isn't supported now.

The language has changed significantly since HandsTrade was developed in 2007.

Please, find other solutions for testing your manual strategies, for exmaple this.

Testing Visualization: Functionality Enhancement Testing Visualization: Functionality Enhancement

The article describes software that can make strategy testing highly similar to the real trading.

Testing Visualization: Trade History Testing Visualization: Trade History

The article describes the possibilities of convenient viewing the trade history when visualizing tests. Starting from build 196, MetaTrader 4 Client Terminal offers testing visualization function. It allows controlling the Expert Advisors' testing on a brand new level. Now, the trading programmer can watch every action of his or her Expert Advisor checking its operation on history!

What Is a Martingale? What Is a Martingale?

A short description of various illusions that come up when people trade using martingale betting strategies or misuse spiking and the like approaches.

Effective Averaging Algorithms with Minimal Lag: Use in Indicators Effective Averaging Algorithms with Minimal Lag: Use in Indicators

The article describes custom averaging functions of higher quality developed by the author: JJMASeries(), JurXSeries(), JLiteSeries(), ParMASeries(), LRMASeries(), T3Series(). The article also deals with application of the above functions in indicators. The author introduces a rich indicators library based on the use of these functions.