I have spent quite a while trying to get my MQl5 up to scratch I have bought a few books and am stummped over a new feature in MQL5 CopyBuffer. I have tried using it ion my code and keep finding it a nusence. In my expert advisors I have the code inside the tick function where I am I going wrong I have checked and check and cant seem to get any clear explination on the reason my code isn't working can anyone help?
Check your parameters - you can't draw moving average with 0 ma_period, and if you want it shifted left by 40 bars, you're not going to get any value from bars 0 to 39.
Also, it's more efficient if you break down this line into two parts and move out of OnTick() (since this need not be executed every tick):
int handle = iMA(_Symbol, _Period, 0, -40, MODE_EMA, PRICE_MEDIAN);
into
int handle; int OnInit() { handle = iMA(_Symbol, _Period, 0, -40, MODE_EMA, PRICE_MEDIAN); }
General rules and best pratices of the Forum. - General - MQL5 programming forum
What would you do if the shift of a iMA was negative as far as the buffer??
For your case, if you stick to -40, then change your CopyBuffer() to:
CopyBuffer(handle, 0, 40, 1, array);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have spent quite a while trying to get my MQl5 up to scratch I have bought a few books and am stummped over a new feature in MQL5 CopyBuffer. I have tried using it ion my code and keep finding it a nusence. In my expert advisors I have the code inside the tick function where I am I going wrong I have checked and check and cant seem to get any clear explination on the reason my code isn't working can anyone help?
void onTick(){
double array[];
int handle = iMA(_Symbol, _Period, 0, -40, MODE_EMA, PRICE_MEDIAN);
ArraySetAsSeries(array, true);
CopyBuffer(handle, 0, 0, 1, array);
Comment(DoubleToString(NormalizeDouble(array[0], 3)));
}