Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
iCustom should in fact be used in the OnInit() because it returns a handle to be used in the other event handlers with CopyBuffer().
iCustom should in fact be used in the OnInit() because it returns a handle to be used in the other event handlers with CopyBuffer().
Thanks Fernando,
I tried to call OnInit() within OnTimer() and got a stack overflow error. Of course everything got reset and this did not help. So that does not work.
So, what is the secret. How do I create a handle outside on OnInit()?
The alternative is a brute force method. Making 154 handles..... I am making a handle for each timeframe ( 7 handles per symbol). Ideally, I do not want to make 7 handles times 22 pairs (154 handles) within OnInit() and call each one separately in OnTimer(). That might be a problem with speed.
Is there a better way?
Chris
So, what is the secret. How do I create a handle outside on OnInit()?
The alternative is a brute force method. Making 154 handles..... I am making a handle for each timeframe ( 7 handles per symbol). Ideally, I do not want to make 7 handles times 22 pairs (154 handles) within OnInit() and call each one separately in OnTimer(). That might be a problem with speed.
Is there a better way?
Don't call event handlers from other handlers. They are to be called from by the event system, not from within your code.
For a simple case, in OnInit(), assign the handle returned by iCustom() to a globally scoped variable. You only do this once. Then use that variable with CopyBuffer() in other locations for the life-time of the EA's execution. Please read the documentation. There is sample code demonstrating this.
For a more complex case with so many handles, either use a globally scoped array of handles, or use classes with an initialization method function that will be called during OnInit() or after the first tick, to assign the handle to a class method variables. This will only be done once during initialisation.
Design your code so that it initialises and assigns handles only once preferably during the OnInit() event. Assigning a handle takes time and consumes resources. It should not be not be done on the fly.
Please note that you can use IndicatorRelease() to release an indicator's resources when it is no longer needed.

- www.mql5.com
Thanks,
I ended up making 154 handles in OnInt(). Tested it and it worked just fine.
Thanks for the direction.
Chris

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am creating a multi-symbol EA (22 symbols) and need to change the iCustom conditions before each pass of the OnTimer().
My OnTimer is set to 15 seconds. So, there is a lot of time before I use the new settings.
I have a INT to switch what happens when the timer is triggered. The first pass will set the iCustom configuration to the new symbol. I set the switch and It then exits OnTimer(). 15 seconds later, the second pass will use that new configuration to get the data using Copy buffer. it resets the switch and 15 seconds later a new symbol will be configured using iCustom.
I am getting a 4806 error when I attempt to get the data using the Copybuffer.
I know the cause. The error happens when I use Copybuffer. but this only happens when I have iCustom within the OnTimer().
When I put the iCustom inside the OnInit(), the Copybuffer inside OnTimer() works just fine. I do not get any errors when I run iCustom. The only error happens when I use Copybuffer.
I believe setting iCustom inside the OnTimer() is the cause of this issue.
Why does the iCustom not work within ONTimer()?... even with a significant time delay between new tasks?
Cheers,
Chris Pinter