
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Friends, I am new to MT5 and am learning to create EAs. I copied simple code to execute Ctrade.Buy but the backtest failed. Here's more info:
1) Account: Its a live account with base currency as NZD
2) MetaEditor settings for backtest:
3) Code: Copied from https://www.mql5.com/en/articles/481:
//+------------------------------------------------------------------+
//| demo.mq5 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#include<Trade\Trade.mqh>
//--- object for performing trade operations
CTrade trade;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- set MagicNumber for your orders identification
int MagicNumber=123456;
trade.SetExpertMagicNumber(MagicNumber);
//--- set available slippage in points when buying/selling
int deviation=10;
trade.SetDeviationInPoints(deviation);
//--- order execution mode
trade.SetTypeFilling(ORDER_FILLING_RETURN);
//--- logging mode: it would be better not to declare this method at all, the class will set the best mode on its own
trade.LogLevel(1);
//--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend()
trade.SetAsyncMode(true);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
BuySample1();
}
//--- Buy sample
//+------------------------------------------------------------------+
//| Buying a specified volume at the current symbol |
//+------------------------------------------------------------------+
void BuySample1()
{
//--- 1. example of buying at the current symbol
if(!trade.Buy(0.1))
{
//--- failure message
Print("Buy() method failed. Return code=",trade.ResultRetcode(),
". Code description: ",trade.ResultRetcodeDescription());
}
else
{
Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
" (",trade.ResultRetcodeDescription(),")");
}
//---
}
4) Error log (Please note that I am testing only on EUR/USD):
GJ 0 19:36:44.410 127.0.0.1 login (build 1730)
HH 0 19:36:44.420 Network 38520 bytes of account info loaded
JO 0 19:36:44.420 Network 1482 bytes of tester parameters loaded
QE 0 19:36:44.420 Network 188 bytes of input parameters loaded
FR 0 19:36:44.421 Network 443 bytes of symbols list loaded
IF 0 19:36:44.421 Tester expert file added: Experts\demo.ex5. 46684 bytes loaded
QH 0 19:36:44.433 Tester initial deposit 10000.00 NZD, leverage 1:100
JN 0 19:36:44.437 Tester successfully initialized
ES 0 19:36:44.437 Network 46 Kb of total initialization data received
PP 0 19:36:44.437 Tester Intel Core i7-4510U @ 2.00GHz, 8103 MB
RJ 0 19:36:44.799 Symbols EURUSD: symbol to be synchronized
HR 0 19:36:44.800 Symbols EURUSD: symbol synchronized, 3624 bytes of symbol info received
NJ 0 19:36:44.800 History EURUSD: history synchronization started
GO 0 19:36:44.856 History EURUSD: load 27 bytes of history data to synchronize in 0:00:00.000
RQ 0 19:36:44.856 History EURUSD: history synchronized from 2012.01.01 to 2017.11.15
EF 0 19:36:44.993 History EURUSD,Daily: history cache allocated for 1010 bars and contains 312 bars from 2014.01.01 00:00 to 2014.12.31 00:00
ND 0 19:36:44.993 History EURUSD,Daily: history begins from 2014.01.01 00:00
OL 0 19:36:44.996 Tester EURUSD,Daily (HalifaxPlus-Live): every tick generating
GN 0 19:36:44.996 Tester EURUSD,Daily: testing of Experts\demo.ex5 from 2015.01.01 00:00 to 2017.11.15 00:00 started
CK 0 19:36:56.288 Symbols NZDUSD: symbol to be synchronized
IS 0 19:36:56.288 Symbols NZDUSD: symbol synchronized, 3624 bytes of symbol info received
JL 0 19:36:56.288 History NZDUSD: history synchronization started
HJ 0 19:36:56.575 History NZDUSD: load 14 Kb of history data to synchronize in 0:00:00.078
LS 0 19:36:56.575 History NZDUSD: history synchronized from 2013.01.01 to 2017.11.15
CO 0 19:36:56.579 Symbols EURNZD: symbol to be synchronized
OJ 0 19:36:56.580 Symbols EURNZD: symbol synchronized, 3624 bytes of symbol info received
DL 0 19:36:56.580 History EURNZD: history synchronization started
MK 0 19:36:56.656 History EURNZD: load 27 bytes of history data to synchronize in 0:00:00.000
OD 0 19:36:56.656 History EURNZD: history synchronized from 2013.01.01 to 2017.11.15
IN 0 19:36:56.665 Trade 2015.01.02 03:00:00 market buy 0.10 EURUSD (1.20538 / 1.20549 / 1.20538)
PE 0 19:36:56.665 Trades 2015.01.02 03:00:00 deal #2 buy 0.10 EURUSD at 1.20549 done (based on order #2)
FH 0 19:36:56.666 Trade 2015.01.02 03:00:00 deal performed [#2 buy 0.10 EURUSD at 1.20549]
OG 0 19:36:56.666 Trade 2015.01.02 03:00:00 order performed buy 0.10 at 1.20549 [#2 buy 0.10 EURUSD at 1.20549]
FO 0 19:36:56.670 demo (EURUSD,D1) 2015.01.02 03:00:00 Buy() method executed successfully. Return code=10009 (done at 1.20549)
NM 2 19:37:15.823 History NZDUSD 2016.09.21 23:01:00: corrupted history detected (s:-73370, o:73433, h:+48, l:-123, c:-117 -- tv:63, rv:11250111)
JF 2 19:37:15.823 History NZDUSD 2016.09.21, bad container found, must be resynchronized
LQ 2 19:37:16.106 Tester history error 9 in undefined function
OH 2 19:37:16.106 Tester stopped on 0% of testing interval with error '20 NZDUSD'
Please tell me whats wrong and how do I resolve this?
Many Thanks and Merry Christmas :)