Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Libraries | Symbol

MetaTrader Experts, Indicators, Scripts and Libraries

The library contains functionality that allows you to understand the basics of work with custom symbols, and offers some ready-made solutions that can be useful.

Example

When you run backtest on cross pairs, the tester uses the main symbol and an additional one allowing to convert the profit currency of the main symbol to the account currency. Access to the additional symbol, generation of its ticks, and synchronization with the main symbol take too much precious computing resources and time during a single test run and especially during optimization. However, this accuracy is almost always unnecessary. Therefore, I wanted to bypass this obtrusiveness/flaw of the MetaTrader 5 tester. It can be easily done in MetaTrader 4, because it provides the possibility to change the account currency directly in the tester. MetaTrader 5 does not provide this option.

The demo script shows an attempt to bypass this restriction of the tester, i.e. to remove unnecessary calculations. For this purpose, it creates a copy of the symbol for backtesting, and the sets profit currency equal to the account currency. Therefore conversion of testing results is not required. In this case, profit is actually calculated in pips, which can be very demonstrative in some situations.

// Creating a copy of the symbol and changing the profit currency
#property script_show_inputs

#include <Symbol.mqh>

sinput string PostFix = "_custom";

void OnStart()
{
  const SYMBOL Symb(_Symbol + PostFix); // Creating the symbol

  Symb = _Symbol; // Copying all properties and the bar history of the main symbol

  Symb.SetProperty(SYMBOL_CURRENCY_PROFIT, AccountInfoString(ACCOUNT_CURRENCY)); // Making the base currency equal to the deposit currency

  Symb.On(); // Enabling the symbol in Market Watch

  ChartOpen(Symb.Name, PERIOD_CURRENT); // Opening the chart of the new symbol
}
18855

Best MetaTrader Indicators + Profitable Expert Advisors