This is how you access value of specific index of indicator in MQL5:
double MA(int index) { int MA_handle = iMA(Symbol(),PERIOD_H4,5,0,MODE_SMA,PRICE_CLOSE); double value[]; ArraySetAsSeries(value, true); if(CopyBuffer(MA_handle, 0, index, 1, value)<=0) { Print("Problem reading indicator value!", GetLastError()); return 0; } return value[0]; }
note: It is best to initiate indicator handle once in OnInit.
Yashar Seyyedin #:
This is how you access value of specific index of indicator in MQL5:
note: It is best to initiate indicator handle once in OnInit.
thank you so much. i also found the docs about it. i'll learn more later
![Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer](https://c.mql5.com/36/82/documentation-on-mql5-timeseries__4.png)
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
- www.mql5.com
CopyBuffer - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
i'm using this iMA docs and this smoothing on MT5 code as reference to add a simple MA 5:
but turns out the output is 10.0 and somehow this iMA is using int instead of double. i look for how to add MA, according this codebase and forum, i need to create/include MA code.
so my question is, how to add MA into my code? do i really need to do extra step instead of that simple code above (like mql4 do)? thanks