| / | Articles |
Articles
Tester
Testing Visualization: Functionality Enhancement
To post a new article, please log in or register
|
Testing Visualization: Functionality Enhancement [ ru ]1. MotivationStarting 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! You can read about how to use the visualizer in the article named Testing of Expert Advisors in the MetaTrader 4 Client Terminal: An Outward Glance. Our article describes how to make the strategy tester highly similar to the terminal. So, what is the main specific of he tester? What lacks in visualization? The most important lack is perhaps the lack of "Trade" tab. How many positions were opened? How soon will the pending order trigger? Has the StopLoss of the position moved? How much is the margin at the moment and how long is it to go to the MarginCall level? We find answers to these and many other questions in the "Trade" tab of the Terminal. But what can we do when testing? This present article is devoted to solution of this problem. 2. Technical AspectsWe will start coding with problem definition, as usual. What result do we want to obtain? It is obvious that indicator in a separate window could be the best solution. It is always visible, does not hatch the price chart and is updated on every tick. But we then face a new problem when using the indicator - it takes all data about orders from the normal terminal, not from the 'virtual' (test) terminal, i.e., while testing, it will show information about the current state of the account without any reaction to the testing itself. So we will have to find an alternative, a kind of a back way, to solve our problem. Showing and updating of information will be assigned to a function library formed an included file. 3. Putting in Use
First of all, a chart template must be created that will use the visualizer. Just adjust the chart (colors, grid, scale), attach vTerminal.mq4 to the chart and use the "Save Template" command: ![]() Chart Appearance before It Is Saved
Window "Save as Template"
4. Integration with the Expert AdvisorFunctions that show information about positions are saved in the included file named VisualTestingTools.mq4, which is in the ...\MetaTrader 4\experts\include\ directory. First of all, it must be attached to the Expert Advisor - insert #include <VisualTestingTools.mq4> line before the start function. It will then appear as follows (example of CrossMACD_DeLuxe): ... double _Commission = 0.0; string _Comment = ""; datetime _Expiration = -1; #include <VisualTestingTools.mq4> int start() { if ( FastEMAPeriod >= SlowEMAPeriod ) { return(-1); } int _GetLastError = 0; ...
... double _Commission = 0.0; string _Comment = ""; datetime _Expiration = -1; #include <VisualTestingTools.mq4> int init() { if ( FastEMAPeriod >= SlowEMAPeriod ) { return(-1); } vTerminalInit(); return(0); } int start() { if ( FastEMAPeriod >= SlowEMAPeriod ) { return(-1); } vTerminalRefresh(); int _GetLastError = 0; ... You can download Expert Advisor CrossMACD_DeLuxe_Visual.mq4 where all necessary changes have already been made. 5. TestingNow let us look what we have got. ![]() New external variables are available after the VisualTestingTools.mq4 file has been added to the Expert Advisor's code
![]() Until there are no open positions, our "terminal" shows only heading and the account status bar. Let us wait until a signal appears and the Expert opens a position. ![]() A Sell position is opened as the first one. As you can see, the line is red. Please direct your attention to the account status bar. It contains everything we get used to see in the "Trade" tab of the terminal. The entire information is updated every tick, so you can see how the position's profit changes: ![]() When price approaches to the Stop Loss level of the position, the StopLoss field changes its color to that preset by user: ![]() As to me, it is quite good. 6. Possible ProblemsOne more feature of using the tester.tpl with indicator vTerminal should be mentioned: During testing, the function that must find the indicator's window (WindowFind()) is unabled. This is why, the subwindow number is explicitly set in the code: win = WindowFind( "vTerminal" ); if ( IsTesting() ) { win = 1; } If the template contains other indicators to be drawn in a separate window, the entire information about them will be shown in the upper window. I.e., you have either to place vTerminal on the top or write win = subwindow number; instead of win = 1; . No other problems were found when working with the indicatorь. 7. ConclusionTo draw a beautiful conclusion, I would like just to show some screenshots. ![]() ![]() ![]() ![]() ![]() Translated from Russian by MetaQuotes Software Corp. Original article: http://articles.mql4.com/ru/176 Attachments:
Warning:
All rights to these materials are reserved by MetaQuotes Software Corp.
Copying or reprinting of these materials in whole or in part is prohibited.
Hi,
good work but I get this error, please help: 2008.02.09 12:10:12 2008.02.07 23:59 CrossMACD_DeLuxe_Visual EURGBP.,H4: ObjectSetText( "Comment_49", "", 8"Arial", 0 ) - Error #4202 Thanks Iinself
2008.02.09 20:16 iinself
1 comment
|