New MetaTrader 5 Platform Build 2340: Managing account settings in the Tester and expanded integration with Python

 

The MetaTrader 5 platform update will be released on Friday, February the 21st, 2020. The new version features the following changes:

  1. MetaEditor: Added new functionality for working with SQLite databases.

    In the previous platform update, we introduced support for operations with SQLite databases directly from MQL5. The main functions have become available through the MetaEditor user interface:

    • Create and connect databases
    • View tables and perform quick data queries
    • Create and execute SQL queries and rollback changes

    How it works
    The quick database creation functionality is available from the MQL5 Wizard. You can easily create your first table and define its fields.




    Upon the database creation, you will be forwarded to a new Navigator section, which features commands for managing the data.

    Database tables are shown in the left-hand side window. Double-click on the table name to quickly query the first 1,000 records. In this navigator section, you can also create and open other databases, as well as work with tables.

    The database can be managed in the main editor window, in which you can fill in the table, search and select data, enter SQL queries and execute other operations:



    For further details about MetaTrader 5 operations with databases, please read the article entitled "SQLite: Native handling of SQL databases in MQL5".

  2. MetaEditor: Expanded support for multi-lingual projects. This update provides further expanded possibilities for working with Python scripts:

    • Now, such scripts can be created using the MQL5 Wizard, while you can instantly add required library dependencies in the code.
    • Special icons have been added in the navigator and the relevant syntax is available in the editor.
    • When running a script via MetaEditor, messages from the Python console (stdout, stderr) appear under the Errors section.




    Click "Compile" in the editor to run the script:





    To work with Python, do not forget to specify its path under the Settings \ Compilers section in MetaEditor. To enable the use of the MetaTrader 5 library, install it using the following command:
    pip install MetaTrader5
    For Python integration details please read the relevant documentation.

  3. MQL5: Completely revised Python integration. The update involves many new functions and new command naming.

    New naming
    The existing commands have been renamed as follows:
    MT5Initialize       -> initialize
    MT5Shutdown         -> shutdown
    MT5TerminalInfo     -> terminal_info
    MT5Version          -> version
    MT5CopyRatesFrom    -> copy_rates_from
    MT5CopyRatesFromPos -> copy_rates_from_pos
    MT5CopyRatesRange   -> copy_rates_range
    MT5CopyTicksFrom    -> copy_ticks_from
    MT5CopyTicksRange   -> copy_tick_range

    New commands
    The list of supported commands has been expanded. Added trading functions, as well as functions for working with the trading history and for receiving financial symbol and current account data.

    • account_info() receives information about the current account. An analogue of AccountInfoInteger , AcountIndoDouble and AccountInfoString.
    • positions_total() receives the number of open positions. An analogue of PositionsTotal.
    • positions_get(symbol, ticket) receives open positions by symbol or ticket.
    • orders_total() receives the number of orders. An analogue of OrdersTotal.
    • orders_get(symbol, ticket) receives open orders by symbol or ticket.
    • history_orders_total(from, to) receives the number of orders in the specified historical time frame.
    • history_orders_get(from, to, position, ticket) receives orders from the specified historical time frame, by ticket or as filtered by position.
    • history_deals_total() receives the number of deals in the history. An analogue of HistoryDealsTotal.
    • history_deals_get(from, to, position, ticket) receives deals from the specified historical time frame, by ticket or as filtered by position.
    • symbol_info(symbol) receives information about a financial instrument. An analogue of SymbolInfoInteger, SymbolInfoDouble, SymbolInfoString.
    • symbol_info_tick(symbol) receives the last tick by symbol. An analogue of SymbolInfoTick.
    • symbol_select(symbol, enable) enables/disables a symbol in Market Watch. An analogue of SymbolSelect.
    • order_check(request) checks order margin. An analogue of OrderCheck.
    • order_send(request) sends an order to the server. An analogue of OrderSend.
    • order_calc_margin(action, symbol, volume, price) calculates margin for an order. An analogue of OrderCalcMargin.
    • order_calc_profit(action, symbol, volume, price_open, price_close) calculates profit. An analogue of OrderCalcProfit.

    Running Python scripts on charts
    Python scripts can be run directly on platform charts, similarly to regular MQL5 programs. These scripts are marked with special icons in the Navigator.



    Script messages will be displayed under the "Toolbox \ Experts" section. If a MetaTrader 5 library is used in the script, it can receive trading symbol and account data, as well as perform trading operations.

    Python scripts can be executed on the same chart in parallel with other MQL5 scripts and Expert Advisors. To stop a script with a looped execution, remove it from the chart.

    Additional protection
    To enable additional account protection when using third-party Python libraries, you may activate the "Disable automated trading via external Python API" option in terminal settings.




    Python scripts can only perform trading operations when this option is disabled.

  4. MQL5: Significantly accelerated re-launch of MQL5 programs and re-creation of custom indicators from MQL5 programs. In some cases, operations are performed 100 times faster.
  5. MQL5: Added functions for working with databases:

    DatabaseImport
    Imports data from a file to a table.
    long  DatabaseImport(
       int           database,          // database handle received in DatabaseOpen
       const string  table,             // table name to insert data to
       const string  filename,          // file name to import data from
       uint          flags,             // combination of flags
       const string  separator,         // data separator
       ulong         skip_rows,         // number of first rows to skip
       const string  skip_comments      // string of characters, which define comments
       );

    DatabaseExport
    Exports a table or an SQL query result to a CSV file. The file is created in UTF-8 encoding.
    long  DatabaseExport( 
       int           database,           // database handle received in DatabaseOpen 
       const string  table_or_sql,       // table name or SQL query
       const string  filename,           // CSV file name for data export
       uint          flags,              // combination of flags
       const string  separator           // data separator in the CSV file
       );

    DatabasePrint
    Prints the table or SQL query result to the Experts journal.
    long  DatabasePrint(
       int           database,          // database handle received in DatabaseOpen
       const string  table_or_sql,      // table or SQL query
       uint          flags              // combination of flags
       );

  6. MQL5: Added FileSelectDialog function, which calls the system dialog creating/opening a file or a folder.
    int  FileSelectDialog(
       string   caption,              // window title
       string   initial_dir,          // initial directory
       string   filter,               // extension filter
       uint     flags,                // combination of flags
       string&  filenames[],          // array with file names
       string   default_filename      // default file name
       );
    The new function enables the efficient user interaction with the MQL5 program.

  7. MQL5: New DEAL_FEE value in the ENUM_DEAL_PROPERTY_DOUBLE enumeration. It is used for a deal fee. The value indicates a separate commission type charged by the broker.

  8. Tester: Added functionality to specify custom trading account settings during strategy testing, such as trading limitations, margin settings and commission. The new functions provide extended capabilities for the modeling of various trading conditions.




    Common settings
    In this section, you can set the maximum number of open orders and positions, which can simultaneously exist on the account. Additionally, you can configure sessions during which the program is not allowed to trade.


    Margin
    The section allows configuration of margin reserving rules and position accounting systems to be used in testing:

    • Risk management — risk management model: OTC and exchange model, netting and hedging systems. For details please read the Documentation.
    • Margin call level — when this level is reached, the account switches to the Margin Call state.
    • Stop out level — when this level is reached, all orders are canceled and all trading positions are closed. These levels can be indicated in percentage and in money. If "in money' is selected, the levels are defined as the account's Equity value. If "In percent" is selected, the levels are defined as the account "Margin level" value (Funds/Margin*100).
    • Unrealized profit — accounting for the current floating profit/loss in the free margin:
      • Do not use unrealized profit/loss — do not include profit/loss of open positions in the calculation.
      • Use unrealized profit/loss — include open positions' profit/loss in the calculation.
      • Use unrealized profit — include only profit.
      • Use unrealized loss — include only loss.
    • Daily fixed profit — accounting for the client's daily fixed profit/loss in the free margin:
      • Use daily fixed profit/loss — include in the free margin profit and loss received during a trading day.
      • Use daily fixed loss — include only loss received during the trade day. During the day, the obtained profit is accumulated in the special account field ("Blocked"). At the end of the trading day, the accumulated profit is released (zeroed) and is added to the account balance (included in the free margin).
    • Release fixed profit at the end of day — this option becomes available only if the option "Use daily fixed loss" is selected. If it is enabled, the accumulated profit will be released (and thus included in the free margin) at the end of the day. Otherwise this profit amount will remain blocked.


    Commission
    This section provides control over commissions charged for all trading operations.

    • Commission may be single-level and multi-level, i.e. be equal regardless of the deal volume/turnover or can depend on their size. Appropriate data is displayed in the terminal.
    • Commission can be charged immediately upon deal execution or at the end of a trading day/month.
    • Different commissions can be charged depending on deal direction: entry, exit or both operation types.
    • Commission can be charged per lot or per deal.
    • Commission can be calculated in money, percentage or points.



  9. Tester: Optimized and accelerated work in the Market Scanner mode, during which multiple testing passes are run for all symbols available in the Market Watch.
  10. Tester: Deal or position size is now taken into account when calculating profit in pips. Previously, the calculation was only performed per one lot.
  11. Tester: Improved control over optimization results graph. The scroll option has been added for a zoomed optimization graph. Double-clicking on a graph point selects the corresponding result in the table of testing passes.
  12. MetaEditor: Added display of SQLite database files (*.db;*.sdb;*.sqlite;*.db3;*.s3db;*.sqlite3) in the Navigator.
  13. MetaEditor: Fixed project property saving errors.
  14. Updated documentation.

