You should always check the result of the handle creation.
You MUST NOT return '0' in OnInit - in OnInit you must return:
ID
Description
INIT_SUCCEEDED
Initialization successful, EA test can be continued.
This code means the same as the zero value – the EA initialization in the tester is successful.
INIT_FAILED
Initialization failed. There is no point in continuing the test due to unavoidable errors. For example, it is impossible to create an indicator necessary for the EA operation.
The return of this value means the same as returning the value different from zero – EA initialization in the tester failed.
INIT_PARAMETERS_INCORRECT
Designed to denote an incorrect set of input parameters by a programmer. In the general optimization table, the result string with this return code is highlighted in red.
A test for such a set of EA inputs is not performed. The agent is ready to receive a new task.
When this value is received, the strategy tester does not pass this task to other agents for repeated execution.
INIT_AGENT_NOT_SUITABLE
No program execution errors during initialization. However, for some reasons, the agent is not suitable for conducting a test. For example, there is not enough RAM, noOpenCL support, etc.
After returning this code, the agent no longer receives tasks until the very end ofthis optimization.
Example:
//+------------------------------------------------------------------+//| ProjectName |//| Copyright 2020, CompanyName |//| http://www.companyname.net |//+------------------------------------------------------------------+#include <Trade\Trade.mqh>
CTrade m_trade; // object of CTrade class//--- input parametersinput group "MACD"inputENUM_TIMEFRAMES Inp_MACD_period = PERIOD_D1; // MACD: timeframeinputint Inp_MACD_fast_ema_period = 12; // MACD: period for Fast average calculationinputint Inp_MACD_slow_ema_period = 26; // MACD: period for Slow average calculationinputint Inp_MACD_signal_period = 9; // MACD: period for their difference averaginginputENUM_APPLIED_PRICE Inp_MACD_applied_price = PRICE_CLOSE; // MACD: type of priceinput group "Trading settings"inputdouble Lots4 = 0.2;
inputint Stoploss4 = 40;
inputint Takeprofit4 = 60;
//--- local variablesdouble PipValue = 1; // this variable is here to support 5-digit brokersbool Terminated = false;
string LF = "\n"; // use this in custom or utility blocks where you need line feedsint NDigits = 4; // used mostly for NormalizeDouble in Flex type blocksint ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique namesint current = 0;
int handle_iMACD; // variable for storing the handle of the iMACD indicatorbool m_init_error = false; // error on InInit//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---
NDigits = Digits();
if(NDigits == 3 || NDigits == 5)
PipValue = 10;
if(AccountInfoInteger(ACCOUNT_TRADE_EXPERT) == false)
{
Print("Check terminal options because EA m_trade option is set to not allowed.");
Comment("Check terminal options because EA m_trade option is set to not allowed.");
}
ObjectsDeleteAll(0); // clear the chart//--- create handle of the indicator iMACD
handle_iMACD=iMACD(Symbol(),Period(),Inp_MACD_fast_ema_period,Inp_MACD_slow_ema_period,
Inp_MACD_signal_period,Inp_MACD_applied_price);
//--- if the handle is not createdif(handle_iMACD==INVALID_HANDLE)
{
//--- tell about the failure and output the error codePrintFormat("Failed to create handle of the iMACD indicator for the symbol %s/%s, error code %d",
Symbol(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped early
m_init_error=true;
return(INIT_SUCCEEDED);
}
Comment(""); // clear the chart//---return(INIT_SUCCEEDED);
}
You should always check the result of the handle creation.
You MUST NOT return '0' in OnInit - in OnInit you must return:
ID
Description
INIT_SUCCEEDED
Initialization successful, EA test can be continued.
This code means the same as the zero value – the EA initialization in the tester is successful.
INIT_FAILED
Initialization failed. There is no point in continuing the test due to unavoidable errors. For example, it is impossible to create an indicator necessary for the EA operation.
The return of this value means the same as returning the value different from zero – EA initialization in the tester failed.
INIT_PARAMETERS_INCORRECT
Designed to denote an incorrect set of input parameters by a programmer. In the general optimization table, the result string with this return code is highlighted in red.
A test for such a set of EA inputs is not performed. The agent is ready to receive a new task.
When this value is received, the strategy tester does not pass this task to other agents for repeated execution.
INIT_AGENT_NOT_SUITABLE
No program execution errors during initialization. However, for some reasons, the agent is not suitable for conducting a test. For example, there is not enough RAM, noOpenCL support, etc.
After returning this code, the agent no longer receives tasks until the very end ofthis optimization.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I know that
i like to correct this code
You should always check the result of the handle creation.
You MUST NOT return '0' in OnInit - in OnInit you must return:
ID
Description
INIT_SUCCEEDED
Initialization successful, EA test can be continued.
This code means the same as the zero value – the EA initialization in the tester is successful.
INIT_FAILED
Initialization failed. There is no point in continuing the test due to unavoidable errors. For example, it is impossible to create an indicator necessary for the EA operation.
The return of this value means the same as returning the value different from zero – EA initialization in the tester failed.
INIT_PARAMETERS_INCORRECT
Designed to denote an incorrect set of input parameters by a programmer. In the general optimization table, the result string with this return code is highlighted in red.
A test for such a set of EA inputs is not performed. The agent is ready to receive a new task.
When this value is received, the strategy tester does not pass this task to other agents for repeated execution.
INIT_AGENT_NOT_SUITABLE
No program execution errors during initialization. However, for some reasons, the agent is not suitable for conducting a test. For example, there is not enough RAM, no OpenCL support, etc.
After returning this code, the agent no longer receives tasks until the very end of this optimization.
Example:
You should always check the result of the handle creation.
You MUST NOT return '0' in OnInit - in OnInit you must return:
ID
Description
INIT_SUCCEEDED
Initialization successful, EA test can be continued.
This code means the same as the zero value – the EA initialization in the tester is successful.
INIT_FAILED
Initialization failed. There is no point in continuing the test due to unavoidable errors. For example, it is impossible to create an indicator necessary for the EA operation.
The return of this value means the same as returning the value different from zero – EA initialization in the tester failed.
INIT_PARAMETERS_INCORRECT
Designed to denote an incorrect set of input parameters by a programmer. In the general optimization table, the result string with this return code is highlighted in red.
A test for such a set of EA inputs is not performed. The agent is ready to receive a new task.
When this value is received, the strategy tester does not pass this task to other agents for repeated execution.
INIT_AGENT_NOT_SUITABLE
No program execution errors during initialization. However, for some reasons, the agent is not suitable for conducting a test. For example, there is not enough RAM, no OpenCL support, etc.
After returning this code, the agent no longer receives tasks until the very end of this optimization.
Example:
That not resolve the problem Sorry .
I will dig by myself