How can I optimize this code? It runs very slowly during the first initialization of the indicators.
How can I optimize this code? It runs very slowly during the first initialization of the indicators. The final calculations of ergoCCIBuf and triggerBuf depend on the preceding buffers.
hini:
How can I optimize this code? It runs very slowly during the first initialization of the indicators. The final calculations of ergoCCIBuf and triggerBuf depend on the preceding buffers.
How can I optimize this code? It runs very slowly during the first initialization of the indicators. The final calculations of ergoCCIBuf and triggerBuf depend on the preceding buffers.
The problem is the design of your iMAOnArray.
The EMA algorithm itself is very efficient, but your implementation isn't utilizing it.
In short:
EMA loop requires an initialization value. On first run that is an SMA value. From there on it is the last EMA value that was calculated.
SMMA and LWMA are just variants of the EMA.
Suggested solution:
Since the EMA algorithm requires a state that depends on the series it is calculated on, I would implement it as an object/class/struct.
Same goes for SMA, use a ring buffer to efficiently calculate the SMA.
Dominik Egert #:
Thank you for your reply. I have resolved this issue. The problem indeed lies in the iMAOnArray function, which caused a lot of redundant calculations. Now I have changed to use the official library function ExponentialMAOnBuffer, which only needs to calculate once. The loading speed of the indicator has returned to normal. The problem is the design of your iMAOnArray.
The EMA algorithm itself is very efficient, but your implementation isn't utilizing it.
In short:
EMA loop requires an initialization value. On first run that is an SMA value. From there on it is the last EMA value that was calculated.
SMMA and LWMA are just variants of the EMA.
Suggested solution:
Since the EMA algorithm requires a state that depends on the series it is calculated on, I would implement it as an object/class/struct.
Same goes for SMA, use a ring buffer to efficiently calculate the SMA.
for (int i = start; i >= 0; i--) { closeBuf[i] = close[i] - close[i + 1]; closeAbsBuf[i] = MathAbs(closeBuf[i]); } ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PQ, closeBuf, emaBuf1); ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PR, emaBuf1, emaBuf2); ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PQ, closeAbsBuf, emaBuf3); ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PR, emaBuf3, emaBuf4); ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PS, emaBuf2, emaBuf5); ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PS, emaBuf4, emaBuf6); for (int i = start; i >= 0; i--) { ergoCCIBuf[i] = 500.0 * emaBuf5[i] / emaBuf6[i]; } ExponentialMAOnBuffer(rates_total, prev_calculated, 0, PT, ergoCCIBuf, emaBuf7); for (int i = start; i >= 0; i--) { triggerBuf[i] = emaBuf7[i]; }
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