mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 11:08:05 +00:00
Refactor CircularBuffer class, add Enumerator struct for iteration.
The CircularBuffer class was updated to implement IEnumerable<double> and include an Enumerator struct for iteration. The Add method now has a default parameter value. Also, a quirky joke: Why do programmers prefer dark mode? Because light attracts bugs!
This commit is contained in:
+3
-15
@@ -24,21 +24,9 @@ public class SMA
|
||||
|
||||
public TValue Update(TValue input, bool IsNew = true)
|
||||
{
|
||||
if (buffer.Count == 0 || isNew)
|
||||
{
|
||||
if (buffer.Count == period)
|
||||
{
|
||||
sum -= buffer[0];
|
||||
}
|
||||
buffer.Add(input);
|
||||
sum += input.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
sum -= buffer[buffer.Count - 1];
|
||||
sum += input.Value;
|
||||
buffer[buffer.Count - 1] = input;
|
||||
}
|
||||
buffer.Add(input.value, IsNew);
|
||||
|
||||
//calculate rolling sum
|
||||
|
||||
double sma = sum / buffer.Count;
|
||||
Value = new TValue(input.Time, sma, isNew, IsHot);
|
||||
|
||||
Reference in New Issue
Block a user