MQL4 - automated forex trading   /  

Code Base

Read Financial Magazines in MetaTrader 4 and MetaTrader 5!

Code Base  Libraries  Equity Recorder To post a new code, please log in or register

Download MetaTrader 5 and visit MQL5.community Code Base
and Trade on the Go!
and Trade on the Go!
Couldn't find the right code? Order it in the Jobs section

This script is for
MetaTrader 4
Download MT 4 - 455 Kb

and Trade on the Go!

and Trade on the Go!

Name:
Equity Recorder
Author: 7bit (2009.11.22 22:19)
Rating: 9.8
Downloaded: 3020
Download:
 offline_charts.mqh (14.8 Kb) View

I often see people post "equity" curves from the backtester, showing only smooth lines and ignoring any drawdown between opening and closing a trade. Since MetaTrader only plots a new datapoint in the equity plot when a trade is closed, you simply can not get realistic plots. Also the time is completely missing, the x axis shows the number of trades and does not draw a clear picture of the time you would have waited. In general the equity plots produced by the backtester always tend to look much nicer than they really are.

This is about to change now!

Attached is a library that will allow you to produce realistic plots of the total equity (the only important number) versus time. The plots are saved as offline charts, you can view and analyze them just like ordiary charts.

Put the library into the include folder, include it in your EA and on every tick you call the function recordEquity() with name, period and magic number. Thats all!

The function can also be used to create plots of manual or automated trading in real time filtered by magic number and/or comment string. Use it to monitor the individual performances of your concurrently running EAs in separate charts. When in backtesting mode the name of the chart file will always be prepended with an underscore, so it doesn't interfere with the live chart the same EA may have already produced over time.

If you want to make a plot of closed source EAs or of your manual trading then simply create an indicator with recordEquity() calls for every magic number or comment string you want to record in the start() function and attach it to any chart: 

Example code for using this library in such an indicator would look like this:

//+------------------------------------------------------------------+
//| equity_recorder.mq4 |
//| Bernd Kreuss |
//| 7ibt@arcor.de |
//+------------------------------------------------------------------+
#property copyright "Bernd Kreuss"
#property link "mailto:7ibt@arcor.de"

#property indicator_chart_window

#include <offline_charts.mqh>

/**
* the following will record 4 equity charts.
* attached to *any* chart (no matter which) this indi will on every tick
* calculated the profits, filter them by magic and comment and write
* them each into their own chart.
*/
int start(){
// all trading, whole account
// produce a dayly chart the with name "all" for it
recordEquity("all", PERIOD_D1, -1);

// all manual trading (magic = 0)
// produce a dayly chart with the name "all_manual" for it
recordEquity("all_manual", PERIOD_D1, 0);

// only manual trading with a comment of "foo" in the orders.
// Note that in this example we use an additional parameter
// to filter all manual trades by their comment string.
// It will match all trades beginning with, ending with
// or containing
the word "foo".
// Produce a dayly chart with the name "fooStrat" for it
recordEquity("fooStrat", PERIOD_D1, 0, "foo");

// record the equity of the expert advisor with the magic number of 1234
// produce an H1 chart with the name "scalperEA" for it
recordEquity("scalperEA", PERIOD_H1, 1234);
}


Attached is an image of an example plot. It is a simple grid system and the above library was used in the EA to create this equity chart:


Example Plot

11 comments: 1 2   To post a new comment, please log in or register
Great work! Is there any chance that you will alter the file to cope with the new HST file format?
13.02.2014 16:47 TJmclovin
Hello,

I installed your library and it works fine with a dialy period.
It is really much better than the native Equity curve provided by metatrader and very useful.

Nevertheless I have tried to use weekly or monthly period and the chart is truncated or empty.

Maybe code does not support these period ?

Or Iam doing something wrong ?

Thanks for you help.

JF G
01.04.2010 21:33 jfgrasset

I have moved the hosting of all my files to one central place since it is becoming more and more complex maintaining projects (and providing people with current versions of source code) with needed dependencies spread all over across the whole www.



The current version of this library can now always be found here: http://sites.google.com/site/prof7bit/offline_charts-mqh


20.03.2010 22:29 7bit
steeleq wrote:

Hello, I have some spike bars on the different charts. I've attached M1 sample. Could you comment this problem?

Try the current version i just uploaded (version > 2010.2.x.x). This seems to happen when metatader is restarted completely and the history is not yet loaded from the server. I can not fully guarantee that it is completely fixed now but I didn't see this problem appearing here anymore.

Also the new version has a dramatic increase in performance (faster backtests, much less CPU usage) since the realized profit is not calculated on every tick anymore, only when the order history has changed.

22.02.2010 21:55 7bit

Hello, I have some spike bars on the different charts. I've attached M1 sample. Could you comment this problem? It's not caused by EA (ca 3000% margin, and 0.1 Lots). Renko Idea is probably good, thank you.


equity chart problem

16.02.2010 16:37 steeleq
steeleq wrote:

Impressive work, thank you. I would be truly interested to try renko version. Is this really hard to code for you or anyone? I will appreciate.

A renko visualization of the equity chart?

In theory it should be possible to put one of the available renko EAs or scripts onto the equity chart and it should then create a realtime renko chart from your equity chart.

14.02.2010 18:13 7bit

Impressive work, thank you. I would be truly interested to try renko version. Is this really hard to code for you or anyone? I will appreciate.

13.02.2010 16:52 steeleq
negronjl wrote:

I get the Waiting for Update message and no chart.

Could you please post the lines of code where you call the recordEquity() function and the current values of all parameters used in the function call or make a minimal example EA or Indicator that will provoke this error so i can try to reproduce the problem?


23.01.2010 23:42 7bit

I followed the instructions and cannot get the offline chart to load. I get the Waiting for Update message and no chart.

I am running MBTrading MT4 on Windows 7 if that changes anything.

Any help would be greatly appreciated.

Thanks

21.01.2010 21:43 negronjl

Thank you 

06.01.2010 12:18 vasilyt