diff --git a/src/TALib.NETCore/Function.cs b/src/TALib.NETCore/Function.cs index 9232a9b..81d5bc6 100644 --- a/src/TALib.NETCore/Function.cs +++ b/src/TALib.NETCore/Function.cs @@ -47,22 +47,20 @@ public int Lookback(params int[] options) var optInParameters = method.GetParameters().Where(pi => pi.Name.StartsWith(OptInPrefix)).ToList(); var paramsArray = new object[optInParameters.Count]; Array.Fill(paramsArray, Type.Missing); - if (options.Length == optInParameters.Count) + + var defOptInParameters = Options.Select(NormalizeOptionalParameter).ToList(); + for (int i = 0, paramsArrayIndex = 0; i < defOptInParameters.Count; i++) { - var defOptInParameters = Options.Select(NormalizeOptionalParameter).ToList(); - for (int i = 0, paramsArrayIndex = 0; i < defOptInParameters.Count; i++) + var optInParameter = optInParameters.SingleOrDefault(p => p.Name == defOptInParameters[i]); + if (optInParameter != null) { - var optInParameter = optInParameters.SingleOrDefault(p => p.Name == defOptInParameters[i]); - if (optInParameter != null) + if (optInParameter.ParameterType.IsEnum && optInParameter.ParameterType.IsEnumDefined(options[i])) { - if (optInParameter.ParameterType.IsEnum && optInParameter.ParameterType.IsEnumDefined(options[i])) - { - paramsArray[paramsArrayIndex++] = Enum.ToObject(optInParameter.ParameterType, options[i]); - } - else - { - paramsArray[paramsArrayIndex++] = options[i]; - } + paramsArray[paramsArrayIndex++] = Enum.ToObject(optInParameter.ParameterType, options[i]); + } + else + { + paramsArray[paramsArrayIndex++] = options[i]; } } } diff --git a/src/TALib.NETCore/TACore.cs b/src/TALib.NETCore/TACore.cs index 3c4565e..3d22f7f 100644 --- a/src/TALib.NETCore/TACore.cs +++ b/src/TALib.NETCore/TACore.cs @@ -228,12 +228,9 @@ private static RetCode TA_INT_MACD(double[] inReal, int startIdx, int endIdx, do { outBegIdx = outNbElement = 0; - int tempInteger; if (optInSlowPeriod < optInFastPeriod) { - tempInteger = optInSlowPeriod; - optInSlowPeriod = optInFastPeriod; - optInFastPeriod = tempInteger; + (optInSlowPeriod, optInFastPeriod) = (optInFastPeriod, optInSlowPeriod); } double k1; @@ -270,7 +267,7 @@ private static RetCode TA_INT_MACD(double[] inReal, int startIdx, int endIdx, do return RetCode.Success; } - tempInteger = endIdx - startIdx + 1 + lookbackSignal; + var tempInteger = endIdx - startIdx + 1 + lookbackSignal; var fastEMABuffer = new double[tempInteger]; var slowEMABuffer = new double[tempInteger]; @@ -324,12 +321,9 @@ private static RetCode TA_INT_MACD(decimal[] inReal, int startIdx, int endIdx, d { outBegIdx = outNbElement = 0; - int tempInteger; if (optInSlowPeriod < optInFastPeriod) { - tempInteger = optInSlowPeriod; - optInSlowPeriod = optInFastPeriod; - optInFastPeriod = tempInteger; + (optInSlowPeriod, optInFastPeriod) = (optInFastPeriod, optInSlowPeriod); } decimal k1; @@ -366,7 +360,7 @@ private static RetCode TA_INT_MACD(decimal[] inReal, int startIdx, int endIdx, d return RetCode.Success; } - tempInteger = endIdx - startIdx + 1 + lookbackSignal; + var tempInteger = endIdx - startIdx + 1 + lookbackSignal; var fastEMABuffer = new decimal[tempInteger]; var slowEMABuffer = new decimal[tempInteger]; @@ -421,12 +415,9 @@ private static RetCode TA_INT_PO(double[] inReal, int startIdx, int endIdx, doub { outBegIdx = outNbElement = 0; - int tempInteger; if (optInSlowPeriod < optInFastPeriod) { - tempInteger = optInSlowPeriod; - optInSlowPeriod = optInFastPeriod; - optInFastPeriod = tempInteger; + (optInSlowPeriod, optInFastPeriod) = (optInFastPeriod, optInSlowPeriod); } RetCode retCode = Ma(inReal, startIdx, endIdx, tempBuffer, out var outBegIdx2, out _, optInMethod, optInFastPeriod); @@ -441,8 +432,7 @@ private static RetCode TA_INT_PO(double[] inReal, int startIdx, int endIdx, doub return retCode; } - tempInteger = outBegIdx1 - outBegIdx2; - for (int i = 0, j = tempInteger; i < outNbElement1; i++, j++) + for (int i = 0, j = outBegIdx1 - outBegIdx2; i < outNbElement1; i++, j++) { if (doPercentageOutput) { @@ -467,12 +457,9 @@ private static RetCode TA_INT_PO(decimal[] inReal, int startIdx, int endIdx, dec { outBegIdx = outNbElement = 0; - int tempInteger; if (optInSlowPeriod < optInFastPeriod) { - tempInteger = optInSlowPeriod; - optInSlowPeriod = optInFastPeriod; - optInFastPeriod = tempInteger; + (optInSlowPeriod, optInFastPeriod) = (optInFastPeriod, optInSlowPeriod); } RetCode retCode = Ma(inReal, startIdx, endIdx, tempBuffer, out var outBegIdx2, out _, optInMethod, optInFastPeriod); @@ -487,8 +474,7 @@ private static RetCode TA_INT_PO(decimal[] inReal, int startIdx, int endIdx, dec return retCode; } - tempInteger = outBegIdx1 - outBegIdx2; - for (int i = 0, j = tempInteger; i < outNbElement1; i++, j++) + for (int i = 0, j = outBegIdx1 - outBegIdx2; i < outNbElement1; i++, j++) { if (doPercentageOutput) { diff --git a/src/TALib.NETCore/TAFunc/TA_MacdExt.cs b/src/TALib.NETCore/TAFunc/TA_MacdExt.cs index 2f16cf8..1b359c4 100644 --- a/src/TALib.NETCore/TAFunc/TA_MacdExt.cs +++ b/src/TALib.NETCore/TAFunc/TA_MacdExt.cs @@ -23,16 +23,10 @@ public static RetCode MacdExt(double[] inReal, int startIdx, int endIdx, double[ return RetCode.BadParam; } - int tempInteger; if (optInSlowPeriod < optInFastPeriod) { - tempInteger = optInSlowPeriod; - optInSlowPeriod = optInFastPeriod; - optInFastPeriod = tempInteger; - - MAType tempMAType = optInSlowMAType; - optInSlowMAType = optInFastMAType; - optInFastMAType = tempMAType; + (optInSlowPeriod, optInFastPeriod) = (optInFastPeriod, optInSlowPeriod); + (optInSlowMAType, optInFastMAType) = (optInFastMAType, optInSlowMAType); } int lookbackSignal = MaLookback(optInSignalMAType, optInSignalPeriod); @@ -48,7 +42,7 @@ public static RetCode MacdExt(double[] inReal, int startIdx, int endIdx, double[ return RetCode.Success; } - tempInteger = endIdx - startIdx + 1 + lookbackSignal; + var tempInteger = endIdx - startIdx + 1 + lookbackSignal; var fastMABuffer = new double[tempInteger]; var slowMABuffer = new double[tempInteger]; @@ -115,16 +109,10 @@ public static RetCode MacdExt(decimal[] inReal, int startIdx, int endIdx, decima return RetCode.BadParam; } - int tempInteger; if (optInSlowPeriod < optInFastPeriod) { - tempInteger = optInSlowPeriod; - optInSlowPeriod = optInFastPeriod; - optInFastPeriod = tempInteger; - - MAType tempMAType = optInSlowMAType; - optInSlowMAType = optInFastMAType; - optInFastMAType = tempMAType; + (optInSlowPeriod, optInFastPeriod) = (optInFastPeriod, optInSlowPeriod); + (optInSlowMAType, optInFastMAType) = (optInFastMAType, optInSlowMAType); } int lookbackSignal = MaLookback(optInSignalMAType, optInSignalPeriod); @@ -140,7 +128,7 @@ public static RetCode MacdExt(decimal[] inReal, int startIdx, int endIdx, decima return RetCode.Success; } - tempInteger = endIdx - startIdx + 1 + lookbackSignal; + var tempInteger = endIdx - startIdx + 1 + lookbackSignal; var fastMABuffer = new decimal[tempInteger]; var slowMABuffer = new decimal[tempInteger]; diff --git a/src/TALib.NETCore/TAFunc/TA_StochRsi.cs b/src/TALib.NETCore/TAFunc/TA_StochRsi.cs index d047f92..19a9e8c 100644 --- a/src/TALib.NETCore/TAFunc/TA_StochRsi.cs +++ b/src/TALib.NETCore/TAFunc/TA_StochRsi.cs @@ -19,7 +19,7 @@ public static RetCode StochRsi(double[] inReal, int startIdx, int endIdx, double return RetCode.BadParam; } - int lookbackSTOCHF = StochFLookback(optInFastDMAType); + int lookbackSTOCHF = StochFLookback(optInFastDMAType, optInFastKPeriod, optInFastDPeriod); int lookbackTotal = StochRsiLookback(optInFastDMAType, optInTimePeriod, optInFastKPeriod, optInFastDPeriod); if (startIdx < lookbackTotal) { @@ -67,7 +67,7 @@ public static RetCode StochRsi(decimal[] inReal, int startIdx, int endIdx, decim return RetCode.BadParam; } - int lookbackSTOCHF = StochFLookback(optInFastDMAType); + int lookbackSTOCHF = StochFLookback(optInFastDMAType, optInFastKPeriod, optInFastDPeriod); int lookbackTotal = StochRsiLookback(optInFastDMAType, optInTimePeriod, optInFastKPeriod, optInFastDPeriod); if (startIdx < lookbackTotal) { diff --git a/src/TALib.NETCore/TAFunc/TA_Sub.cs b/src/TALib.NETCore/TAFunc/TA_Sub.cs index 52dc836..9d29b07 100644 --- a/src/TALib.NETCore/TAFunc/TA_Sub.cs +++ b/src/TALib.NETCore/TAFunc/TA_Sub.cs @@ -47,7 +47,7 @@ public static RetCode Sub(decimal[] inReal0, decimal[] inReal1, int startIdx, in int outIdx = default; for (int i = startIdx; i <= endIdx; i++) { - outReal[outIdx++] = inReal0[i] * inReal1[i]; + outReal[outIdx++] = inReal0[i] - inReal1[i]; } outBegIdx = startIdx; diff --git a/src/TALib.NETCore/TALib.NETCore.csproj b/src/TALib.NETCore/TALib.NETCore.csproj index c900e8e..cd8cdcd 100644 --- a/src/TALib.NETCore/TALib.NETCore.csproj +++ b/src/TALib.NETCore/TALib.NETCore.csproj @@ -10,7 +10,7 @@ TicTacTec LLC LICENSE https://ta-lib.org - 0.4.3 + 0.4.4 https://github.com/hmG3/TA-Lib.NETCore git talib.png