Indicators: SMA(no loop)

 

SMA(no loop):

Fast way calculate Simple moving average.

SMA(no loop)

Author: Navdeep Singh

 
  1. All you've done is implement what every optimized SMA already does: SMA(i) = SMA(i-1) + (Close[i] - Close[i+period])/period.
  2. But only for SMA(close)
  3. Wrong for the first period values! I.e. for the second value you compute (Close[0] * (period-1) + Close[1] ) / period which is not the SMA of two values.
  4. And you did it with two buffers instead of one.
 
William Roeder #:
All you've done is implement what every optimized SMA already does.

(1) Okay, although I don't see the exact same implementation on code base. Do point me if it has already been done here. Thanks :)

(2) It is an example, any potential coder can add price options.

(3) It's (i==period)

(4) Would like to see how that is done

 
Navdeep Singh #:

(1) Okay, although I don't see the exact same implementation on code base. Do point me if it has already been done here. Thanks :)

(2) It is an example, any potential coder can add price options.

(3) It's (i==period)

(4) Would like to see how that is done

just for point 1 : https://www.mql5.com/en/code/24984

PS: you should revise your initial sum (it shall carry wrong sum to later bars)

Simple moving average
Simple moving average
  • www.mql5.com
Simple moving average
 
Mladen Rakic #:

just for point 1 : https://www.mql5.com/en/code/24984

PS: you should revise your initial sum (it shall carry wrong sum to later bars)

You work is great. But the point of my implementation was to eliminate loop. How would my initial calculation cause wrong future values?
 
Navdeep Singh #:
You work is great. But the point of my implementation was to eliminate loop. How would my initial calculation cause wrong future values?

You should check the code you are referenced to before commenting

As of the sum (and inheriting the wrong sum) : please do your math

all the best

 
Mladen Rakic #:

You should check the code you are referenced to before commenting

As of the sum (and inheriting the wrong sum) : please do your math

all the best

I don't see any mathematical error in this code and most importantly the values match exactly with in-built SMA. I have checked that before posting the code.
 
Navdeep Singh #:
I don't see any mathematical error in this code and most importantly the values match exactly with in-built SMA. I have checked that before posting the code.

Whatever ...

 
Good idea, thanks