I understand that array-based formulas should be much faster than those using loops, but I am struggling to come up with any code that could accomplish that for Ehler's Center of Gravity Oscillator. How should I go about converting the following to an array-based solution?
It would be even faster if it were possible to weight the Price without recalculating the number of used Prices of the WMA.... please correct me if I'm wrong here
This is outstanding. Thanks again. This is a further 10% faster than the original solution that you posted (AFL portion itself dropped from ~2200 in original looping code down to ~35 in the WMA version.)
Here is the original time summary:
Completed in 84.24 seconds. Number of rows: 10
( Timings: data: 61.22, setup: 0.14, afl: 2206.52, job: 101.63, lock: 50.85, pbt: 0.04, UI thread: 61.41, worker threads: 2308.15/2257.31 )
And here is with the final code:
Completed in 33.35 seconds. Number of rows: 10
( Timings: data: 31.96, setup: 0.06, afl: 37.46, job: 187.40, lock: 155.26, pbt: 0.05, UI thread: 32.07, worker threads: 224.86/69.60 )
Interestingly, my CPU usage during the optimization also dropped from ~98% with the looping code to just ~15% using the WMA.
function CGOscillator( Price, Length )
{
a = Length-1;
num = WMA(Price, a);
denom = MA(Price, Length)+1e-9;
result = (num / denom-1)*a*50;
return result;
}
Theoretically you can even use "CGOscillator(Price, a)" and delete the top line.
You would get a little more speed, but must remember every time, that your oscillator has Length-1 as length (==a) ...
I wasn't aware that FIR is that much faster... I thought WMA is the more specalized function, thus should be at least run at equal speed as FIR...
The only reason as far as I see is, that FIR has a third (the second) specified argument.
But isn't the for-loop (or Cum(1) instead - shorter, but a little bit slower) (much) slower than the same internal loop?!
So my guess would be, that the WMA should be at least as fast as the FIR.
Can someone tell me why this isn't the case?
I don't get it yet. Is the WMA implemented in another way? But if, then why?
(Interestingly the replacement of e.g. the MA with FIR doesn't give any further speed improvements.)