Skip to content

Commit

Permalink
Fix analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hmG3 committed Aug 8, 2024
1 parent d925c61 commit f60bcd0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 36 deletions.
14 changes: 8 additions & 6 deletions src/TALib.NETCore/Candles/TA_HikkakeModified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,21 @@ private static void CalcHikkakeModified<T>(
int nearTrailingIdx,
int endIdx) where T : IFloatingPointIeee754<T>
{
var pResult = patternResult;
var pIdx = patternIdx;
do
{
if (IsHikkakeModifiedPattern(inOpen, inHigh, inLow, inClose, i, nearPeriodTotal))
{
patternResult = 100 * (inHigh[i] < inHigh[i - 1] ? 1 : -1);
patternIdx = i;
outIntType[outIdx++] = patternResult;
pResult = 100 * (inHigh[i] < inHigh[i - 1] ? 1 : -1);
pIdx = i;
outIntType[outIdx++] = pResult;
}
// search for confirmation if modified hikkake was no more than 3 bars ago
else if (IsHikkakeModifiedPatternConfirmation(inHigh, inLow, inClose, i, patternIdx, patternResult))
else if (IsHikkakeModifiedPatternConfirmation(inHigh, inLow, inClose, i, pIdx, pResult))
{
outIntType[outIdx++] = patternResult + 100 * (patternResult > 0 ? 1 : -1);
patternIdx = 0;
outIntType[outIdx++] = pResult + 100 * (pResult > 0 ? 1 : -1);
pIdx = 0;
}
else
{
Expand Down
50 changes: 28 additions & 22 deletions src/TALib.NETCore/Functions/FunctionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,30 +407,33 @@ public static (int, T) CalcLowest<T>(
where T : IFloatingPointIeee754<T>
{
var tmp = input[today];
if (lowestIdx < trailingIdx)
var lIdx = lowestIdx;
var l = lowest;

if (lIdx < trailingIdx)
{
lowestIdx = trailingIdx;
lowest = input[lowestIdx];
var i = lowestIdx;
lIdx = trailingIdx;
l = input[lIdx];
var i = lIdx;
while (++i <= today)
{
tmp = input[i];
if (tmp > lowest)
if (tmp > l)
{
continue;
}

lowestIdx = i;
lowest = tmp;
lIdx = i;
l = tmp;
}
}
else if (tmp <= lowest)
else if (tmp <= l)
{
lowestIdx = today;
lowest = tmp;
lIdx = today;
l = tmp;
}

return (lowestIdx, lowest);
return (lIdx, l);
}

public static (int, T) CalcHighest<T>(
Expand All @@ -442,30 +445,33 @@ public static (int, T) CalcHighest<T>(
where T : IFloatingPointIeee754<T>
{
var tmp = input[today];
if (highestIdx < trailingIdx)
var hIdx = highestIdx;
var h = highest;

if (hIdx < trailingIdx)
{
highestIdx = trailingIdx;
highest = input[highestIdx];
var i = highestIdx;
hIdx = trailingIdx;
h = input[hIdx];
var i = hIdx;
while (++i <= today)
{
tmp = input[i];
if (tmp < highest)
if (tmp < h)
{
continue;
}

highestIdx = i;
highest = tmp;
hIdx = i;
h = tmp;
}
}
else if (tmp >= highest)
else if (tmp >= h)
{
highestIdx = today;
highest = tmp;
hIdx = today;
h = tmp;
}

return (highestIdx, highest);
return (hIdx, h);
}

public static void InitDMAndTR<T>(
Expand Down
7 changes: 4 additions & 3 deletions src/TALib.NETCore/Functions/TA_HtDcPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,17 @@ private static T CalcDcPhase<T>(
T smoothPeriod) where T : IFloatingPointIeee754<T>
{
var tempReal = T.Abs(imagPart);
T dcPhaseValue = T.Zero;
if (tempReal > T.Zero)
{
dcPhase = T.RadiansToDegrees(T.Atan(realPart / imagPart));
dcPhaseValue = T.RadiansToDegrees(T.Atan(realPart / imagPart));
}
else if (tempReal <= T.CreateChecked(0.01))
{
dcPhase = AdjustPhaseForSmallImaginaryPart(realPart, dcPhase);
dcPhaseValue = AdjustPhaseForSmallImaginaryPart(realPart, dcPhase);
}

dcPhase = FinalPhaseAdjustments(imagPart, dcPhase, smoothPeriod);
dcPhase = FinalPhaseAdjustments(imagPart, dcPhaseValue, smoothPeriod);

return dcPhase;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TALib.NETCore/Functions/TA_Trima.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static Core.RetCode TrimaImpl<T>(
}

int outIdx;
if (optInTimePeriod % 2 == 1)
if (optInTimePeriod % 2 != 0)
{
ProcessOdd(inReal, startIdx, endIdx, optInTimePeriod, lookbackTotal, outReal, out outIdx);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TALib.NETCore.Tests/JsonFileDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public override IEnumerable<object[]> GetData(MethodInfo testMethod)
throw new JsonException($"Could not find property {_propertyName}");
}

dataModels = (IEnumerable<object>) dataProperty.ToObject(_targetCollectionType,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
dataModels = (dataProperty.ToObject(_targetCollectionType,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true }) as IEnumerable<object>)!;
}
else
{
dataModels = (IEnumerable<object>) dataDocument.ToObject(_targetCollectionType,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
dataModels = (dataDocument.ToObject(_targetCollectionType,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true }) as IEnumerable<object>)!;
}
}

Expand Down

0 comments on commit f60bcd0

Please sign in to comment.