The new MetaTrader 5 version will be available through the LiveUpdate system.

 
Hi,

I've just updated to MetaTrader 2340 and I noticed that it broke custom DLL loading in Strategy Tester. I have an EA that uses a custom DLL and it stopped working because the Strategy Tester is unable to load the DLL. Before version 2340, everything was working properly

I wrote a simple EA with a test.dll to reproduce this error. The test DLL exports only one function, which is "void __stdcall  test(int & x)".


When I try to run the EA in the Strategy Tester, I get this error:

2020.02.21 22:57:17.607 Tester file C:\Users\Luis\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\Luis\tests\TestExpert\TestDLL.dll.ex5 open error [2]

Here is the test EA code:

#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"


#import "TestDLL.dll"
void test (int& x);
#import

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   int p = 0;
   test(p);
   
   Print (p);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   


Here is the DLL code:


#define _DLLAPI extern "C" __declspec(dllexport)

_DLLAPI void __stdcall  test(int & x)
{
    x = 25;
    return;
}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}


How to solve this issue? I attached the sample project to this post.


Thanks

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Dozens of new automated trading applications appear in the MQL5 Market every day. Choose the right app among 10,000 products and forget about unnecessary routine operations of manual trading. Sell your algorithmic trading programs through the largest store of trading applications! CreateGridOrdersTune A script for opening a grid of orders If...
Files:
TestExpert.zip  19 kb
 
