Features of the mql5 language, subtleties and tricks - page 18
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
And may I ask why static?
Because it is taken out of context - see the original post.
undocumented feature of the OnInit() function, this function can be run in any part of the program. Test code.
Result
...
undocumented feature of the OnInit() function, this function can be run in any part of the program. Test code.
All On-functions are normal functions and, accordingly, they can be called whenever you want. Either OnCalculate or OnTradeTransaction.
All On-functions are normal functions, and accordingly they can be called whenever you want. Either OnCalculate or OnTradeTransaction.
But it's not written in the documentation
OnInit
The OnInit() function is the OnInit event handler. It can be of typevoid orint, and has no parameters:
voidOnInit();
The Init event is generated immediately after loading an Expert Advisor or indicator, this event is not generated for scripts. The OnInit() function is used for initialization. If OnInit() has the int type return value, the non-zero return code means unsuccessful initialization, and it generates theDeinit event with the deinitialization reason codeREASON_INITFAILED.
To optimize the input parameters of an Expert Advisor it is recommended to use values from enumENUM_INIT_RETCODE as the return code. These values are used to control the course of optimization, including the selection of the most appropriatetesting agents. During initialization of an Expert Advisor before the start of testing you can request information about the configuration and resources of an agent (the number of cores, amount of free memory, etc.) using theTerminalInfoInteger() function. Based on the information obtained, you can either allow to use this testing agent, or reject using it during the optimization of this Expert Advisor.
ENUM_INIT_RETCODE
Identifier
Description
INIT_SUCCEEDED.
Successful initialization, testing of the Expert Advisor can be continued.
This code means the same as zero - initialization of the Expert Advisor in the tester was successful.
INIT_FAILED
Unsuccessful initialization, testing is meaningless to continue due to unrecoverable errors. For example, failed to create an indicator that is required for the work of the Expert Advisor.
Return of this value means the same as the return of a value other than zero - initialization of the Expert Advisor in the tester was unsuccessful.
INIT_PARAMETERS_INCORRECT
Designed to indicate an incorrect set of input parameters to the programmer. The result string containing this return code will be highlighted in red in the general optimization table.
Testing for this set of parameters of the Expert Advisor will not be executed, the agent is free to get a new task.
When receiving this value, the strategy tester is guaranteed not to pass this task to other agents for repeated execution.
INIT_AGENT_NOT_SUITABLE
No errors during initialization, but for some reason the agent is not suitable for testing. For example, there is insufficient RAM, there is noOpenCL supportand so on.
After returning this code, the agent will not receive tasks until the end of thisoptimization.
The OnInit() function of the void type always means successful initialization.
But it's not written in the documentation
OnInit
The OnInit()function is the OnInit event handler. It can be of typevoid orint, and has no parameters:
voidOnInit();
The Init event is generated immediately after loading an Expert Advisor or indicator
It says that it is a function.
It's not written in documentation, it's not mentioned here. It's called before OnInit and after OnDeinit - constructor/destructor calls of global objects (inaccuracy in Help). You can declare the indicator buffers without OnInit. The rudiments are as follows.
If the array is smaller, only part of the colors are transferred. If the array is larger, it is trimmed.
For width and style arrays, the principle is the same.
The overloaded (see above) HistoryDealSelect is called in OrderSendSync.
How can I determine the time of opening the last position and the time of closing the last position?
And in general, I would like to know the general principles and algorithms for obtaining information on open/closed positions on mql5.
What should be taken into account, what peculiarities exist at the moment?
How can I determine the time of opening the last position and the time of closing the last position?
In general, I would like to know the general principles and algorithms for obtaining information on open/closed positions in mql5.
What should be considered, what are the peculiarities at the moment?
This is all determined by selecting the history of orders and deals and then reading the properties of orders.
POSITION_IDENTIFIER
The position identifier is a unique number, which is assigned to each newly opened position and does not change throughout its lifetime. It corresponds to the ticket of the order with which the position was opened.
The position identifier is specified in each order (ORDER_POSITION_ID) and each trade (DEAL_POSITION_ID) that opened, changed or closed it. Use this property to search for orders and trades associated with the position.
When a position is reversed in netting mode (a single in/out trade), the POSITION_IDENTIFIER position identifier is not changed. However, POSITION_TICKET is changed to the order ticket which resulted in the reversal. In the hedging mode, there is no position reversal.
long
And using the properties from the enumeration ENUM_DEAL_ENTRY
DEAL_ENTRY_IN
Entering the market
DEAL_ENTRY_OUT
Market exit
DEAL_ENTRY_INOUT
U-turn
DEAL_ENTRY_OUT_BY
Closing of counter position