diff --git a/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs b/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs
index 38a736fd..b4861e59 100644
--- a/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs
+++ b/src/TechnicalAnalysis.Common/Abstractions/CandleIndicator.cs
@@ -11,44 +11,34 @@ namespace TechnicalAnalysis.Common;
///
/// Represents an abstract base class for candlestick pattern recognition indicators.
///
-public abstract class CandleIndicator
+/// The floating-point type the price arrays are expressed in.
+/// An array of open prices.
+/// An array of high prices.
+/// An array of low prices.
+/// An array of close prices.
+public abstract class CandleIndicator(T[] open, T[] high, T[] low, T[] close)
where T : IFloatingPoint
{
///
/// An array of open prices.
///
- protected T[] Open { get; }
-
+ protected T[] Open { get; } = open;
+
///
/// An array of high prices.
///
- protected T[] High { get; }
-
+ protected T[] High { get; } = high;
+
///
/// An array of low prices.
///
- protected T[] Low { get; }
+ protected T[] Low { get; } = low;
///
/// An array of close prices.
///
- protected T[] Close { get; }
-
- ///
- /// Initializes a new instance of the CandleIndicator class.
- ///
- /// An array of open prices.
- /// An array of high prices.
- /// An array of low prices.
- /// An array of close prices.
- protected CandleIndicator(T[] open, T[] high, T[] low, T[] close)
- {
- Open = open;
- High = high;
- Low = low;
- Close = close;
- }
-
+ protected T[] Close { get; } = close;
+
///
/// Returns the lookback period for the indicator.
///
diff --git a/src/TechnicalAnalysis.Common/Helpers/ValidationHelper.cs b/src/TechnicalAnalysis.Common/Helpers/ValidationHelper.cs
index cb5ae67a..394147e7 100644
--- a/src/TechnicalAnalysis.Common/Helpers/ValidationHelper.cs
+++ b/src/TechnicalAnalysis.Common/Helpers/ValidationHelper.cs
@@ -37,17 +37,9 @@ public static class ValidationHelper
///
public static RetCode ValidateIndexRange(int startIdx, int endIdx)
{
- if (startIdx < 0)
- {
- return OutOfRangeStartIndex;
- }
-
- if (endIdx < 0 || endIdx < startIdx)
- {
- return OutOfRangeEndIndex;
- }
-
- return Success;
+ return startIdx < 0 ? OutOfRangeStartIndex
+ : endIdx < 0 || endIdx < startIdx ? OutOfRangeEndIndex
+ : Success;
}
///
@@ -151,24 +143,15 @@ public static RetCode ValidateSingleInputIndicator(
int minPeriod = 2,
int maxPeriod = 100000)
{
- RetCode indexCheck = ValidateIndexRange(startIdx, endIdx);
- if (indexCheck != Success)
- {
- return indexCheck;
- }
-
- RetCode arrayCheck = ValidateArrays(inReal, outReal);
- if (arrayCheck != Success)
- {
- return arrayCheck;
- }
-
- if (optInTimePeriod.HasValue)
- {
- return ValidatePeriodRange(optInTimePeriod.Value, minPeriod, maxPeriod);
- }
-
- return Success;
+ // ValidateAll runs these in order and stops at the first failure, which is what the
+ // hand-rolled guard chain did — but as one expression, and matching how the indicators
+ // themselves compose their validation.
+ return ValidateAll(
+ () => ValidateIndexRange(startIdx, endIdx),
+ () => ValidateArrays(inReal, outReal),
+ () => optInTimePeriod.HasValue
+ ? ValidatePeriodRange(optInTimePeriod.Value, minPeriod, maxPeriod)
+ : Success);
}
///
diff --git a/src/TechnicalAnalysis.Functions/Correl/CorrelResult.cs b/src/TechnicalAnalysis.Functions/Correl/CorrelResult.cs
index b69f02a7..c2ad3504 100644
--- a/src/TechnicalAnalysis.Functions/Correl/CorrelResult.cs
+++ b/src/TechnicalAnalysis.Functions/Correl/CorrelResult.cs
@@ -30,14 +30,4 @@ public CorrelResult(RetCode retCode, int begIdx, int nbElement, double[] real)
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of correlation coefficient values.
- ///
- ///
- /// An array of doubles representing the correlation values, ranging from -1 to +1.
- /// Values near +1 indicate strong positive correlation, values near -1 indicate
- /// strong negative correlation, and values near 0 indicate weak or no linear relationship.
- /// These values are essential for risk management and portfolio optimization.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/Dx/DxResult.cs b/src/TechnicalAnalysis.Functions/Dx/DxResult.cs
index 8756a331..cadeb475 100644
--- a/src/TechnicalAnalysis.Functions/Dx/DxResult.cs
+++ b/src/TechnicalAnalysis.Functions/Dx/DxResult.cs
@@ -10,6 +10,11 @@ namespace TechnicalAnalysis.Functions;
/// Represents the result of the Directional Movement Index (DX) indicator calculation.
/// DX measures the strength of a trend regardless of its direction, derived from comparing directional movements.
///
+///
+/// The array holds the Directional Movement Index values.
+/// Values range from 0 to 100, where higher values indicate stronger trends (either up or down).
+/// Values below 20 typically indicate weak trends, while values above 40 suggest strong trends.
+///
public record DxResult : SingleOutputResult
{
///
@@ -23,10 +28,4 @@ public DxResult(RetCode retCode, int begIdx, int nbElement, double[] real)
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of Directional Movement Index values.
- /// Values range from 0 to 100, where higher values indicate stronger trends (either up or down).
- /// Values below 20 typically indicate weak trends, while values above 40 suggest strong trends.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/HtDcPeriod/HtDcPeriodResult.cs b/src/TechnicalAnalysis.Functions/HtDcPeriod/HtDcPeriodResult.cs
index ba992f8c..6f88f26a 100644
--- a/src/TechnicalAnalysis.Functions/HtDcPeriod/HtDcPeriodResult.cs
+++ b/src/TechnicalAnalysis.Functions/HtDcPeriod/HtDcPeriodResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator identifies the dominant cycle period of market data using Hilbert Transform techniques,
/// providing insight into the cyclical nature of price movements.
///
+///
+/// The array holds the dominant cycle period values.
+/// Each value represents the period (in bars) of the dominant market cycle at that point in time.
+/// Values typically range from 10 to 50 bars, depending on market conditions.
+///
public record HtDcPeriodResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public HtDcPeriodResult(RetCode retCode, int begIdx, int nbElement, double[] rea
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of dominant cycle period values.
- /// Each value represents the period (in bars) of the dominant market cycle at that point in time.
- /// Values typically range from 10 to 50 bars, depending on market conditions.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/HtDcPhase/HtDcPhaseResult.cs b/src/TechnicalAnalysis.Functions/HtDcPhase/HtDcPhaseResult.cs
index aa87009f..ab8e7f18 100644
--- a/src/TechnicalAnalysis.Functions/HtDcPhase/HtDcPhaseResult.cs
+++ b/src/TechnicalAnalysis.Functions/HtDcPhase/HtDcPhaseResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator measures the phase angle of the dominant market cycle using Hilbert Transform techniques,
/// helping to identify the current position within a price cycle.
///
+///
+/// The array holds the dominant cycle phase values.
+/// Each value represents the phase angle in degrees (-180 to +180) of the dominant cycle.
+/// Positive values indicate the cycle is in an upward phase, while negative values indicate a downward phase.
+///
public record HtDcPhaseResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public HtDcPhaseResult(RetCode retCode, int begIdx, int nbElement, double[] real
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of dominant cycle phase values.
- /// Each value represents the phase angle in degrees (-180 to +180) of the dominant cycle.
- /// Positive values indicate the cycle is in an upward phase, while negative values indicate a downward phase.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/HtTrendline/HtTrendlineResult.cs b/src/TechnicalAnalysis.Functions/HtTrendline/HtTrendlineResult.cs
index ee96cdb7..76b247fb 100644
--- a/src/TechnicalAnalysis.Functions/HtTrendline/HtTrendlineResult.cs
+++ b/src/TechnicalAnalysis.Functions/HtTrendline/HtTrendlineResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator creates a smooth trendline by removing the dominant cycle component from price data,
/// effectively filtering out short-term fluctuations to reveal the underlying trend.
///
+///
+/// The array holds the instantaneous trendline values.
+/// These values represent a smoothed version of the price with dominant cycles filtered out,
+/// providing a clear view of the underlying trend direction and strength.
+///
public record HtTrendlineResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public HtTrendlineResult(RetCode retCode, int begIdx, int nbElement, double[] re
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of instantaneous trendline values.
- /// These values represent a smoothed version of the price with dominant cycles filtered out,
- /// providing a clear view of the underlying trend direction and strength.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/LinearReg/LinearRegResult.cs b/src/TechnicalAnalysis.Functions/LinearReg/LinearRegResult.cs
index cfe0086b..812dfa73 100644
--- a/src/TechnicalAnalysis.Functions/LinearReg/LinearRegResult.cs
+++ b/src/TechnicalAnalysis.Functions/LinearReg/LinearRegResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator calculates the linear regression line value at each point, providing a statistical
/// best-fit line through the price data over a specified period.
///
+///
+/// The array holds the linear regression line values.
+/// Each value represents the y-coordinate of the regression line at that point in time,
+/// calculated using least squares method over the specified lookback period.
+///
public record LinearRegResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public LinearRegResult(RetCode retCode, int begIdx, int nbElement, double[] real
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of linear regression line values.
- /// Each value represents the y-coordinate of the regression line at that point in time,
- /// calculated using least squares method over the specified lookback period.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/LinearRegAngle/LinearRegAngleResult.cs b/src/TechnicalAnalysis.Functions/LinearRegAngle/LinearRegAngleResult.cs
index 11a8dcbb..aa450dc3 100644
--- a/src/TechnicalAnalysis.Functions/LinearRegAngle/LinearRegAngleResult.cs
+++ b/src/TechnicalAnalysis.Functions/LinearRegAngle/LinearRegAngleResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator calculates the angle of the linear regression line in degrees, providing insight
/// into the strength and direction of the trend over a specified period.
///
+///
+/// Gets the array of linear regression angle values in degrees.
+/// Positive angles indicate an upward trend, negative angles indicate a downward trend.
+/// The magnitude of the angle reflects the steepness of the trend.
+///
public record LinearRegAngleResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public LinearRegAngleResult(RetCode retCode, int begIdx, int nbElement, double[]
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of linear regression angle values in degrees.
- /// Positive angles indicate an upward trend, negative angles indicate a downward trend.
- /// The magnitude of the angle reflects the steepness of the trend.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/LinearRegIntercept/LinearRegInterceptResult.cs b/src/TechnicalAnalysis.Functions/LinearRegIntercept/LinearRegInterceptResult.cs
index e757c27f..2a9fdf01 100644
--- a/src/TechnicalAnalysis.Functions/LinearRegIntercept/LinearRegInterceptResult.cs
+++ b/src/TechnicalAnalysis.Functions/LinearRegIntercept/LinearRegInterceptResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator calculates the y-intercept of the linear regression line, representing where
/// the regression line would cross the y-axis if extended backward.
///
+///
+/// The array holds the linear regression intercept values.
+/// Each value represents the y-intercept of the regression line calculated over the lookback period,
+/// useful for projecting the regression line and understanding price levels.
+///
public record LinearRegInterceptResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public LinearRegInterceptResult(RetCode retCode, int begIdx, int nbElement, doub
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of linear regression intercept values.
- /// Each value represents the y-intercept of the regression line calculated over the lookback period,
- /// useful for projecting the regression line and understanding price levels.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/LinearRegSlope/LinearRegSlopeResult.cs b/src/TechnicalAnalysis.Functions/LinearRegSlope/LinearRegSlopeResult.cs
index da314087..bf940dc5 100644
--- a/src/TechnicalAnalysis.Functions/LinearRegSlope/LinearRegSlopeResult.cs
+++ b/src/TechnicalAnalysis.Functions/LinearRegSlope/LinearRegSlopeResult.cs
@@ -11,6 +11,11 @@ namespace TechnicalAnalysis.Functions;
/// This indicator calculates the slope of the linear regression line, indicating the rate of change
/// in price over the specified period.
///
+///
+/// The array holds the linear regression slope values.
+/// Each value represents the slope (rate of change per bar) of the regression line.
+/// Positive values indicate rising prices, negative values indicate falling prices.
+///
public record LinearRegSlopeResult : SingleOutputResult
{
///
@@ -24,10 +29,4 @@ public LinearRegSlopeResult(RetCode retCode, int begIdx, int nbElement, double[]
: base(retCode, begIdx, nbElement, real)
{
}
-
- ///
- /// Gets the array of linear regression slope values.
- /// Each value represents the slope (rate of change per bar) of the regression line.
- /// Positive values indicate rising prices, negative values indicate falling prices.
- ///
}
diff --git a/src/TechnicalAnalysis.Functions/MacdFix/TAMath.cs b/src/TechnicalAnalysis.Functions/MacdFix/TAMath.cs
index 6c59f5e4..311bae73 100644
--- a/src/TechnicalAnalysis.Functions/MacdFix/TAMath.cs
+++ b/src/TechnicalAnalysis.Functions/MacdFix/TAMath.cs
@@ -51,9 +51,10 @@ public static MacdFixResult MacdFix(int startIdx, int endIdx, double[] real, int
/// The starting index for the calculation range.
/// The ending index for the calculation range.
/// Array of input values (usually closing prices).
+ /// The signal line period. Defaults to 9.
/// A MacdFixResult containing the MACD line, signal line, and histogram values.
///
- /// Uses fixed values: fastPeriod=12, slowPeriod=26, signalPeriod=9.
+ /// The fast and slow periods are fixed at 12 and 26; only the signal period is adjustable.
///
public static MacdFixResult MacdFix(int startIdx, int endIdx, float[] real, int signalPeriod = 9)
=> TAMathHelper.Execute(startIdx, endIdx, real, (s, e, r) => MacdFix(s, e, r, signalPeriod));
diff --git a/src/TechnicalAnalysis.Functions/MidPrice/TAMath.cs b/src/TechnicalAnalysis.Functions/MidPrice/TAMath.cs
index 58a01e81..0eea8c99 100644
--- a/src/TechnicalAnalysis.Functions/MidPrice/TAMath.cs
+++ b/src/TechnicalAnalysis.Functions/MidPrice/TAMath.cs
@@ -50,6 +50,7 @@ public static MidPriceResult MidPrice(int startIdx, int endIdx, double[] high, d
/// The ending index for the calculation range.
/// Array of high prices.
/// Array of low prices.
+ /// The number of periods in each rolling window. Defaults to 14.
/// A MidPriceResult containing the midprice values over each rolling window.
///
/// This overload uses a default time period of 14.
diff --git a/src/TechnicalAnalysis.Functions/Natr/TAMath.cs b/src/TechnicalAnalysis.Functions/Natr/TAMath.cs
index 5cb0df79..1efb96ef 100644
--- a/src/TechnicalAnalysis.Functions/Natr/TAMath.cs
+++ b/src/TechnicalAnalysis.Functions/Natr/TAMath.cs
@@ -55,6 +55,7 @@ public static NatrResult Natr(int startIdx, int endIdx, double[] high, double[]
/// An array of high prices.
/// An array of low prices.
/// An array of closing prices.
+ /// The number of periods to average over. Defaults to 14.
/// A NatrResult object containing the calculated values.
/// Uses the default time period of 14.
public static NatrResult Natr(int startIdx, int endIdx, float[] high, float[] low, float[] close, int timePeriod = 14)
diff --git a/src/TechnicalAnalysis.Functions/ZigZag/TAMath.cs b/src/TechnicalAnalysis.Functions/ZigZag/TAMath.cs
index 8ebf7585..2d56a2df 100644
--- a/src/TechnicalAnalysis.Functions/ZigZag/TAMath.cs
+++ b/src/TechnicalAnalysis.Functions/ZigZag/TAMath.cs
@@ -57,6 +57,7 @@ public static ZigZagResult ZigZag(
/// The ending index for the calculation.
/// Array of high prices.
/// Array of low prices.
+ /// The minimum percentage move required to start a new leg. Defaults to 5.0.
/// A ZigZagResult object containing the calculated values and metadata.
public static ZigZagResult ZigZag(int startIdx, int endIdx, float[] high, float[] low, double deviation = 5.0)
=> TAMathHelper.Execute(startIdx, endIdx, high, low, (s, e, h, l) => ZigZag(s, e, h, l, deviation));