I just found out how to get a iMA from a different period.
You need to use 2 chars, one for the current period, and 1 for the 2nd period.
When I left a 4 hour chart open, EMA( PERIOD_H4, 20, 0, PRICE_CLOSE, 10); -> it worked
When I just used a 15 min chart and did EMA( PERIOD_H4, 20, 0, PRICE_CLOSE, 10); -> it failed
MAJOR BUG???? or Design flaw????
Obviously I could go back and calculate the EMA, but that defeats the purpose
So you cannot get iMA from different Periods unless the chart for that period is open.
I am not doing error checking here, I just put some break points
Do that error checking first, so you have valid argument.
MQL5 Reference > Timeseries and Indicators access > CopyBuffer
Note
When requesting data from the indicator, if requested timeseries are not yet built or they need to be downloaded from the server, the function will immediately return -1, but the process of downloading/building will be initiated.
When requesting data from an Expert Advisor or script, downloading from the server will be initiated, if the terminal does not have these data locally, or building of a required timeseries will start, if data can be built from the local history but they are not ready yet. The function will return the amount of data that will be ready by the moment of timeout expiration.
:)
Do that error checking first, so you have valid argument.
MQL5 Reference > Timeseries and Indicators access > CopyBuffer
Note
When requesting data from the indicator, if requested timeseries are not yet built or they need to be downloaded from the server, the function will immediately return -1, but the process of downloading/building will be initiated.
When requesting data from an Expert Advisor or script, downloading from the server will be initiated, if the terminal does not have these data locally, or building of a required timeseries will start, if data can be built from the local history but they are not ready yet. The function will return the amount of data that will be ready by the moment of timeout expiration.
:)
It is not the error that throws me off. MT4 gets the time series without you having to have a 2 windows in 2 period open in order to construct the MA's
Also, if you close the window of the 2nd period and rerun my example, you will have an error, despite having already downloaded the data.
Try this:
Open USDCAD in 15 with my example and try to get an iMA value from the 4 hour timeframe. - will fail
Open USDCAD in 4H and in 15 min(2 windows) then run the example on the 15 min window - will work
The data supposedly is already downloaded as history.
Also, this is just an indicator ;-)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Every time I try to use iMA and copy buffer to copy an iMA of a different period from the one I am looking, it fails:
I am not doing error checking here, I just put some break points
Example:
I am looking at 15 min bars
EMA( _Period,20, 0, PRICE_CLOSE, 10); -> this works
EMA( PERIOD_H4, 20, 0, PRICE_CLOSE, 10); -> this fails
double EMA(ENUM_TIMEFRAMES period, int ma_period, int ma_shift, ENUM_APPLIED_PRICE price, int shift)
{
int handle=iMA(_Symbol,period,ma_period, ma_shift,
MODE_EMA, price);
double buf[];
int val = CopyBuffer(handle,0,shift,1,buf);
return(buf[0]);
}
Any hints?