당사 팬 페이지에 가입하십시오
Сode that records balance and equity charts and calculates additional optimization criteria - MetaTrader 5용 라이브러리
- 조회수:
- 209
- 평가:
- 게시됨:
- 업데이트됨:
-
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
I decided to share the code from a large project designed in a separate library.
If you have access to the Expert Advisor code, you can save balance and equity charts and calculate additional optimization criteria by adding additional code from this library.
Download the Advanced Optimization Report Saver.mqh file from attached link and save it to the terminal folder \MQL5\Include\
Add the code that connects the downloaded file: (you can add it below the last line of your Expert Advisor code or anywhere else)
#include <Advanced Optimization Report Saver.mqh> Then, you need to add calls to the exported functions to the existing functions in your Expert Advisor: (if there are no functions, add them)
void OnTick(){ //... your code //Save balance and equity charts save_OnTick(TimeCurrent(), AccountInfoDouble(ACCOUNT_BALANCE), AccountInfoDouble(ACCOUNT_EQUITY)); } void OnTesterInit() { //... your code save_OnTesterInit();//print to chart "Do not close this window until the optimization is complete!" } void OnTesterDeinit(){ //... your code save_OnTesterDeinit();// get frames } double OnTester(){ //... your code //save any custom values: double AvgPips=0; save_Add( AvgPips, 2, "Custom 1", true);//value, digits, name, sort_min_to_max save_Add( TesterStatistics( STAT_PROFIT ), 2, "Custom 2"); double Custom = 0;//your Custom fitness saveCharts(Custom);//save final equity, all deals... return Custom; }
save_Add functions, allow you to add your own criteria that you want to include to your Report:
save_Add( AvgPips, 2, "Custom 1", true);//value, digits, name, sort_min_to_max
save_Add( TesterStatistics( STAT_PROFIT ), 2, "Custom 2");
For example, let's add this code to the Moving Average Expert Advisor from the Examples folder (...\MQL5\Experts\Examples\Moving Average\Moving Average.mq5). First, copy the original Expert Advisor and name it Moving Average Charts.mq5. Now, add the code from the instructions above to it.
The changes are only at the very end of the code, starting from the OnTick() function after CheckForOpen(); line:
void OnTick(void) { //--- if(SelectPosition()) CheckForClose(); else CheckForOpen(); //Save balance and equity charts save_OnTick (TimeCurrent(), AccountInfoDouble( ACCOUNT_BALANCE), AccountInfoDouble( ACCOUNT_EQUITY)); } void OnTesterInit() { //... your code save_OnTesterInit();//print to chart "Do not close this window until the optimization is complete!" } void OnTesterDeinit(){ //... your code save_OnTesterDeinit();// get frames } double OnTester(){ //... your code //save any custom values: double AvgPips=0; save_Add( AvgPips, 2, "Custom 1", true);//value, digits, name, sort_min_to_max save_Add( TesterStatistics( STAT_PROFIT ), 2, "Custom 2"); double Custom = 0;//your Custom fitness saveCharts(Custom);//save final equity, all deals... return Custom; } #include <Advanced Optimization Report Saver.mqh>
As you can see, it's quite simple and only takes a couple of minutes.
After that, you can run the optimization:


The last screenshot shows that the connected code added 2 parameters:
- Save Statistics - enables or disables the collection of statistics
- Pixels in balance and equity charts - specifies the number of pixels in the width of mini-charts.
Once the optimization is complete, you can create a report (using a program that parses saved frames) and see the following:
| 100 lines with MovingPeriod | 10 lines with MovingShift |
If there are more than 20 lines, only 3 horizontal lines of average values will be displayed: 3 on top and 3 on the bottom.
100 lines are difficult to perceive, so you need to reduce their number.
You to use input variables not with the same step, but with a scale through an enumerator (enum), for example: 1,2,3,5,7,10,15,20,30,50,70,100 - there will be only 12 lines instead of 100.
enum nums1 {__0=0, __1=1, __2=2, __3=3, __5=5, __7=7, __10=10, __15=15, __20=20, __30=30, __50=50, __70=70, __100=100, __150=150, __200=200, __300=300, __500=500}; input nums1 MovingPeriod = 10; // Moving Average periodYou can download the enum version of the Expert Advisor from attached files.
Instead of 1000 optimization passes, there will be 120, and the calculation time will be ~8 times faster, and the file size will be ~8 times smaller.
The result is more visible:

The result with MovingPeriod = 15 stands out immediately, with the highest average line and the highest maximum.
However, as is often the case, the best results on the backtest are not the best on the forward test.
Your program that parses saved frames can display Charts like this:

And additional criteria like this:
If you have a code for other interesting criteria, you can suggest them for adding to the library.
Binary tradng based on candle colors
A simple binary trading strategy that counts candle colors.
VR Locker Lite - Trading strategy based on a positive lock
Works using a positive lock; the trading robot creates one positive lock, and the trader decides what to do with it.
ShowTradeLines Service
This is a service to show entry/exit points of existing positions/deals as trend lines and/or arrows on charts.
MACD Signals
Indicator edition for new platform.


