i am trying to undestand basic codes in MQL5 and one thing i've got biggest problem with are indicator handles.
can someone tell me what is this line supposed to do:
Is the value in maHandle actualized every time MA changes?
Does the iMA function return a reference to the first element of the buffer where all MA values are stored?
What exactly a handle is?
If maHandle is a single int, what is this line supposed to do?
assuming MA is a dynamic array.
I am sorry if such topic already exists. If so please, give me the link.
You should try and read this article, it will guide you:
Thank You for your quick answer olowsam, but
i have already read that one,
i know something about how to use them, but i dont know the mechanics behind them
and the article doesnt explain it :(
I repeat queston that puzzles me the most:
The iMA, just like any other indicator functions returns the handle for that particular indicator. This is similar to opening a file.
// This code is taken from the manual
Print("Failed to open the file by the absolute path ");
Print("Error code ",GetLastError());
Remember that when you get a handle for a file, all you need to manipulate the file is just the handle you have created. You can now write and do whatsoever you wish with the file using the handle.
The same goes for Indicators. You use the indicator function to obtain a handle which will now be used to get whatever values of the indicator at any point in time in a timeframe/chart.
The code :
is used to obtain the handle for the indicator. This is mormally done only once within the OnInit() function of your expert advisor code.
Somewhere in your code within the OnTick() function, you need to get the corresponding values of the indicator for each bar on the timeframe you are considering. So we use the CopyBuffer function together with the handle we had obtained earlier, so we how have
Alert("Error copying MA indicator Buffers - error:",GetLastError(),"!!");
As you said, MA is declared as a dynamic array and what CopyBuffer does is to copy the specified range of values (in the CopyBuffer function) for the indicator using the handle as a reference to the Indicator you working on. What we have done above is to copy the values of the indicator from the current bar (Bar 0) to the previous 99 bars. These values will in turn be stored in the MA array for you to access as MA => BAR 0 value MA => bar 3 value etc.
I don't know if you are now clear with my explanation.
great explanation! Thank You a lot.
Slowly i am getting much more confident in MQL, although some features are quite unintuitive for me.
Thanks again :)