From 06f5846f5e88112f46c2d37aeb02563eb732e635 Mon Sep 17 00:00:00 2001 From: Philippe Matray Date: Mon, 27 Nov 2023 16:56:37 +0100 Subject: [PATCH] refactor: some some candle initialization logic into base class --- README.md | 2 +- .../Atypical.TechnicalAnalysis.Common.md | 4 ++ ...ndleIndicator_T_.PrepareOutput(int,int).md | 27 ++++++++++ ...leIndicator_T_.ValidateIndices(int,int).md | 23 ++++++++ ...andleIndicator_T_.ValidateParameters(T).md | 17 ++++++ ...andleIndicator_T_.ValidatePriceArrays().md | 10 ++++ docs/common/CandleIndicator_T_.md | 4 ++ .../Candle2Crows/Candle2Crows.cs | 31 ++--------- .../Candle3BlackCrows/Candle3BlackCrows.cs | 16 ++---- .../Candle3Inside/Candle3Inside.cs | 16 ++---- .../Candle3LineStrike/Candle3LineStrike.cs | 16 ++---- .../Candle3Outside/Candle3Outside.cs | 16 ++---- .../Candle3StarsInSouth.cs | 18 ++----- .../Candle3WhiteSoldiers.cs | 18 ++----- .../CandleAbandonedBaby.cs | 20 ++----- .../CandleAdvanceBlock/CandleAdvanceBlock.cs | 18 ++----- .../CandleBeltHold/CandleBeltHold.cs | 16 ++---- .../CandleBreakaway/CandleBreakaway.cs | 16 ++---- .../CandleClosingMarubozu.cs | 16 ++---- .../CandleConcealBabySwallow.cs | 16 ++---- .../CandleCounterAttack.cs | 18 ++----- .../CandleDarkCloudCover.cs | 20 ++----- .../CandleDoji/CandleDoji.cs | 16 ++---- .../CandleDojiStar/CandleDojiStar.cs | 16 ++---- .../CandleDragonflyDoji.cs | 16 ++---- .../CandleEngulfing/CandleEngulfing.cs | 16 ++---- .../CandleEveningDojiStar.cs | 20 ++----- .../CandleEveningStar/CandleEveningStar.cs | 20 ++----- .../CandleGapSideSideWhite.cs | 16 ++---- .../CandleGravestoneDoji.cs | 16 ++---- .../CandleHammer/CandleHammer.cs | 16 ++---- .../CandleHangingMan/CandleHangingMan.cs | 16 ++---- .../CandleHarami/CandleHarami.cs | 16 ++---- .../CandleHaramiCross/CandleHaramiCross.cs | 16 ++---- .../CandleHighWave/CandleHighWave.cs | 16 ++---- .../CandleHikkake/CandleHikkake.cs | 16 ++---- .../CandleHikkakeMod/CandleHikkakeMod.cs | 16 ++---- .../CandleHomingPigeon/CandleHomingPigeon.cs | 16 ++---- .../CandleIdentical3Crows.cs | 18 ++----- .../CandleInNeck/CandleInNeck.cs | 16 ++---- .../CandleInvertedHammer.cs | 16 ++---- .../CandleKicking/CandleKicking.cs | 18 ++----- .../CandleKickingByLength.cs | 18 ++----- .../CandleLadderBottom/CandleLadderBottom.cs | 16 ++---- .../CandleLongLeggedDoji.cs | 16 ++---- .../CandleLongLine/CandleLongLine.cs | 16 ++---- .../CandleMarubozu/CandleMarubozu.cs | 16 ++---- .../CandleMatHold/CandleMatHold.cs | 22 +++----- .../CandleMatchingLow/CandleMatchingLow.cs | 16 ++---- .../CandleMorningDojiStar.cs | 20 ++----- .../CandleMorningStar/CandleMorningStar.cs | 20 ++----- .../CandleOnNeck/CandleOnNeck.cs | 16 ++---- .../CandlePiercing/CandlePiercing.cs | 16 ++---- .../CandleRickshawMan/CandleRickshawMan.cs | 16 ++---- .../CandleRiseFall3Methods.cs | 18 ++----- .../CandleSeparatingLines.cs | 16 ++---- .../CandleShootingStar/CandleShootingStar.cs | 16 ++---- .../CandleShortLine/CandleShortLine.cs | 16 ++---- .../CandleSpinningTop/CandleSpinningTop.cs | 16 ++---- .../CandleStalledPattern.cs | 18 ++----- .../CandleStickSandwich.cs | 16 ++---- .../CandleTakuri/CandleTakuri.cs | 16 ++---- .../CandleTasukiGap/CandleTasukiGap.cs | 16 ++---- .../CandleThrusting/CandleThrusting.cs | 16 ++---- .../CandleTristar/CandleTristar.cs | 16 ++---- .../CandleUnique3River/CandleUnique3River.cs | 16 ++---- .../CandleUpsideGap2Crows.cs | 16 ++---- .../CandleXSideGap3Methods.cs | 16 ++---- .../Abstractions/CandleIndicator.cs | 52 +++++++++++++++++++ 69 files changed, 400 insertions(+), 778 deletions(-) create mode 100644 docs/common/CandleIndicator_T_.PrepareOutput(int,int).md create mode 100644 docs/common/CandleIndicator_T_.ValidateIndices(int,int).md create mode 100644 docs/common/CandleIndicator_T_.ValidateParameters(T).md create mode 100644 docs/common/CandleIndicator_T_.ValidatePriceArrays().md diff --git a/README.md b/README.md index 9ad7430d..ea8850d8 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A modern and robust C# Technical Analysis library based on the original open-sou [![GitHub contributors](https://img.shields.io/github/contributors/phmatray/TaLibStandard)](https://github.com/phmatray/TaLibStandard/graphs/contributors) [![GitHub last commit](https://img.shields.io/github/last-commit/phmatray/TaLibStandard)](https://github.com/phmatray/TaLibStandard/commits/master) [![codecov](https://codecov.io/gh/phmatray/TaLibStandard/branch/main/graph/badge.svg?token=041C4QKW6O)](https://app.codecov.io/gh/phmatray/TaLibStandard/tree/main) -[![Codacy Badge](https://app.codacy.com/project/badge/Grade/84e2475f22a04bc1bed551f081029e82)](https://www.codacy.com/gh/phmatray/TaLibStandard/dashboard?utm_source=github.com&utm_medium=referral&utm_content=phmatray/TaLibStandard&utm_campaign=Badge_Grade) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/84e2475f22a04bc1bed551f081029e82)](https://app.codacy.com/gh/phmatray/TaLibStandard/dashboard) --- diff --git a/docs/common/Atypical.TechnicalAnalysis.Common.md b/docs/common/Atypical.TechnicalAnalysis.Common.md index 3296e15a..68fa3b7e 100644 --- a/docs/common/Atypical.TechnicalAnalysis.Common.md +++ b/docs/common/Atypical.TechnicalAnalysis.Common.md @@ -47,6 +47,10 @@ - **[IsColorOpposite(int, int)](CandleIndicator_T_.IsColorOpposite(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.IsColorOpposite(int, int)')** `Method` - **[IsColorRed(int)](CandleIndicator_T_.IsColorRed(int).md 'TechnicalAnalysis.Common.CandleIndicator.IsColorRed(int)')** `Method` - **[IsColorSame(int, int)](CandleIndicator_T_.IsColorSame(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.IsColorSame(int, int)')** `Method` + - **[PrepareOutput(int, int)](CandleIndicator_T_.PrepareOutput(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.PrepareOutput(int, int)')** `Method` Prepares the output variables. + - **[ValidateIndices(int, int)](CandleIndicator_T_.ValidateIndices(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.ValidateIndices(int, int)')** `Method` Validates the specified indices. + - **[ValidateParameters(T)](CandleIndicator_T_.ValidateParameters(T).md 'TechnicalAnalysis.Common.CandleIndicator.ValidateParameters(T)')** `Method` Validates the specified parameters. + - **[ValidatePriceArrays()](CandleIndicator_T_.ValidatePriceArrays().md 'TechnicalAnalysis.Common.CandleIndicator.ValidatePriceArrays()')** `Method` Validates the price arrays. - **[CandleIndicatorResult](CandleIndicatorResult.md 'TechnicalAnalysis.Common.CandleIndicatorResult')** `Class` Represents the result of the candlestick pattern indicator. - **[CandleIndicatorResult(RetCode, int, int, int[])](CandleIndicatorResult.CandleIndicatorResult(RetCode,int,int,int[]).md 'TechnicalAnalysis.Common.CandleIndicatorResult.CandleIndicatorResult(TechnicalAnalysis.Common.RetCode, int, int, int[])')** `Constructor` Initializes a new instance of the CandleResult class. - **[Integers](CandleIndicatorResult.Integers.md 'TechnicalAnalysis.Common.CandleIndicatorResult.Integers')** `Property` Gets the array of integers indicating the presence of the candle pattern. (values are -100, 0 or 100) diff --git a/docs/common/CandleIndicator_T_.PrepareOutput(int,int).md b/docs/common/CandleIndicator_T_.PrepareOutput(int,int).md new file mode 100644 index 00000000..1339209a --- /dev/null +++ b/docs/common/CandleIndicator_T_.PrepareOutput(int,int).md @@ -0,0 +1,27 @@ +#### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md 'Atypical.TechnicalAnalysis.Common') +### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md#TechnicalAnalysis.Common 'TechnicalAnalysis.Common').[CandleIndicator<T>](CandleIndicator_T_.md 'TechnicalAnalysis.Common.CandleIndicator') + +## CandleIndicator.PrepareOutput(int, int) Method + +Prepares the output variables. + +```csharp +protected virtual (int outBegIdx,int outNBElement,int[] outInteger) PrepareOutput(int startIdx, int endIdx); +``` +#### Parameters + + + +`startIdx` [System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32') + +The start index. + + + +`endIdx` [System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32') + +The end index. + +#### Returns +[<](https://docs.microsoft.com/en-us/dotnet/api/System.ValueTuple 'System.ValueTuple')[System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32')[,](https://docs.microsoft.com/en-us/dotnet/api/System.ValueTuple 'System.ValueTuple')[System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32')[,](https://docs.microsoft.com/en-us/dotnet/api/System.ValueTuple 'System.ValueTuple')[System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32')[[]](https://docs.microsoft.com/en-us/dotnet/api/System.Array 'System.Array')[>](https://docs.microsoft.com/en-us/dotnet/api/System.ValueTuple 'System.ValueTuple') +A tuple containing the output variables. \ No newline at end of file diff --git a/docs/common/CandleIndicator_T_.ValidateIndices(int,int).md b/docs/common/CandleIndicator_T_.ValidateIndices(int,int).md new file mode 100644 index 00000000..5bf02c03 --- /dev/null +++ b/docs/common/CandleIndicator_T_.ValidateIndices(int,int).md @@ -0,0 +1,23 @@ +#### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md 'Atypical.TechnicalAnalysis.Common') +### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md#TechnicalAnalysis.Common 'TechnicalAnalysis.Common').[CandleIndicator<T>](CandleIndicator_T_.md 'TechnicalAnalysis.Common.CandleIndicator') + +## CandleIndicator.ValidateIndices(int, int) Method + +Validates the specified indices. + +```csharp +protected virtual void ValidateIndices(ref int startIdx, ref int endIdx); +``` +#### Parameters + + + +`startIdx` [System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32') + +The start index. + + + +`endIdx` [System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32') + +The end index. \ No newline at end of file diff --git a/docs/common/CandleIndicator_T_.ValidateParameters(T).md b/docs/common/CandleIndicator_T_.ValidateParameters(T).md new file mode 100644 index 00000000..7429f4a2 --- /dev/null +++ b/docs/common/CandleIndicator_T_.ValidateParameters(T).md @@ -0,0 +1,17 @@ +#### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md 'Atypical.TechnicalAnalysis.Common') +### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md#TechnicalAnalysis.Common 'TechnicalAnalysis.Common').[CandleIndicator<T>](CandleIndicator_T_.md 'TechnicalAnalysis.Common.CandleIndicator') + +## CandleIndicator.ValidateParameters(T) Method + +Validates the specified parameters. + +```csharp +protected virtual void ValidateParameters(T penetration); +``` +#### Parameters + + + +`penetration` [T](CandleIndicator_T_.md#TechnicalAnalysis.Common.CandleIndicator_T_.T 'TechnicalAnalysis.Common.CandleIndicator.T') + +The penetration to validate. \ No newline at end of file diff --git a/docs/common/CandleIndicator_T_.ValidatePriceArrays().md b/docs/common/CandleIndicator_T_.ValidatePriceArrays().md new file mode 100644 index 00000000..b6f0f574 --- /dev/null +++ b/docs/common/CandleIndicator_T_.ValidatePriceArrays().md @@ -0,0 +1,10 @@ +#### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md 'Atypical.TechnicalAnalysis.Common') +### [TechnicalAnalysis.Common](Atypical.TechnicalAnalysis.Common.md#TechnicalAnalysis.Common 'TechnicalAnalysis.Common').[CandleIndicator<T>](CandleIndicator_T_.md 'TechnicalAnalysis.Common.CandleIndicator') + +## CandleIndicator.ValidatePriceArrays() Method + +Validates the price arrays. + +```csharp +protected virtual void ValidatePriceArrays(); +``` \ No newline at end of file diff --git a/docs/common/CandleIndicator_T_.md b/docs/common/CandleIndicator_T_.md index fdef975b..34e2e080 100644 --- a/docs/common/CandleIndicator_T_.md +++ b/docs/common/CandleIndicator_T_.md @@ -51,3 +51,7 @@ Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.O | [IsColorOpposite(int, int)](CandleIndicator_T_.IsColorOpposite(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.IsColorOpposite(int, int)') | | | [IsColorRed(int)](CandleIndicator_T_.IsColorRed(int).md 'TechnicalAnalysis.Common.CandleIndicator.IsColorRed(int)') | | | [IsColorSame(int, int)](CandleIndicator_T_.IsColorSame(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.IsColorSame(int, int)') | | +| [PrepareOutput(int, int)](CandleIndicator_T_.PrepareOutput(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.PrepareOutput(int, int)') | Prepares the output variables. | +| [ValidateIndices(int, int)](CandleIndicator_T_.ValidateIndices(int,int).md 'TechnicalAnalysis.Common.CandleIndicator.ValidateIndices(int, int)') | Validates the specified indices. | +| [ValidateParameters(T)](CandleIndicator_T_.ValidateParameters(T).md 'TechnicalAnalysis.Common.CandleIndicator.ValidateParameters(T)') | Validates the specified parameters. | +| [ValidatePriceArrays()](CandleIndicator_T_.ValidatePriceArrays().md 'TechnicalAnalysis.Common.CandleIndicator.ValidatePriceArrays()') | Validates the price arrays. | diff --git a/src/TechnicalAnalysis.Candles/Candle2Crows/Candle2Crows.cs b/src/TechnicalAnalysis.Candles/Candle2Crows/Candle2Crows.cs index 3f1d8b47..e99e46d1 100644 --- a/src/TechnicalAnalysis.Candles/Candle2Crows/Candle2Crows.cs +++ b/src/TechnicalAnalysis.Candles/Candle2Crows/Candle2Crows.cs @@ -20,19 +20,6 @@ public class Candle2Crows(in T[] open, in T[] high, in T[] low, in T[] close) { private T _bodyLongPeriodTotal = T.Zero; - private void ValidateIndices(ref int startIdx, ref int endIdx) - { - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - } - /// /// Computes the indicator. /// @@ -42,19 +29,11 @@ private void ValidateIndices(ref int startIdx, ref int endIdx) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/Candle3BlackCrows/Candle3BlackCrows.cs b/src/TechnicalAnalysis.Candles/Candle3BlackCrows/Candle3BlackCrows.cs index f823a098..f73343f4 100644 --- a/src/TechnicalAnalysis.Candles/Candle3BlackCrows/Candle3BlackCrows.cs +++ b/src/TechnicalAnalysis.Candles/Candle3BlackCrows/Candle3BlackCrows.cs @@ -29,19 +29,11 @@ public class Candle3BlackCrows(in T[] open, in T[] high, in T[] low, in T[] c public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/Candle3Inside/Candle3Inside.cs b/src/TechnicalAnalysis.Candles/Candle3Inside/Candle3Inside.cs index be4361a1..1db47180 100644 --- a/src/TechnicalAnalysis.Candles/Candle3Inside/Candle3Inside.cs +++ b/src/TechnicalAnalysis.Candles/Candle3Inside/Candle3Inside.cs @@ -30,19 +30,11 @@ public class Candle3Inside(in T[] open, in T[] high, in T[] low, in T[] close public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/Candle3LineStrike/Candle3LineStrike.cs b/src/TechnicalAnalysis.Candles/Candle3LineStrike/Candle3LineStrike.cs index 2a487af1..bf47726c 100644 --- a/src/TechnicalAnalysis.Candles/Candle3LineStrike/Candle3LineStrike.cs +++ b/src/TechnicalAnalysis.Candles/Candle3LineStrike/Candle3LineStrike.cs @@ -29,19 +29,11 @@ public class Candle3LineStrike(in T[] open, in T[] high, in T[] low, in T[] c public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/Candle3Outside/Candle3Outside.cs b/src/TechnicalAnalysis.Candles/Candle3Outside/Candle3Outside.cs index 9a1c7895..a32f10e7 100644 --- a/src/TechnicalAnalysis.Candles/Candle3Outside/Candle3Outside.cs +++ b/src/TechnicalAnalysis.Candles/Candle3Outside/Candle3Outside.cs @@ -27,19 +27,11 @@ public class Candle3Outside(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/Candle3StarsInSouth/Candle3StarsInSouth.cs b/src/TechnicalAnalysis.Candles/Candle3StarsInSouth/Candle3StarsInSouth.cs index b9fb6d36..2afa607f 100644 --- a/src/TechnicalAnalysis.Candles/Candle3StarsInSouth/Candle3StarsInSouth.cs +++ b/src/TechnicalAnalysis.Candles/Candle3StarsInSouth/Candle3StarsInSouth.cs @@ -32,19 +32,11 @@ public class Candle3StarsInSouth(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/Candle3WhiteSoldiers/Candle3WhiteSoldiers.cs b/src/TechnicalAnalysis.Candles/Candle3WhiteSoldiers/Candle3WhiteSoldiers.cs index 5e974780..a6923ff1 100644 --- a/src/TechnicalAnalysis.Candles/Candle3WhiteSoldiers/Candle3WhiteSoldiers.cs +++ b/src/TechnicalAnalysis.Candles/Candle3WhiteSoldiers/Candle3WhiteSoldiers.cs @@ -32,19 +32,11 @@ public class Candle3WhiteSoldiers(in T[] open, in T[] high, in T[] low, in T[ public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleAbandonedBaby/CandleAbandonedBaby.cs b/src/TechnicalAnalysis.Candles/CandleAbandonedBaby/CandleAbandonedBaby.cs index 59dfc0a5..e006d85a 100644 --- a/src/TechnicalAnalysis.Candles/CandleAbandonedBaby/CandleAbandonedBaby.cs +++ b/src/TechnicalAnalysis.Candles/CandleAbandonedBaby/CandleAbandonedBaby.cs @@ -35,22 +35,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleAdvanceBlock/CandleAdvanceBlock.cs b/src/TechnicalAnalysis.Candles/CandleAdvanceBlock/CandleAdvanceBlock.cs index 10f15752..212711a5 100644 --- a/src/TechnicalAnalysis.Candles/CandleAdvanceBlock/CandleAdvanceBlock.cs +++ b/src/TechnicalAnalysis.Candles/CandleAdvanceBlock/CandleAdvanceBlock.cs @@ -33,19 +33,11 @@ public class CandleAdvanceBlock(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleBeltHold/CandleBeltHold.cs b/src/TechnicalAnalysis.Candles/CandleBeltHold/CandleBeltHold.cs index e1ab7fcc..0abf6719 100644 --- a/src/TechnicalAnalysis.Candles/CandleBeltHold/CandleBeltHold.cs +++ b/src/TechnicalAnalysis.Candles/CandleBeltHold/CandleBeltHold.cs @@ -30,19 +30,11 @@ public class CandleBeltHold(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleBreakaway/CandleBreakaway.cs b/src/TechnicalAnalysis.Candles/CandleBreakaway/CandleBreakaway.cs index b83c4d1e..171bbc23 100644 --- a/src/TechnicalAnalysis.Candles/CandleBreakaway/CandleBreakaway.cs +++ b/src/TechnicalAnalysis.Candles/CandleBreakaway/CandleBreakaway.cs @@ -29,19 +29,11 @@ public class CandleBreakaway(in T[] open, in T[] high, in T[] low, in T[] clo public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleClosingMarubozu/CandleClosingMarubozu.cs b/src/TechnicalAnalysis.Candles/CandleClosingMarubozu/CandleClosingMarubozu.cs index b5d4e2d9..4348872a 100644 --- a/src/TechnicalAnalysis.Candles/CandleClosingMarubozu/CandleClosingMarubozu.cs +++ b/src/TechnicalAnalysis.Candles/CandleClosingMarubozu/CandleClosingMarubozu.cs @@ -30,19 +30,11 @@ public class CandleClosingMarubozu(in T[] open, in T[] high, in T[] low, in T public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleConcealBabySwallow/CandleConcealBabySwallow.cs b/src/TechnicalAnalysis.Candles/CandleConcealBabySwallow/CandleConcealBabySwallow.cs index b228e868..62224ac1 100644 --- a/src/TechnicalAnalysis.Candles/CandleConcealBabySwallow/CandleConcealBabySwallow.cs +++ b/src/TechnicalAnalysis.Candles/CandleConcealBabySwallow/CandleConcealBabySwallow.cs @@ -29,19 +29,11 @@ public class CandleConcealBabySwallow(in T[] open, in T[] high, in T[] low, i public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleCounterAttack/CandleCounterAttack.cs b/src/TechnicalAnalysis.Candles/CandleCounterAttack/CandleCounterAttack.cs index e11981cd..98fc2e0b 100644 --- a/src/TechnicalAnalysis.Candles/CandleCounterAttack/CandleCounterAttack.cs +++ b/src/TechnicalAnalysis.Candles/CandleCounterAttack/CandleCounterAttack.cs @@ -30,19 +30,11 @@ public class CandleCounterAttack(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleDarkCloudCover/CandleDarkCloudCover.cs b/src/TechnicalAnalysis.Candles/CandleDarkCloudCover/CandleDarkCloudCover.cs index e98f6d9e..4fb4db5b 100644 --- a/src/TechnicalAnalysis.Candles/CandleDarkCloudCover/CandleDarkCloudCover.cs +++ b/src/TechnicalAnalysis.Candles/CandleDarkCloudCover/CandleDarkCloudCover.cs @@ -33,22 +33,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleDoji/CandleDoji.cs b/src/TechnicalAnalysis.Candles/CandleDoji/CandleDoji.cs index 75c2b1d9..62f70057 100644 --- a/src/TechnicalAnalysis.Candles/CandleDoji/CandleDoji.cs +++ b/src/TechnicalAnalysis.Candles/CandleDoji/CandleDoji.cs @@ -29,19 +29,11 @@ public class CandleDoji(in T[] open, in T[] high, in T[] low, in T[] close) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleDojiStar/CandleDojiStar.cs b/src/TechnicalAnalysis.Candles/CandleDojiStar/CandleDojiStar.cs index ea20956e..44919940 100644 --- a/src/TechnicalAnalysis.Candles/CandleDojiStar/CandleDojiStar.cs +++ b/src/TechnicalAnalysis.Candles/CandleDojiStar/CandleDojiStar.cs @@ -30,19 +30,11 @@ public class CandleDojiStar(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleDragonflyDoji/CandleDragonflyDoji.cs b/src/TechnicalAnalysis.Candles/CandleDragonflyDoji/CandleDragonflyDoji.cs index 4337d0e3..2becc0f7 100644 --- a/src/TechnicalAnalysis.Candles/CandleDragonflyDoji/CandleDragonflyDoji.cs +++ b/src/TechnicalAnalysis.Candles/CandleDragonflyDoji/CandleDragonflyDoji.cs @@ -30,19 +30,11 @@ public class CandleDragonflyDoji(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleEngulfing/CandleEngulfing.cs b/src/TechnicalAnalysis.Candles/CandleEngulfing/CandleEngulfing.cs index b2203607..d9fa0c0a 100644 --- a/src/TechnicalAnalysis.Candles/CandleEngulfing/CandleEngulfing.cs +++ b/src/TechnicalAnalysis.Candles/CandleEngulfing/CandleEngulfing.cs @@ -27,19 +27,11 @@ public class CandleEngulfing(in T[] open, in T[] high, in T[] low, in T[] clo public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleEveningDojiStar/CandleEveningDojiStar.cs b/src/TechnicalAnalysis.Candles/CandleEveningDojiStar/CandleEveningDojiStar.cs index 8ed26c64..87d159e5 100644 --- a/src/TechnicalAnalysis.Candles/CandleEveningDojiStar/CandleEveningDojiStar.cs +++ b/src/TechnicalAnalysis.Candles/CandleEveningDojiStar/CandleEveningDojiStar.cs @@ -35,22 +35,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleEveningStar/CandleEveningStar.cs b/src/TechnicalAnalysis.Candles/CandleEveningStar/CandleEveningStar.cs index b1fee640..e57b7844 100644 --- a/src/TechnicalAnalysis.Candles/CandleEveningStar/CandleEveningStar.cs +++ b/src/TechnicalAnalysis.Candles/CandleEveningStar/CandleEveningStar.cs @@ -35,22 +35,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleGapSideSideWhite/CandleGapSideSideWhite.cs b/src/TechnicalAnalysis.Candles/CandleGapSideSideWhite/CandleGapSideSideWhite.cs index f90e2558..036ba875 100644 --- a/src/TechnicalAnalysis.Candles/CandleGapSideSideWhite/CandleGapSideSideWhite.cs +++ b/src/TechnicalAnalysis.Candles/CandleGapSideSideWhite/CandleGapSideSideWhite.cs @@ -30,19 +30,11 @@ public class CandleGapSideSideWhite(in T[] open, in T[] high, in T[] low, in public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleGravestoneDoji/CandleGravestoneDoji.cs b/src/TechnicalAnalysis.Candles/CandleGravestoneDoji/CandleGravestoneDoji.cs index 358dbc05..8e000b81 100644 --- a/src/TechnicalAnalysis.Candles/CandleGravestoneDoji/CandleGravestoneDoji.cs +++ b/src/TechnicalAnalysis.Candles/CandleGravestoneDoji/CandleGravestoneDoji.cs @@ -30,19 +30,11 @@ public class CandleGravestoneDoji(in T[] open, in T[] high, in T[] low, in T[ public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHammer/CandleHammer.cs b/src/TechnicalAnalysis.Candles/CandleHammer/CandleHammer.cs index 69b45859..f33a6aa8 100644 --- a/src/TechnicalAnalysis.Candles/CandleHammer/CandleHammer.cs +++ b/src/TechnicalAnalysis.Candles/CandleHammer/CandleHammer.cs @@ -32,19 +32,11 @@ public class CandleHammer(in T[] open, in T[] high, in T[] low, in T[] close) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHangingMan/CandleHangingMan.cs b/src/TechnicalAnalysis.Candles/CandleHangingMan/CandleHangingMan.cs index 71e91dbc..5770535f 100644 --- a/src/TechnicalAnalysis.Candles/CandleHangingMan/CandleHangingMan.cs +++ b/src/TechnicalAnalysis.Candles/CandleHangingMan/CandleHangingMan.cs @@ -32,19 +32,11 @@ public class CandleHangingMan(in T[] open, in T[] high, in T[] low, in T[] cl public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHarami/CandleHarami.cs b/src/TechnicalAnalysis.Candles/CandleHarami/CandleHarami.cs index d8861cd3..278c80d6 100644 --- a/src/TechnicalAnalysis.Candles/CandleHarami/CandleHarami.cs +++ b/src/TechnicalAnalysis.Candles/CandleHarami/CandleHarami.cs @@ -30,19 +30,11 @@ public class CandleHarami(in T[] open, in T[] high, in T[] low, in T[] close) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHaramiCross/CandleHaramiCross.cs b/src/TechnicalAnalysis.Candles/CandleHaramiCross/CandleHaramiCross.cs index 149e5457..7c941d3e 100644 --- a/src/TechnicalAnalysis.Candles/CandleHaramiCross/CandleHaramiCross.cs +++ b/src/TechnicalAnalysis.Candles/CandleHaramiCross/CandleHaramiCross.cs @@ -30,19 +30,11 @@ public class CandleHaramiCross(in T[] open, in T[] high, in T[] low, in T[] c public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHighWave/CandleHighWave.cs b/src/TechnicalAnalysis.Candles/CandleHighWave/CandleHighWave.cs index 2d5b9ac7..729cf7f6 100644 --- a/src/TechnicalAnalysis.Candles/CandleHighWave/CandleHighWave.cs +++ b/src/TechnicalAnalysis.Candles/CandleHighWave/CandleHighWave.cs @@ -30,19 +30,11 @@ public class CandleHighWave(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHikkake/CandleHikkake.cs b/src/TechnicalAnalysis.Candles/CandleHikkake/CandleHikkake.cs index a23290ae..e938ff8a 100644 --- a/src/TechnicalAnalysis.Candles/CandleHikkake/CandleHikkake.cs +++ b/src/TechnicalAnalysis.Candles/CandleHikkake/CandleHikkake.cs @@ -27,19 +27,11 @@ public class CandleHikkake(in T[] open, in T[] high, in T[] low, in T[] close public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHikkakeMod/CandleHikkakeMod.cs b/src/TechnicalAnalysis.Candles/CandleHikkakeMod/CandleHikkakeMod.cs index ad3d532c..9e41b2b8 100644 --- a/src/TechnicalAnalysis.Candles/CandleHikkakeMod/CandleHikkakeMod.cs +++ b/src/TechnicalAnalysis.Candles/CandleHikkakeMod/CandleHikkakeMod.cs @@ -31,19 +31,11 @@ public class CandleHikkakeMod(in T[] open, in T[] high, in T[] low, in T[] cl public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleHomingPigeon/CandleHomingPigeon.cs b/src/TechnicalAnalysis.Candles/CandleHomingPigeon/CandleHomingPigeon.cs index 6f1b339b..cd112ecf 100644 --- a/src/TechnicalAnalysis.Candles/CandleHomingPigeon/CandleHomingPigeon.cs +++ b/src/TechnicalAnalysis.Candles/CandleHomingPigeon/CandleHomingPigeon.cs @@ -30,19 +30,11 @@ public class CandleHomingPigeon(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleIdentical3Crows/CandleIdentical3Crows.cs b/src/TechnicalAnalysis.Candles/CandleIdentical3Crows/CandleIdentical3Crows.cs index e892cdca..f0b8a466 100644 --- a/src/TechnicalAnalysis.Candles/CandleIdentical3Crows/CandleIdentical3Crows.cs +++ b/src/TechnicalAnalysis.Candles/CandleIdentical3Crows/CandleIdentical3Crows.cs @@ -30,19 +30,11 @@ public class CandleIdentical3Crows(in T[] open, in T[] high, in T[] low, in T public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleInNeck/CandleInNeck.cs b/src/TechnicalAnalysis.Candles/CandleInNeck/CandleInNeck.cs index e36d0016..66ad8fce 100644 --- a/src/TechnicalAnalysis.Candles/CandleInNeck/CandleInNeck.cs +++ b/src/TechnicalAnalysis.Candles/CandleInNeck/CandleInNeck.cs @@ -30,19 +30,11 @@ public class CandleInNeck(in T[] open, in T[] high, in T[] low, in T[] close) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleInvertedHammer/CandleInvertedHammer.cs b/src/TechnicalAnalysis.Candles/CandleInvertedHammer/CandleInvertedHammer.cs index 2488a8d8..60e22de7 100644 --- a/src/TechnicalAnalysis.Candles/CandleInvertedHammer/CandleInvertedHammer.cs +++ b/src/TechnicalAnalysis.Candles/CandleInvertedHammer/CandleInvertedHammer.cs @@ -31,19 +31,11 @@ public class CandleInvertedHammer(in T[] open, in T[] high, in T[] low, in T[ public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleKicking/CandleKicking.cs b/src/TechnicalAnalysis.Candles/CandleKicking/CandleKicking.cs index 75777dac..d5b5542a 100644 --- a/src/TechnicalAnalysis.Candles/CandleKicking/CandleKicking.cs +++ b/src/TechnicalAnalysis.Candles/CandleKicking/CandleKicking.cs @@ -30,19 +30,11 @@ public class CandleKicking(in T[] open, in T[] high, in T[] low, in T[] close public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleKickingByLength/CandleKickingByLength.cs b/src/TechnicalAnalysis.Candles/CandleKickingByLength/CandleKickingByLength.cs index df64ad84..0a5bde5e 100644 --- a/src/TechnicalAnalysis.Candles/CandleKickingByLength/CandleKickingByLength.cs +++ b/src/TechnicalAnalysis.Candles/CandleKickingByLength/CandleKickingByLength.cs @@ -30,19 +30,11 @@ public class CandleKickingByLength(in T[] open, in T[] high, in T[] low, in T public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleLadderBottom/CandleLadderBottom.cs b/src/TechnicalAnalysis.Candles/CandleLadderBottom/CandleLadderBottom.cs index 7f5b1b0f..1f553840 100644 --- a/src/TechnicalAnalysis.Candles/CandleLadderBottom/CandleLadderBottom.cs +++ b/src/TechnicalAnalysis.Candles/CandleLadderBottom/CandleLadderBottom.cs @@ -29,19 +29,11 @@ public class CandleLadderBottom(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleLongLeggedDoji/CandleLongLeggedDoji.cs b/src/TechnicalAnalysis.Candles/CandleLongLeggedDoji/CandleLongLeggedDoji.cs index 48a338d2..20bd43ff 100644 --- a/src/TechnicalAnalysis.Candles/CandleLongLeggedDoji/CandleLongLeggedDoji.cs +++ b/src/TechnicalAnalysis.Candles/CandleLongLeggedDoji/CandleLongLeggedDoji.cs @@ -30,19 +30,11 @@ public class CandleLongLeggedDoji(in T[] open, in T[] high, in T[] low, in T[ public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleLongLine/CandleLongLine.cs b/src/TechnicalAnalysis.Candles/CandleLongLine/CandleLongLine.cs index fd1a7129..218cca39 100644 --- a/src/TechnicalAnalysis.Candles/CandleLongLine/CandleLongLine.cs +++ b/src/TechnicalAnalysis.Candles/CandleLongLine/CandleLongLine.cs @@ -30,19 +30,11 @@ public class CandleLongLine(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleMarubozu/CandleMarubozu.cs b/src/TechnicalAnalysis.Candles/CandleMarubozu/CandleMarubozu.cs index 74c8c80f..fca2e190 100644 --- a/src/TechnicalAnalysis.Candles/CandleMarubozu/CandleMarubozu.cs +++ b/src/TechnicalAnalysis.Candles/CandleMarubozu/CandleMarubozu.cs @@ -30,19 +30,11 @@ public class CandleMarubozu(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleMatHold/CandleMatHold.cs b/src/TechnicalAnalysis.Candles/CandleMatHold/CandleMatHold.cs index 46f445e0..9b864116 100644 --- a/src/TechnicalAnalysis.Candles/CandleMatHold/CandleMatHold.cs +++ b/src/TechnicalAnalysis.Candles/CandleMatHold/CandleMatHold.cs @@ -33,22 +33,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleMatchingLow/CandleMatchingLow.cs b/src/TechnicalAnalysis.Candles/CandleMatchingLow/CandleMatchingLow.cs index f3822e8b..dd374d23 100644 --- a/src/TechnicalAnalysis.Candles/CandleMatchingLow/CandleMatchingLow.cs +++ b/src/TechnicalAnalysis.Candles/CandleMatchingLow/CandleMatchingLow.cs @@ -29,19 +29,11 @@ public class CandleMatchingLow(in T[] open, in T[] high, in T[] low, in T[] c public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleMorningDojiStar/CandleMorningDojiStar.cs b/src/TechnicalAnalysis.Candles/CandleMorningDojiStar/CandleMorningDojiStar.cs index 9d8e0400..3da22822 100644 --- a/src/TechnicalAnalysis.Candles/CandleMorningDojiStar/CandleMorningDojiStar.cs +++ b/src/TechnicalAnalysis.Candles/CandleMorningDojiStar/CandleMorningDojiStar.cs @@ -35,22 +35,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleMorningStar/CandleMorningStar.cs b/src/TechnicalAnalysis.Candles/CandleMorningStar/CandleMorningStar.cs index 869542ce..3e31a823 100644 --- a/src/TechnicalAnalysis.Candles/CandleMorningStar/CandleMorningStar.cs +++ b/src/TechnicalAnalysis.Candles/CandleMorningStar/CandleMorningStar.cs @@ -35,22 +35,12 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra _penetration = optInPenetration; // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); - - // Verify parameters - ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); + ValidateParameters(optInPenetration); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleOnNeck/CandleOnNeck.cs b/src/TechnicalAnalysis.Candles/CandleOnNeck/CandleOnNeck.cs index 9dc9a658..9ed6a74d 100644 --- a/src/TechnicalAnalysis.Candles/CandleOnNeck/CandleOnNeck.cs +++ b/src/TechnicalAnalysis.Candles/CandleOnNeck/CandleOnNeck.cs @@ -30,19 +30,11 @@ public class CandleOnNeck(in T[] open, in T[] high, in T[] low, in T[] close) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandlePiercing/CandlePiercing.cs b/src/TechnicalAnalysis.Candles/CandlePiercing/CandlePiercing.cs index 6963ddb8..4a633761 100644 --- a/src/TechnicalAnalysis.Candles/CandlePiercing/CandlePiercing.cs +++ b/src/TechnicalAnalysis.Candles/CandlePiercing/CandlePiercing.cs @@ -29,19 +29,11 @@ public class CandlePiercing(in T[] open, in T[] high, in T[] low, in T[] clos public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleRickshawMan/CandleRickshawMan.cs b/src/TechnicalAnalysis.Candles/CandleRickshawMan/CandleRickshawMan.cs index 8e40ee45..08c609ce 100644 --- a/src/TechnicalAnalysis.Candles/CandleRickshawMan/CandleRickshawMan.cs +++ b/src/TechnicalAnalysis.Candles/CandleRickshawMan/CandleRickshawMan.cs @@ -31,19 +31,11 @@ public class CandleRickshawMan(in T[] open, in T[] high, in T[] low, in T[] c public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleRiseFall3Methods/CandleRiseFall3Methods.cs b/src/TechnicalAnalysis.Candles/CandleRiseFall3Methods/CandleRiseFall3Methods.cs index 83eea861..e28a9598 100644 --- a/src/TechnicalAnalysis.Candles/CandleRiseFall3Methods/CandleRiseFall3Methods.cs +++ b/src/TechnicalAnalysis.Candles/CandleRiseFall3Methods/CandleRiseFall3Methods.cs @@ -29,19 +29,11 @@ public class CandleRiseFall3Methods(in T[] open, in T[] high, in T[] low, in public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleSeparatingLines/CandleSeparatingLines.cs b/src/TechnicalAnalysis.Candles/CandleSeparatingLines/CandleSeparatingLines.cs index a249361d..92257374 100644 --- a/src/TechnicalAnalysis.Candles/CandleSeparatingLines/CandleSeparatingLines.cs +++ b/src/TechnicalAnalysis.Candles/CandleSeparatingLines/CandleSeparatingLines.cs @@ -31,19 +31,11 @@ public class CandleSeparatingLines(in T[] open, in T[] high, in T[] low, in T public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleShootingStar/CandleShootingStar.cs b/src/TechnicalAnalysis.Candles/CandleShootingStar/CandleShootingStar.cs index 71e75a75..eaeafb27 100644 --- a/src/TechnicalAnalysis.Candles/CandleShootingStar/CandleShootingStar.cs +++ b/src/TechnicalAnalysis.Candles/CandleShootingStar/CandleShootingStar.cs @@ -31,19 +31,11 @@ public class CandleShootingStar(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleShortLine/CandleShortLine.cs b/src/TechnicalAnalysis.Candles/CandleShortLine/CandleShortLine.cs index d372ce56..b7bdc6ba 100644 --- a/src/TechnicalAnalysis.Candles/CandleShortLine/CandleShortLine.cs +++ b/src/TechnicalAnalysis.Candles/CandleShortLine/CandleShortLine.cs @@ -30,19 +30,11 @@ public class CandleShortLine(in T[] open, in T[] high, in T[] low, in T[] clo public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleSpinningTop/CandleSpinningTop.cs b/src/TechnicalAnalysis.Candles/CandleSpinningTop/CandleSpinningTop.cs index 784ca552..44c9bf9d 100644 --- a/src/TechnicalAnalysis.Candles/CandleSpinningTop/CandleSpinningTop.cs +++ b/src/TechnicalAnalysis.Candles/CandleSpinningTop/CandleSpinningTop.cs @@ -29,19 +29,11 @@ public class CandleSpinningTop(in T[] open, in T[] high, in T[] low, in T[] c public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleStalledPattern/CandleStalledPattern.cs b/src/TechnicalAnalysis.Candles/CandleStalledPattern/CandleStalledPattern.cs index 81b7a9c5..73649d6b 100644 --- a/src/TechnicalAnalysis.Candles/CandleStalledPattern/CandleStalledPattern.cs +++ b/src/TechnicalAnalysis.Candles/CandleStalledPattern/CandleStalledPattern.cs @@ -32,19 +32,11 @@ public class CandleStalledPattern(in T[] open, in T[] high, in T[] low, in T[ public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; - - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleStickSandwich/CandleStickSandwich.cs b/src/TechnicalAnalysis.Candles/CandleStickSandwich/CandleStickSandwich.cs index d2e4a8dd..f4beba38 100644 --- a/src/TechnicalAnalysis.Candles/CandleStickSandwich/CandleStickSandwich.cs +++ b/src/TechnicalAnalysis.Candles/CandleStickSandwich/CandleStickSandwich.cs @@ -29,19 +29,11 @@ public class CandleStickSandwich(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleTakuri/CandleTakuri.cs b/src/TechnicalAnalysis.Candles/CandleTakuri/CandleTakuri.cs index d9e748ed..35508cab 100644 --- a/src/TechnicalAnalysis.Candles/CandleTakuri/CandleTakuri.cs +++ b/src/TechnicalAnalysis.Candles/CandleTakuri/CandleTakuri.cs @@ -31,19 +31,11 @@ public class CandleTakuri(in T[] open, in T[] high, in T[] low, in T[] close) public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleTasukiGap/CandleTasukiGap.cs b/src/TechnicalAnalysis.Candles/CandleTasukiGap/CandleTasukiGap.cs index 21fb577b..a6f909ac 100644 --- a/src/TechnicalAnalysis.Candles/CandleTasukiGap/CandleTasukiGap.cs +++ b/src/TechnicalAnalysis.Candles/CandleTasukiGap/CandleTasukiGap.cs @@ -29,19 +29,11 @@ public class CandleTasukiGap(in T[] open, in T[] high, in T[] low, in T[] clo public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleThrusting/CandleThrusting.cs b/src/TechnicalAnalysis.Candles/CandleThrusting/CandleThrusting.cs index 5f8dbb66..5bc66eea 100644 --- a/src/TechnicalAnalysis.Candles/CandleThrusting/CandleThrusting.cs +++ b/src/TechnicalAnalysis.Candles/CandleThrusting/CandleThrusting.cs @@ -30,19 +30,11 @@ public class CandleThrusting(in T[] open, in T[] high, in T[] low, in T[] clo public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleTristar/CandleTristar.cs b/src/TechnicalAnalysis.Candles/CandleTristar/CandleTristar.cs index f350c1ab..dd8a9ee4 100644 --- a/src/TechnicalAnalysis.Candles/CandleTristar/CandleTristar.cs +++ b/src/TechnicalAnalysis.Candles/CandleTristar/CandleTristar.cs @@ -29,19 +29,11 @@ public class CandleTristar(in T[] open, in T[] high, in T[] low, in T[] close public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleUnique3River/CandleUnique3River.cs b/src/TechnicalAnalysis.Candles/CandleUnique3River/CandleUnique3River.cs index 2406f17e..16ae2418 100644 --- a/src/TechnicalAnalysis.Candles/CandleUnique3River/CandleUnique3River.cs +++ b/src/TechnicalAnalysis.Candles/CandleUnique3River/CandleUnique3River.cs @@ -30,19 +30,11 @@ public class CandleUnique3River(in T[] open, in T[] high, in T[] low, in T[] public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleUpsideGap2Crows/CandleUpsideGap2Crows.cs b/src/TechnicalAnalysis.Candles/CandleUpsideGap2Crows/CandleUpsideGap2Crows.cs index 1ace364d..4504b004 100644 --- a/src/TechnicalAnalysis.Candles/CandleUpsideGap2Crows/CandleUpsideGap2Crows.cs +++ b/src/TechnicalAnalysis.Candles/CandleUpsideGap2Crows/CandleUpsideGap2Crows.cs @@ -30,19 +30,11 @@ public class CandleUpsideGap2Crows(in T[] open, in T[] high, in T[] low, in T public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Candles/CandleXSideGap3Methods/CandleXSideGap3Methods.cs b/src/TechnicalAnalysis.Candles/CandleXSideGap3Methods/CandleXSideGap3Methods.cs index a58ea51a..9ea3dfbb 100644 --- a/src/TechnicalAnalysis.Candles/CandleXSideGap3Methods/CandleXSideGap3Methods.cs +++ b/src/TechnicalAnalysis.Candles/CandleXSideGap3Methods/CandleXSideGap3Methods.cs @@ -27,19 +27,11 @@ public class CandleXSideGap3Methods(in T[] open, in T[] high, in T[] low, in public CandleIndicatorResult Compute(int startIdx, int endIdx) { // Initialize output variables - int outBegIdx = default; - int outNBElement = default; - int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)]; + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); - // Validate the requested output range. - ArgumentOutOfRangeException.ThrowIfNegative(startIdx); - ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); - - // Verify required price component. - ArgumentNullException.ThrowIfNull(Open); - ArgumentNullException.ThrowIfNull(High); - ArgumentNullException.ThrowIfNull(Low); - ArgumentNullException.ThrowIfNull(Close); + // Validations + ValidateIndices(ref startIdx, ref endIdx); + ValidatePriceArrays(); // Identify the minimum number of price bar needed to calculate at least one output. int lookbackTotal = GetLookback(); diff --git a/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs b/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs index 6aedfa61..3bbd6f09 100644 --- a/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs +++ b/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs @@ -62,6 +62,58 @@ protected CandleIndicator(T[] open, T[] high, T[] low, T[] close) /// True if the pattern is recognized, false otherwise. public abstract bool GetPatternRecognition(int i); + + + + /// + /// Prepares the output variables. + /// + /// The start index. + /// The end index. + /// A tuple containing the output variables. + protected virtual (int outBegIdx, int outNBElement, int[] outInteger) PrepareOutput(int startIdx, int endIdx) + { + // Initialize output variables + (int outBegIdx, int outNBElement, int[] outInteger) = PrepareOutput(startIdx, endIdx); + + // Return the output variables. + return (outBegIdx, outNBElement, outInteger); + } + + /// + /// Validates the specified indices. + /// + /// The start index. + /// The end index. + protected virtual void ValidateIndices(ref int startIdx, ref int endIdx) + { + // Validate the requested output range. + ArgumentOutOfRangeException.ThrowIfNegative(startIdx); + ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx); + } + + /// + /// Validates the price arrays. + /// + protected virtual void ValidatePriceArrays() + { + // Verify required price component. + ArgumentNullException.ThrowIfNull(Open); + ArgumentNullException.ThrowIfNull(High); + ArgumentNullException.ThrowIfNull(Low); + ArgumentNullException.ThrowIfNull(Close); + } + + /// + /// Validates the specified parameters. + /// + /// The penetration to validate. + protected virtual void ValidateParameters(T penetration) + { + // Verify parameters + ArgumentOutOfRangeException.ThrowIfNegative(penetration); + } + /// /// Gets the range type of the specified candle setting. ///