Good day to all forumchanam. I can’t figure out the sliding ones. More precisely, how to take the readings of two moving averages in mql5 ? I read the help, but I can’t figure it out yet. I want to take the fast MA readings at 10 and 15 bars. And the same slow MA at 10 and 15 bars, but Cheto already does not think straight, he is completely confused. It was based on the standard code and references. Even the value of one moving average is already displayed incorrectly. Tell me who will tell you how to implement this code. Thank you all in advance. //---- indicator buffers
double MA10_fast []; / / array of the 1st fast MA bar
double MA15_fast []; / / array of the 2nd fast MA bar
//---- handles for indicators
int MA_handle_fast; / / pointers to the fast iMA indicator
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//- - - creating a pointer to an iMA indicator object
MA_handle_fast = iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE); / / fast iMA
return(0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void onTick()
{
//- - - filling the MA [] array with the current values of the iMA indicator
/ / - - - 100 CopyBuffer elements will be written to the array
(MA_handle_fast,0,0,20, MA15_fast);
/ / - - - setting the indexing order of the MA[] array as in MQL4
ArraySetAsSeries(MA15_fast,true);
/ / - - - and then do whatever you want with this data, for example:
/* if(MA[0]>MA[1])
{
//--- performing some operations
}*/
Comment ("MA_1 = "+DoubleToString(MA15_fast[15],_Digits));
return;
}
1006293
Good day to all who answered, and to all forumchanam. I was completely confused, and decided to re-take the standard code and start to understand again. I output the value of the indicator value, and according to the idea it should coincide with the closing of the candle that I specified (in my case,the 10th bar), but I look at the value of the bar and it does not match. I don’t understand what the error is, where does it get this Close value from ??? I just just started learning mql5 and want to do a simple moving average intersection. But to do this, you need to get the values of the moving averages. And in my case, some gibberish turns out! Of course, I understand that I can’t do it properly. Tell me who knows what the reason is?! Thank you all in advance for your answers.
//---- indicator buffers
double MA []; / / array for the iMA indicator
//---- handles for indicators
int MA_handle; / / pointer to the iMA indicator
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
Comment(" ");
/ / - - - creating a pointer to an iMA indicator object
MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);
/ / - - - if an error occurred when creating the object, then output the message
if(MA_handle<0)
{
Print("iMA object not created: MA_handle= ",INVALID_HANDLE);
Print("Execution error=",GetLastError());
/ / - - - forced program termination
return(-1);
}
return(0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- fill the array MA[] current values of the indicator iMA
/ / in the array will be written 100 items, and if there is
//--- error stop execution of further operations
if(CopyBuffer(MA_handle,0,0,100,MA)<=0) return;
/ / - - - setting the indexing order of the MA[] array as in
the ArraySetAsSeries timeseries(MA,true);
Comment("MA_1 = "+DoubleToString(MA[10],_Digits));
/ / - - - and then do whatever you want with this data
}
Here, for example, I run the code on EURUSD, H1 and I output the value MA_1 = 1.21170, I look at the destination of the 10th bar, Close 21.21261, and the idea should be the closing of the 10-bar 1.21170, or am I confusing something? I'm telling you, you're already confused!
alexandrim
OnInit – properties of the indicator, not the code itself.
elenavvt
To avoid confusion, I usually create a handle for each parameter, so it’s easier, and then just match the values of one and the other. You have an error in the enumeration of the handle parameters, please review it in accordance with the help