Skip to content
Open
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
9 changes: 7 additions & 2 deletions Indicators/ChoppinessIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ public class ChoppinessIndex : BarIndicator, IIndicatorWarmUpPeriodProvider
/// Creates a new ChoppinessIndex indicator using the specified period and moving average type
/// </summary>
/// <param name="name">The name of this indicator</param>
/// <param name="period">The period used for rolling windows for highs and lows</param>
/// <param name="period">The period used for rolling windows for highs and lows, must be greater than one</param>
public ChoppinessIndex(string name, int period)
: base(name)
{
if (period < 2)
{
throw new ArgumentException($"Period parameter for ChoppinessIndex indicator must be greater than 1 but was {period}");
}

_period = period;

_trueRange = new TrueRange();
Expand All @@ -64,7 +69,7 @@ public ChoppinessIndex(string name, int period)
/// <summary>
/// Creates a new ChoppinessIndex indicator using the specified period
/// </summary>
/// <param name="period">The period used for rolling windows for highs and lows</param>
/// <param name="period">The period used for rolling windows for highs and lows, must be greater than one</param>
public ChoppinessIndex(int period)
: this($"CHOP({period})", period)
{
Expand Down
10 changes: 10 additions & 0 deletions Tests/Indicators/ChoppinessIndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

using System;
using NUnit.Framework;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
Expand All @@ -32,5 +33,14 @@ protected override IndicatorBase<IBaseDataBar> CreateIndicator()
protected override string TestFileName => "spy_with_chop.csv";

protected override string TestColumnName => "CHOP14";

[Test]
public void PeriodBelowMinimumThrows()
{
var period = 1;

var exception = Assert.Throws<ArgumentException>(() => new ChoppinessIndex(period));
Assert.That(exception.Message, Is.EqualTo($"Period parameter for ChoppinessIndex indicator must be greater than 1 but was {period}"));
}
}
}