
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
// 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.