// This line should be in OnInit() and maHandle declared as global int maHandle = iMA( symbol, TF, maPeriod, xShift , maMode, priceMethod ); double X,mas[1];
If you want to use old MT4 notation for indicators in MT5 you should include my library. Otherwise your only resort is to change your code according to MT5 syntax and logic which are different to those in MT4.
// This line should be in OnInit() and maHandle declared as global int maHandle = iMA( symbol, TF, maPeriod, xShift , maMode, priceMethod ); double X,mas[1];
any tips if you want to change symbol and timeframe later in the coding? This was easy with MT4, as you could simply change the period/timeframe/symbol when you called IMA function. How can we do this now in MT5, when the handler is created in the init? Any tips for that, I'm a bit stuck with this one.
any tips if you want to change symbol and timeframe later in the coding? This was easy with MT4, as you could simply change the period/timeframe/symbol when you called IMA function. How can we do this now in MT5, when the handler is created in the init? Any tips for that, I'm a bit stuck with this one.
Thanks and regards,
Victor
Yes, that's a disadvantage in MT5. You must open a new handle all the time :)
any tips if you want to change symbol and timeframe later in the coding? This was easy with MT4, as you could simply change the period/timeframe/symbol when you called IMA function. How can we do this now in MT5, when the handler is created in the init? Any tips for that, I'm a bit stuck with this one.
Thanks and regards,
Victor
Creating the handle on OnInit() is actually not mandatory, but as most people are unable to deal with it dynamically, it's what is recommended to do.
In opposite to what is said by some, MT5 way is more flexible and advantageous, when you understand how to deal with it. Basically the principle is easy, create an handle ONCE, and use it when it's ready as much as you want. That means in practice, when you call iCustom to create and handle (or iMA...doesn't matter), don't try to use it on the next line because, most probable, the indicator is not ready yet.
If you want coding help, post your code, describe what you are trying to do and what problem you are encountering.
Thanks Alain and Bernhard! Much appreciated! Based on your input I think the issue is that I don’t add enough time for the handler before I use it. Is there any way to check the status of the handler after it is created?
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.
// This line should be in OnInit() and maHandle declared as global
int maHandle = iMA( symbol, TF, maPeriod, xShift , maMode, priceMethod );
double X,mas[1];
if(CopyBuffer(maHandle,0,xShift,1,mas)!=-1)
X=mas[1];
Thanks Alain
which line do you mean to be in OnInit() ?
and for this function
double iCloseMQL4(string symbol,ENUM_TIMEFRAMES tf,int index)
{
double Arr[];
CopyClose(symbol,tf, index, 1, Arr);
Print (symbol," high = ",Arr[0]);
return(Arr[0]);
}
Do you say it should be return(Arr[1]); ?
// This line should be in OnInit() and maHandle declared as global
int maHandle = iMA( symbol, TF, maPeriod, xShift , maMode, priceMethod );
double X,mas[1];
if(CopyBuffer(maHandle,0,xShift,1,mas)!=-1)
X=mas[1];
Alain,
any tips if you want to change symbol and timeframe later in the coding? This was easy with MT4, as you could simply change the period/timeframe/symbol when you called IMA function. How can we do this now in MT5, when the handler is created in the init? Any tips for that, I'm a bit stuck with this one.
Thanks and regards,
Victor
Alain,
any tips if you want to change symbol and timeframe later in the coding? This was easy with MT4, as you could simply change the period/timeframe/symbol when you called IMA function. How can we do this now in MT5, when the handler is created in the init? Any tips for that, I'm a bit stuck with this one.
Thanks and regards,
Victor
Yes, that's a disadvantage in MT5. You must open a new handle all the time :)
Alain,
any tips if you want to change symbol and timeframe later in the coding? This was easy with MT4, as you could simply change the period/timeframe/symbol when you called IMA function. How can we do this now in MT5, when the handler is created in the init? Any tips for that, I'm a bit stuck with this one.
Thanks and regards,
Victor
Creating the handle on OnInit() is actually not mandatory, but as most people are unable to deal with it dynamically, it's what is recommended to do.
In opposite to what is said by some, MT5 way is more flexible and advantageous, when you understand how to deal with it. Basically the principle is easy, create an handle ONCE, and use it when it's ready as much as you want. That means in practice, when you call iCustom to create and handle (or iMA...doesn't matter), don't try to use it on the next line because, most probable, the indicator is not ready yet.
If you want coding help, post your code, describe what you are trying to do and what problem you are encountering.