Hi everybody,

I have same problem as Luis, no DLL import possible on Strategy Tester anymore.
Strange is, that .ex5 is added in the error message -> filename.dll.ex5
If I add ex5 behind my dll file-name, it doesn‘t throw that error-message anymore, but doesn’t use the dll easier...

Please help/fix!

Thanks in advance!

Cheers
René 

UPDATE
-> Found a workaround, not nice but works, at least for me.
Put the same dll file in Tester and Terminal libraries with an additional .ex5 extension, so that you have filename.dll.ex5 and filename.dll in the libraries folder. Don‘t forget you need those in tester and terminal...

As said not nice, so may I ask please to work on an bugfix anyways?

Thanks!
 

I haven't been able to use MT5's strategy tester properly for a long time.

Before today, I was able to use the 2280 version on my local CPU core and get the correct results.

Tester agents deployed to remote CPU cores on the LAN are always forced to upgrade to bug-ridden versions after 2280, causing all remote tester agents to return incorrect results.


So for a long time I had to wait patiently for optimizations to be done on the local computer while a lot of computing power deployed on the LAN was wasted.

I'm so hoping that metaquotes fixes bugs in the new release version, making the strategy tester a tool that at least works.

And today I finally got version 2340.

Then I found out that even the optimizations tasks on the local CPU core were not getting the right results!

 
tickfenix:

I haven't been able to use MT5's strategy tester properly for a long time.

Before today, I was able to use the 2280 version on my local CPU core and get the correct results.

Tester agents deployed to remote CPU cores on the LAN are always forced to upgrade to bug-ridden versions after 2280, causing all remote tester agents to return incorrect results.


So for a long time I had to wait patiently for optimizations to be done on the local computer while a lot of computing power deployed on the LAN was wasted.

I'm so hoping that metaquotes fixes bugs in the new release version, making the strategy tester a tool that at least works.

And today I finally got version 2340.

Then I found out that even the optimizations tasks on the local CPU core were not getting the right results!


Reply from Russian forum thread - post #626 (just in case someone else is interested)

Forum on trading, automated trading systems and testing trading strategies

MetaTrader 5 Strategy Tester: errors, bugs, suggestions for improving the work

fxsaber , 2020.02.22 11:16

The last few pages in this thread are dedicated to this issue. Yesterday, the developers managed to reproduce this bug, and they are engaged in its elimination.


 

Dear MetaQuotes Software Corp.!

I make software development and I want to make a report about an error issue with the MQL5 programming language. Please submit my report to the MetaTrader 5 and MQL5 software developer team! Many thanks for considering my request! The following code is not compilable and the preprocessor and the compiler do not operate as the programmers expect. The code example is the following.

#define p_paste(arg_0, arg_1, arg_2) arg_0##arg_1##arg_2
#define p_evaluate_paste(arg_0, arg_1, arg_2) p_paste(arg_0, arg_1, arg_2)
#define apple 11
#define mouse 12
#define table 13

