TSeries optimized + Unit tests
This commit is contained in:
@@ -216,7 +216,7 @@ begin
|
||||
var
|
||||
stdDev: Double;
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, Period);
|
||||
sourceData.Add(Value, Period);
|
||||
Result.MiddleBand := Double.NaN;
|
||||
Result.UpperBand := Double.NaN;
|
||||
Result.LowerBand := Double.NaN;
|
||||
@@ -240,7 +240,7 @@ begin
|
||||
Result :=
|
||||
function(const Value: Double): Double
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, Period);
|
||||
sourceData.Add(Value, Period);
|
||||
|
||||
if (sourceData.Count < Period) then
|
||||
begin
|
||||
@@ -281,7 +281,7 @@ begin
|
||||
Result := Double.NaN;
|
||||
|
||||
// Add new price to the source data array, respecting the lookback period.
|
||||
sourceData := sourceData.Add(price, Period);
|
||||
sourceData.Add(price, Period);
|
||||
|
||||
// Check if there is enough data to start the first stage of calculation.
|
||||
if (sourceData.Count >= Period) then
|
||||
@@ -292,7 +292,7 @@ begin
|
||||
|
||||
// Calculate the difference and add to the intermediate series.
|
||||
diff := 2 * wmaHalf - wmaFull;
|
||||
diffSeries := diffSeries.Add(diff, periodSqrt);
|
||||
diffSeries.Add(diff, periodSqrt);
|
||||
|
||||
// Check if there is enough intermediate data for the final calculation.
|
||||
if (diffSeries.Count >= periodSqrt) then
|
||||
@@ -352,7 +352,7 @@ begin
|
||||
gainSum, lossSum: Double;
|
||||
i: Integer;
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, Period + 1);
|
||||
sourceData.Add(Value, Period + 1);
|
||||
Result := Double.NaN;
|
||||
|
||||
if (sourceData.Count <= Period) then
|
||||
@@ -404,7 +404,7 @@ begin
|
||||
Result :=
|
||||
function(const Value: Double): Double
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, Period);
|
||||
sourceData.Add(Value, Period);
|
||||
if (sourceData.Count >= Period) then
|
||||
Result := CalculateSMA(sourceData, Period)
|
||||
else
|
||||
@@ -432,7 +432,7 @@ begin
|
||||
i: Integer;
|
||||
highestHigh, lowestLow: Double;
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, KPeriod);
|
||||
sourceData.Add(Value, KPeriod);
|
||||
Result.K := Double.NaN;
|
||||
Result.D := Double.NaN;
|
||||
|
||||
@@ -477,7 +477,7 @@ begin
|
||||
tr: Double;
|
||||
begin
|
||||
// We only need the previous bar to calculate true range.
|
||||
sourceData := sourceData.Add(Value, 2);
|
||||
sourceData.Add(Value, 2);
|
||||
|
||||
if (sourceData.Count < 2) then
|
||||
begin
|
||||
|
||||
Reference in New Issue
Block a user