diff --git a/Indicators/MidPrice.cs b/Indicators/MidPrice.cs
index 684ddb88b154..23e75b3982d3 100644
--- a/Indicators/MidPrice.cs
+++ b/Indicators/MidPrice.cs
@@ -72,5 +72,15 @@ protected override decimal ComputeNextValue(IBaseDataBar input)
return (_maximum.Current.Value + _minimum.Current.Value) / 2;
}
+
+ ///
+ /// Resets this indicator to its initial state
+ ///
+ public override void Reset()
+ {
+ _maximum.Reset();
+ _minimum.Reset();
+ base.Reset();
+ }
}
}
\ No newline at end of file
diff --git a/Tests/Indicators/MidPriceTests.cs b/Tests/Indicators/MidPriceTests.cs
index ffca6d049d73..2cf1b6a635a2 100644
--- a/Tests/Indicators/MidPriceTests.cs
+++ b/Tests/Indicators/MidPriceTests.cs
@@ -13,6 +13,8 @@
* limitations under the License.
*/
+using System;
+using System.Collections.Generic;
using NUnit.Framework;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
@@ -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();
+ 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);
+ }
+ }
}
}