void f()
{
    int i = 10 + p_evaluate_paste(apple, mouse, table);
    PrintFormat("%d\n", i);
    return;
}

This code is not compilable. The compiler error message is: "'111213' - undeclared identifier". This is not an identifier but just an integer literal. This does not have to be a valid identifier token. This is an obvious error of the implementation of the preprocessor. With GNU CPP this kind of programming constructions are compilable. I have a huge and bigger and bigger MQL5 software framework for my trading system and I could not compile some of my solutions with concatenating just an `arg_type' and a `&' to create a plain reference variable for objects. Please fix this issue ASAP! Many thanks for considering my request! Please, please, finish the implementation of the multiple inheritance from interfaces facilities ASAP! This is important for the future achievements. MetaTraders are otherwise excellent products and I have installed 250 instances in my   virtual machine of the MetaTrader 5 client application. I would like to operate serious trading with your and my softwares.

Yours faithfully and best wishes: László Müller (voyevoda), Dombóvár, Hungary.

Virtual hosting for MetaTrader 5
Virtual hosting for MetaTrader 5
  • www.mql5.com
Virtual hosting for MetaTrader 4/5 is the best VPS solution for Forex. It is cheap, it requires no configuration and it features minimum delays to the server. For only $10 per month, you obtain a virtual platform that works around the clock, saves your profit and pays off. Create a remote copy of the application directly from the platform...
 

It seems that when starting the test (i.e. by clicking "Start" in the Strategy Tester),  the Tester agent is not copying the required files (including the DLL) to its internal MQL\Libraries folder. I've identified two events:

If I have a "Test.dll" file in my EAm then

1) Strategy Tester complains that the Test.dll.ex5 file is not found

2) The Test agent does not copy Test.dll to its internal folder and thus, the Strategy Tester complains that Test.dll cannot be found

%appdata%\Roaming\MetaQuotes\Tester\<MT5 ID>\Agent-127.0.0.1-3000\MQL5\Libraries\




Luis:
Hi,

I've just updated to MetaTrader 2340 and I noticed that it broke custom DLL loading in Strategy Tester. I have an EA that uses a custom DLL and it stopped working because the Strategy Tester is unable to load the DLL. Before version 2340, everything was working properly

I wrote a simple EA with a test.dll to reproduce this error. The test DLL exports only one function, which is "void __stdcall  test(int & x)".


When I try to run the EA in the Strategy Tester, I get this error:

2020.02.21 22:57:17.607 Tester file C:\Users\Luis\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\Luis\tests\TestExpert\TestDLL.dll.ex5 open error [2]

Here is the test EA code:


Here is the DLL code:



How to solve this issue? I attached the sample project to this post.


Thanks

 

What exactly re-launch of MQL5 programs and re-creation of custom indicators from MQL5 programs means?

"4. MQL5: Significantly accelerated re-launch of MQL5 programs and re-creation of custom indicators from MQL5 programs. In some cases, operations are performed 100 times faster"

 
Luis:

It seems that when starting the test (i.e. by clicking "Start" in the Strategy Tester),  the Tester agent is not copying the required files (including the DLL) to its internal MQL\Libraries folder. I've identified two events:

If I have a "Test.dll" file in my EAm then

1) Strategy Tester complains that the Test.dll.ex5 file is not found

2) The Test agent does not copy Test.dll to its internal folder and thus, the Strategy Tester complains that Test.dll cannot be found

%appdata%\Roaming\MetaQuotes\Tester\<MT5 ID>\Agent-127.0.0.1-3000\MQL5\Libraries\





Hi.

Many of us are running the same problem with DLL file loading on strategy tester.


There is no libraries folder any more under Tester folder. This path below is no longer existing.

%appdata%\Roaming\MetaQuotes\Tester\<MT5 ID>\Agent-127.0.0.1-3000\MQL5\Libraries\

Did you try to create Libraries forlder for Tester manually ?

Does it work ?




%appdata%\Roaming\MetaQuotes\Tester\<MT5 ID>\Agent-127.0.0.1-3000\MQL5\Libraries\

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 
Yes, copying the DLL manually to the Agent\MQL\Libraries folder (and creating this folder if it does not exist) seems to work as a workaround
 
Luis:
Yes, copying the DLL manually to the Agent\MQL\Libraries folder (and creating this folder if it does not exist) seems to work as a workaround

In previous version of MetaTrarader 5, the platform did it automatically.

Hence, they just forgot to copy and paste some piece of code for this new version.

I guess this is really minor bug though in terms of coding.

Hope they can fix it and release the new version really soon.

Not many people enjoying to create, copy and paste files from folder to folder manually.  

Reason: