Русский 中文 Español Deutsch 日本語 Português
Testing Visualization: Account State Charts

Testing Visualization: Account State Charts

MetaTrader 4Tester | 27 July 2007, 12:22
3 565 2
Andrey Khatimlianskii
Andrey Khatimlianskii

Introduction

I think, it is not only my wish to view the information about the account state during testing in the visualization mode in a more informative form.
What was the amount of free margin before opening the last position? Where is the balance curve directed to? How large was the drawdown on equity for the last day?

Some of these questions were discussed in the articles Testing Visualization: Functionality Enhancement and Testing Visualization: Trade History. But they do not contain any tool for quick and easy viewing the information on the account. In this article we will discuss programs for drawing charts of the account state during testing in the visualization mode. As an example we will examine Balance and Equity charts. The article also contains instructions on building charts of other account attributes.



Is it Easy?

One would think, what can be easier than writing an indicator, displaying Balance? The only buffer is fulfilled by the last known Balance value upon the receipt of bars. This is the algorithm.
But there is one problem: the indicator, displayed on the testing visualization chart, does not have the access to the state of the tested account. All functions, responsible for this information, return the values of the real account.
In this article we will learn to avoid this "peculiarity". For this purpose we need:

  • receive the information about the account state from the Expert Advisor;
  • pass it to the indicator and visualize it.

For passing the relevant data we will use Global variables of the terminal, and for their visualization - standard functions of custom indicators.



It is easy!

We need to add into the Expert Advisor, which will be tested, a code of saving the Balance into the Global variable. All we need is add one line in the beginning of the function start():

int start()
{
   // saving the last value of the balance into the global variable
   GlobalVariableSet( "vGrafBalance", AccountBalance() );
 
   // Expert Advisor code
 
   return(0);
}

The indicator code is not much more difficult:

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
 
double balance[];
 
int init()
{
    IndicatorShortName( "vGrafBalance" );
    IndicatorDigits( 2 );
 
    SetIndexStyle( 0, DRAW_LINE );
    SetIndexBuffer( 0, balance );
    SetIndexLabel( 0, "Balance" );
}
int start()
{
    balance[0] = GlobalVariableGet( "vGrafBalance" );
    return(0);
}

That is all! Now we can compile the indicator, the new version of the Expert Advisor and start testing!

After clicking the Start button and attaching an indicator to the chart, we will see something like this:




You see, the balance curve reflects real changes - at the closing of each trade its value changes.



What else can be done?

All other graphs are built the same way:

  • add into the Expert Advisor a line, updating the value of the necessary Global variable;
  • create a simple indicator, reading the value of this variable and reflecting it on the chart.

Note, that the variable name for each characteristic must be unique, i.e. it must not be identical with the names of other variables.
Besides, it should be identical with the name of the variable, read by the indicator.


The second example shows how to add the Equity chart to the Balance chart.
The code of the Expert Advisor:

int start()
{
   // saving the last value of the balance into the global variable
   GlobalVariableSet( "vGrafBalance", AccountBalance() );
   // saving the last value of the equity into the global variable 
   GlobalVariableSet( "vGrafEquity", AccountEquity() );
 
   // Expert Advisor code
 
   return(0);
}

The indicator code:

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
 
double equity[];
 
int init()
{
    IndicatorShortName( "vGrafEquity" );
    IndicatorDigits( 2 );
 
    SetIndexStyle( 0, DRAW_LINE );
    SetIndexBuffer( 0, equity );
    SetIndexLabel( 0, "Equity" );
}
int start()
{
    equity[0] = GlobalVariableGet( "vGrafEquity" );
    return(0);
}

Example of use:




We may attach one indicator to the another one to view the correlation of two characteristics:




Conclusion

The article describes the process of creating indicators, visualizing the account state. We have analysed the simplest indicators - Balance and Equity indicators.
You can create any other graph: percentage of profitable trades, expected payoff, Average lot or Profit of a position in points - everything is available.

The information can be beautifully presented!

Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/1487

Last comments | Go to discussion (2)
[Deleted] | 15 Sep 2007 at 16:51
I think your idea of indicator of equity and balance is very usefull.

But I have 2 problems.

One is I cannot write the indicator with both lines in one window (as you presented at the ned of your article).
Could you paste the code of the indicator of both balance and equity in one window?

The second problem is that the indicators work only when the testing is run in normal mode.
When Itry to run the indicator in the fast mode (using "skip to" function) the indicators are not drawn.
I guess it is possible to solve this problem by implementing the indicator into the expert advisor body.
But I have no idea how to do it.

Maybe you have any idea?


Thank you in advance for your help.
Andrey Khatimlianskii
Andrey Khatimlianskii | 16 Sep 2007 at 23:04
paszo:
One is I cannot write the indicator with both lines in one window (as you presented at the ned of your article).
Could you paste the code of the indicator of both balance and equity in one window?
Use this code:
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
 
double balance[], equity[];
 
int init()
{
    IndicatorShortName( "vGrafBalance&Equity" );
    IndicatorDigits( 2 );
 
    SetIndexStyle( 0, DRAW_LINE );
    SetIndexBuffer( 0, balance );
    SetIndexLabel( 0, "Balance" );
 
    SetIndexStyle( 1, DRAW_LINE );
    SetIndexBuffer( 1, equity );
    SetIndexLabel( 1, "Equity" );
}
int start()
{
    balance[0] = GlobalVariableGet( "vGrafBalance" );
    equity [0] = GlobalVariableGet( "vGrafEquity"  );
    return(0);
}

paszo:
The second problem is that the indicators work only when the testing is run in normal mode.
When Itry to run the indicator in the fast mode (using "skip to" function) the indicators are not drawn.
I guess it is possible to solve this problem by implementing the indicator into the expert advisor body.
But I have no idea how to do it.

Maybe you have any idea?
Unfortunately, it is impossible to solve this problem.
Strings: Table of ASCII Symbols and Its Use Strings: Table of ASCII Symbols and Its Use
In this article we will analyze the table of ASCII symbols and the ways it can be used. We will also deal with some new functions, the principle of operation of which is based on the peculiarities of the ASCII table, and then we will create a new library, which will include these functions. They are quite popular in other programming languages, but they are not included into the list of built-in functions. Besides, we will examine in details the basics of working with strings. So, I think you will certainly learn something new about this useful type of data.
Non-standard Automated Trading Non-standard Automated Trading
Successful and comfortable trading using MT4 platform without detailed market analysis - is it possible? Can such trading be implemented in practice? I suppose, yes. Especially in terms of the automated trading!
ZUP - Universal ZigZag with Pesavento Patterns. Part 2 ZUP - Universal ZigZag with Pesavento Patterns. Part 2
ZUP - Universal ZigZag with Pesavento Patterns. Part 2 - Description of Embedded Tools
Tester in the Terminal MetaTrader 4: It Should Be Known Tester in the Terminal MetaTrader 4: It Should Be Known
The elaborate interface of the terminal MetaTrader 4 is a forefront, but beside this the terminal includes a deep-laid tester of strategies. And while the worth of MetaTrader 4 as a trading terminal is obvious, the quality of the tester's strategy testing can be assessed only in practice. This article shows the advantages and conveniences of testing in MetaTrader 4.