Skip to content

Commit

Permalink
Fixed the infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-lopez committed Aug 28, 2023
1 parent e697f39 commit 00d5986
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 394 deletions.
26 changes: 13 additions & 13 deletions source/TALib/Core/MomentumIndicators.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static function adxr(int $startIdx, int $endIdx, array $inHigh, array $in
$j = 0;
$outIdx = 0;
$nbElement = $endIdx - $startIdx + 2;
while (--$nbElement !== 0) {
while (--$nbElement > 0) {
$outReal[$outIdx++] = ($adx[$i++] + $adx[$j++]) / 2.0;
}
$outBegIdx = $startIdx;
Expand Down Expand Up @@ -701,7 +701,7 @@ public static function dx(int $startIdx, int $endIdx, array $inHigh, array $inLo
$prevClose = $inClose[$today];
}
$i = static::$unstablePeriod[UnstablePeriodFunctionID::DX] + 1;
while ($i-- !== 0) {
while ($i-- > 0) {
$today++;
$tempReal = $inHigh[$today];
$diffP = $tempReal - $prevHigh;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ public static function minusDI(int $startIdx, int $endIdx, array $inHigh, array
if ($diffM > 0 && $diffP < $diffM) {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod + $diffM;
} else {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod;
$prevMinusDM -= $prevMinusDM / $optInTimePeriod;
}
{
$tempReal = $prevHigh - $prevLow;
Expand Down Expand Up @@ -1232,7 +1232,7 @@ public static function minusDI(int $startIdx, int $endIdx, array $inHigh, array
if ($diffM > 0 && $diffP < $diffM) {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod + $diffM;
} else {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod;
$prevMinusDM -= $prevMinusDM / $optInTimePeriod;
}
{
$tempReal = $prevHigh - $prevLow;
Expand Down Expand Up @@ -1324,7 +1324,7 @@ public static function minusDM(int $startIdx, int $endIdx, array $inHigh, array
}
}
$i = static::$unstablePeriod[UnstablePeriodFunctionID::MinusDM];
while ($i-- !== 0) {
while ($i-- > 0) {
$today++;
$tempReal = $inHigh[$today];
$diffP = $tempReal - $prevHigh;
Expand All @@ -1335,7 +1335,7 @@ public static function minusDM(int $startIdx, int $endIdx, array $inHigh, array
if ($diffM > 0 && $diffP < $diffM) {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod + $diffM;
} else {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod;
$prevMinusDM -= $prevMinusDM / $optInTimePeriod;
}
}
$outReal[0] = $prevMinusDM;
Expand All @@ -1351,7 +1351,7 @@ public static function minusDM(int $startIdx, int $endIdx, array $inHigh, array
if ($diffM > 0 && $diffP < $diffM) {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod + $diffM;
} else {
$prevMinusDM = $prevMinusDM - $prevMinusDM / $optInTimePeriod;
$prevMinusDM -= $prevMinusDM / $optInTimePeriod;
}
$outReal[$outIdx++] = $prevMinusDM;
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ public static function plusDI(int $startIdx, int $endIdx, array $inHigh, array $
$prevClose = $inClose[$today];
}
$i = static::$unstablePeriod[UnstablePeriodFunctionID::PlusDI] + 1;
while ($i-- !== 0) {
while ($i-- > 0) {
$today++;
$tempReal = $inHigh[$today];
$diffP = $tempReal - $prevHigh;
Expand All @@ -1501,7 +1501,7 @@ public static function plusDI(int $startIdx, int $endIdx, array $inHigh, array $
if ($diffP > 0 && $diffP > $diffM) {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod + $diffP;
} else {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod;
$prevPlusDM -= $prevPlusDM / $optInTimePeriod;
}
{
$tempReal = $prevHigh - $prevLow;
Expand Down Expand Up @@ -1534,7 +1534,7 @@ public static function plusDI(int $startIdx, int $endIdx, array $inHigh, array $
if ($diffP > 0 && $diffP > $diffM) {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod + $diffP;
} else {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod;
$prevPlusDM -= $prevPlusDM / $optInTimePeriod;
}
{
$tempReal = $prevHigh - $prevLow;
Expand Down Expand Up @@ -1626,7 +1626,7 @@ public static function plusDM(int $startIdx, int $endIdx, array $inHigh, array $
}
}
$i = static::$unstablePeriod[UnstablePeriodFunctionID::PlusDM];
while ($i-- !== 0) {
while ($i-- > 0) {
$today++;
$tempReal = $inHigh[$today];
$diffP = $tempReal - $prevHigh;
Expand All @@ -1637,7 +1637,7 @@ public static function plusDM(int $startIdx, int $endIdx, array $inHigh, array $
if ($diffP > 0 && $diffP > $diffM) {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod + $diffP;
} else {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod;
$prevPlusDM -= $prevPlusDM / $optInTimePeriod;
}
}
$outReal[0] = $prevPlusDM;
Expand All @@ -1653,7 +1653,7 @@ public static function plusDM(int $startIdx, int $endIdx, array $inHigh, array $
if ($diffP > 0 && $diffP > $diffM) {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod + $diffP;
} else {
$prevPlusDM = $prevPlusDM - $prevPlusDM / $optInTimePeriod;
$prevPlusDM -= $prevPlusDM / $optInTimePeriod;
}
$outReal[$outIdx++] = $prevPlusDM;
}
Expand Down
Loading

0 comments on commit 00d5986

Please sign in to comment.