Skip to content

Commit

Permalink
Refactor to use built-in ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
hmG3 committed Jul 25, 2024
1 parent daa2b8d commit 5f0a70c
Show file tree
Hide file tree
Showing 163 changed files with 2,571 additions and 3,600 deletions.
38 changes: 15 additions & 23 deletions src/TALib.NETCore/Candles/TA_AbandonedBaby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public static Core.RetCode AbandonedBaby<T>(
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement,
out Range outRange,
double optInPenetration = 0.3) where T : IFloatingPointIeee754<T> =>
AbandonedBabyImpl(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement, optInPenetration);
AbandonedBabyImpl(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange, optInPenetration);

[PublicAPI]
public static int AbandonedBabyLookback() =>
Expand All @@ -52,30 +50,28 @@ private static Core.RetCode AbandonedBaby<T>(
T[] inHigh,
T[] inLow,
T[] inClose,
int startIdx,
int endIdx,
Range inRange,
int[] outIntType,
out int outBegIdx,
out int outNbElement,
out Range outRange,
double optInPenetration = 0.3) where T : IFloatingPointIeee754<T> =>
AbandonedBabyImpl<T>(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement,
optInPenetration);
AbandonedBabyImpl<T>(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange, optInPenetration);

private static Core.RetCode AbandonedBabyImpl<T>(

Check warning on line 59 in src/TALib.NETCore/Candles/TA_AbandonedBaby.cs

View workflow job for this annotation

GitHub Actions / analyze (ubuntu-latest)

Method has 8 parameters, which is greater than the 7 authorized. (https://rules.sonarsource.com/csharp/RSPEC-107)
ReadOnlySpan<T> inOpen,
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement,
out Range outRange,
double optInPenetration) where T : IFloatingPointIeee754<T>
{
outBegIdx = outNbElement = 0;
outRange = Range.EndAt(0);

if (startIdx < 0 || endIdx < 0 || endIdx < startIdx)
var startIdx = inRange.Start.Value;
var endIdx = inRange.End.Value;

if (endIdx < startIdx)
{
return Core.RetCode.OutOfRangeStartIndex;
}
Expand All @@ -86,10 +82,7 @@ private static Core.RetCode AbandonedBabyImpl<T>(
}

var lookbackTotal = AbandonedBabyLookback();
if (startIdx < lookbackTotal)
{
startIdx = lookbackTotal;
}
startIdx = Math.Max(startIdx, lookbackTotal);

if (startIdx > endIdx)
{
Expand Down Expand Up @@ -172,8 +165,7 @@ private static Core.RetCode AbandonedBabyImpl<T>(
bodyShortTrailingIdx++;
} while (i <= endIdx);

outBegIdx = startIdx;
outNbElement = outIdx;
outRange = new Range(startIdx, startIdx + outIdx);

return Core.RetCode.Success;
}
Expand Down
37 changes: 15 additions & 22 deletions src/TALib.NETCore/Candles/TA_AdvanceBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ public static Core.RetCode AdvanceBlock<T>(
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
AdvanceBlockImpl(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
AdvanceBlockImpl(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

[PublicAPI]
public static int AdvanceBlockLookback() =>
Expand All @@ -53,36 +51,32 @@ private static Core.RetCode AdvanceBlock<T>(
T[] inHigh,
T[] inLow,
T[] inClose,
int startIdx,
int endIdx,
Range inRange,
int[] outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
AdvanceBlockImpl<T>(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
AdvanceBlockImpl<T>(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

private static Core.RetCode AdvanceBlockImpl<T>(
ReadOnlySpan<T> inOpen,
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T>
out Range outRange) where T : IFloatingPointIeee754<T>
{
outBegIdx = outNbElement = 0;
outRange = Range.EndAt(0);

if (startIdx < 0 || endIdx < 0 || endIdx < startIdx)
var startIdx = inRange.Start.Value;
var endIdx = inRange.End.Value;

if (endIdx < startIdx)
{
return Core.RetCode.OutOfRangeStartIndex;
}

var lookbackTotal = AdvanceBlockLookback();
if (startIdx < lookbackTotal)
{
startIdx = lookbackTotal;
}
startIdx = Math.Max(startIdx, lookbackTotal);

if (startIdx > endIdx)
{
Expand Down Expand Up @@ -203,8 +197,7 @@ private static Core.RetCode AdvanceBlockImpl<T>(
bodyLongTrailingIdx++;
} while (i <= endIdx);

outBegIdx = startIdx;
outNbElement = outIdx;
outRange = new Range(startIdx, startIdx + outIdx);

return Core.RetCode.Success;
}
Expand Down
37 changes: 15 additions & 22 deletions src/TALib.NETCore/Candles/TA_BeltHold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ public static Core.RetCode BeltHold<T>(
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
BeltHoldImpl(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
BeltHoldImpl(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

[PublicAPI]
public static int BeltHoldLookback() =>
Expand All @@ -48,36 +46,32 @@ private static Core.RetCode BeltHold<T>(
T[] inHigh,
T[] inLow,
T[] inClose,
int startIdx,
int endIdx,
Range inRange,
int[] outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
BeltHoldImpl<T>(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
BeltHoldImpl<T>(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

private static Core.RetCode BeltHoldImpl<T>(
ReadOnlySpan<T> inOpen,
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T>
out Range outRange) where T : IFloatingPointIeee754<T>
{
outBegIdx = outNbElement = 0;
outRange = Range.EndAt(0);

if (startIdx < 0 || endIdx < 0 || endIdx < startIdx)
var startIdx = inRange.Start.Value;
var endIdx = inRange.End.Value;

if (endIdx < startIdx)
{
return Core.RetCode.OutOfRangeStartIndex;
}

var lookbackTotal = BeltHoldLookback();
if (startIdx < lookbackTotal)
{
startIdx = lookbackTotal;
}
startIdx = Math.Max(startIdx, lookbackTotal);

if (startIdx > endIdx)
{
Expand Down Expand Up @@ -134,8 +128,7 @@ private static Core.RetCode BeltHoldImpl<T>(
shadowVeryShortTrailingIdx++;
} while (i <= endIdx);

outBegIdx = startIdx;
outNbElement = outIdx;
outRange = new Range(startIdx, startIdx + outIdx);

return Core.RetCode.Success;
}
Expand Down
37 changes: 15 additions & 22 deletions src/TALib.NETCore/Candles/TA_Breakaway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ public static Core.RetCode Breakaway<T>(
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
BreakawayImpl(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
BreakawayImpl(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

[PublicAPI]
public static int BreakawayLookback() => CandleAveragePeriod(Core.CandleSettingType.BodyLong) + 4;
Expand All @@ -47,36 +45,32 @@ private static Core.RetCode Breakaway<T>(
T[] inHigh,
T[] inLow,
T[] inClose,
int startIdx,
int endIdx,
Range inRange,
int[] outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
BreakawayImpl<T>(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
BreakawayImpl<T>(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

private static Core.RetCode BreakawayImpl<T>(
ReadOnlySpan<T> inOpen,
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T>
out Range outRange) where T : IFloatingPointIeee754<T>
{
outBegIdx = outNbElement = 0;
outRange = Range.EndAt(0);

if (startIdx < 0 || endIdx < 0 || endIdx < startIdx)
var startIdx = inRange.Start.Value;
var endIdx = inRange.End.Value;

if (endIdx < startIdx)
{
return Core.RetCode.OutOfRangeStartIndex;
}

var lookbackTotal = BreakawayLookback();
if (startIdx < lookbackTotal)
{
startIdx = lookbackTotal;
}
startIdx = Math.Max(startIdx, lookbackTotal);

if (startIdx > endIdx)
{
Expand Down Expand Up @@ -126,8 +120,7 @@ private static Core.RetCode BreakawayImpl<T>(
bodyLongTrailingIdx++;
} while (i <= endIdx);

outBegIdx = startIdx;
outNbElement = outIdx;
outRange = new Range(startIdx, startIdx + outIdx);

return Core.RetCode.Success;
}
Expand Down
37 changes: 15 additions & 22 deletions src/TALib.NETCore/Candles/TA_ClosingMarubozu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ public static Core.RetCode ClosingMarubozu<T>(
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
ClosingMarubozuImpl(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
ClosingMarubozuImpl(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

[PublicAPI]
public static int ClosingMarubozuLookback() =>
Expand All @@ -48,36 +46,32 @@ private static Core.RetCode ClosingMarubozu<T>(
T[] inHigh,
T[] inLow,
T[] inClose,
int startIdx,
int endIdx,
Range inRange,
int[] outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T> =>
ClosingMarubozuImpl<T>(inOpen, inHigh, inLow, inClose, startIdx, endIdx, outIntType, out outBegIdx, out outNbElement);
out Range outRange) where T : IFloatingPointIeee754<T> =>
ClosingMarubozuImpl<T>(inOpen, inHigh, inLow, inClose, inRange, outIntType, out outRange);

private static Core.RetCode ClosingMarubozuImpl<T>(
ReadOnlySpan<T> inOpen,
ReadOnlySpan<T> inHigh,
ReadOnlySpan<T> inLow,
ReadOnlySpan<T> inClose,
int startIdx,
int endIdx,
Range inRange,
Span<int> outIntType,
out int outBegIdx,
out int outNbElement) where T : IFloatingPointIeee754<T>
out Range outRange) where T : IFloatingPointIeee754<T>
{
outBegIdx = outNbElement = 0;
outRange = Range.EndAt(0);

if (startIdx < 0 || endIdx < 0 || endIdx < startIdx)
var startIdx = inRange.Start.Value;
var endIdx = inRange.End.Value;

if (endIdx < startIdx)
{
return Core.RetCode.OutOfRangeStartIndex;
}

var lookbackTotal = ClosingMarubozuLookback();
if (startIdx < lookbackTotal)
{
startIdx = lookbackTotal;
}
startIdx = Math.Max(startIdx, lookbackTotal);

if (startIdx > endIdx)
{
Expand Down Expand Up @@ -135,8 +129,7 @@ private static Core.RetCode ClosingMarubozuImpl<T>(
shadowVeryShortTrailingIdx++;
} while (i <= endIdx);

outBegIdx = startIdx;
outNbElement = outIdx;
outRange = new Range(startIdx, startIdx + outIdx);

return Core.RetCode.Success;
}
Expand Down
Loading

0 comments on commit 5f0a70c

Please sign in to comment.