Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Indicators/MidPrice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,15 @@ protected override decimal ComputeNextValue(IBaseDataBar input)

return (_maximum.Current.Value + _minimum.Current.Value) / 2;
}

/// <summary>
/// Resets this indicator to its initial state
/// </summary>
public override void Reset()
{
_maximum.Reset();
_minimum.Reset();
base.Reset();
}
}
}
32 changes: 32 additions & 0 deletions Tests/Indicators/MidPriceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using NUnit.Framework;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
Expand All @@ -36,5 +38,35 @@ protected override string TestColumnName
{
get { return "MIDPRICE_5"; }
}

[Test]
public void ProducesTheSameValuesAfterReset()
{
var midPrice = new MidPrice(3);
var reference = new DateTime(2024, 1, 1);
var bars = new[]
{
new TradeBar { High = 110m, Low = 100m },
new TradeBar { High = 111m, Low = 101m },
new TradeBar { High = 112m, Low = 102m },
new TradeBar { High = 105m, Low = 95m }
};

var expected = new List<decimal>();
for (var i = 0; i < bars.Length; i++)
{
bars[i].Time = reference.AddDays(i);
midPrice.Update(bars[i]);
expected.Add(midPrice.Current.Value);
}

midPrice.Reset();

for (var i = 0; i < bars.Length; i++)
{
midPrice.Update(bars[i]);
Assert.AreEqual(expected[i], midPrice.Current.Value);
}
}
}
}
Loading