Public Shared Function Calc_JMATurbo(ByVal Data() As RTT_Structures.OHLC, ByVal Length As Integer, Optional ByVal Phase As Integer = 0) As Double() Dim JMAValueBuffer(Data.GetUpperBound(0)) As Double Dim fC0Buffer(Data.GetUpperBound(0)) As Double Dim fA8Buffer(Data.GetUpperBound(0)) As Double Dim fC8Buffer(Data.GetUpperBound(0)) As Double Dim list(128) As Double Dim ring1(128) As Double Dim ring2(11) As Double Dim buffer(62) As Double Dim initFlag As Boolean Dim limitValue As Integer = 63 Dim startValue As Integer = 64 Dim loopParam As Integer Dim loopCriteria As Integer Dim cycleLimit As Integer Dim highLimit As Integer Dim counterA As Integer Dim counterB As Integer Dim cycleDelta As Double Dim lowDValue As Double Dim highDValue As Double Dim absValue As Double Dim paramA As Double Dim paramB As Double Dim phaseParam As Double Dim logParam As Double Dim JMAValue As Double Dim series As Double Dim sValue As Double Dim sqrtParam As Double Dim lengthDivider As Double Dim s58 As Integer Dim s60 As Integer Dim s40 As Integer Dim s38 As Integer Dim s68 As Integer Dim lengthParam As Double Dim diffFlag As Integer Dim dValue As Double Dim JMATempValue As Double Dim sqrtDivider As Double Dim intPart As Integer Dim leftInt As Integer Dim rightPart As Integer Dim upshift As Integer Dim dnshift As Integer Dim powerValue As Double Dim squareValue As Double 'SETUP For i As Integer = 0 To limitValue list(i) = -1000000 Next For i As Integer = startValue To 127 list(i) = 1000000 Next initFlag = True If (Length < 1.0000000002) Then lengthParam = 0.0000000001 Else lengthParam = (Length - 1) / 2.0 End If If (Phase < -100) Then phaseParam = 0.5 ElseIf (Phase > 100) Then phaseParam = 2.5 Else phaseParam = Phase / 100.0 + 1.5 End If logParam = Math.Log(Math.Sqrt(lengthParam)) / Math.Log(2.0) If (logParam + 2.0 < 0) Then logParam = 0 Else logParam = logParam + 2.0 End If sqrtParam = Math.Sqrt(lengthParam) * logParam lengthParam = lengthParam * 0.9 lengthDivider = lengthParam / (lengthParam + 2.0) 'Debug.Write("1 / " & sqrtParam & " / " & lengthParam & " / " & lengthDivider & vbNewLine) 'RUN thru data For k As Integer = 0 To Data.GetUpperBound(0) series = (Data(k).nClose + Data(k).nHigh + Data(k).nLow) / 3 If (loopParam < 61) Then buffer(loopParam) = series loopParam += 1 End If If (loopParam > 30) Then If initFlag = True Then initFlag = False diffFlag = 0 For i As Integer = 1 To 29 If (buffer(i + 1) <> buffer(i)) Then diffFlag = 1 Next End If highLimit = diffFlag * 30 If (highLimit = 0) Then paramB = series Else paramB = buffer(1) End If paramA = paramB If (highLimit > 29) Then highLimit = 29 Else highLimit = 0 End If 'Debug.Write("3 / " & Data(k).nClose & " / " & k & " / " & highLimit & " / " & paramA & vbNewLine) 'BIG CYCLE For i As Integer = highLimit To 0 Step -1 If i = 0 Then sValue = series Else sValue = buffer(31 - i) End If If (Math.Abs(sValue - paramA) > Math.Abs(sValue - paramB)) Then absValue = Math.Abs(sValue - paramA) Else absValue = Math.Abs(sValue - paramB) End If dValue = 0 dValue = absValue + 0.0000000001 If (counterA <= 1) Then counterA = 127 Else counterA -= 1 End If If (counterB <= 1) Then counterB = 10 Else counterB -= 1 End If If (cycleLimit < 128) Then cycleLimit += 1 cycleDelta += (dValue - ring2(counterB)) ring2(counterB) = dValue If (cycleLimit > 10) Then highDValue = cycleDelta / 10.0 Else highDValue = cycleDelta / cycleLimit End If If cycleLimit > 127 Then dValue = ring1(counterA) ring1(counterA) = highDValue s68 = 64 s58 = s68 While s68 > 1 If list(s58) < dValue Then s68 = CInt(s68 / 2.0) s58 += s68 ElseIf list(s58) <= dValue Then s68 = 1 Else s68 = CInt(s68 / 2.0) s58 -= s68 End If End While Else ring1(counterA) = highDValue If (limitValue + startValue) > 127 Then startValue -= 1 s58 = startValue Else limitValue += 1 s58 = limitValue End If If limitValue > 96 Then s38 = 96 Else s38 = limitValue End If If startValue < 32 Then s40 = 32 Else s40 = startValue End If End If s68 = 64 s60 = s68 While s68 > 1 If list(s60) >= highDValue Then If list(s60 - 1) <= highDValue Then s68 = 1 Else s68 = CInt(s68 / 2.0) s60 -= s68 End If Else s68 = CInt(s68 / 2.0) s60 += s68 End If If (s60 = 127) AndAlso (highDValue > list(127)) Then s60 = 128 End If End While If cycleLimit > 127 Then If s58 >= s60 Then If ((s38 + 1) > s60) AndAlso ((s40 - 1) < s60) Then lowDValue += highDValue ElseIf (s40 > s60) AndAlso ((s40 - 1) < s58) Then lowDValue += list(s40 - 1) End If ElseIf s40 >= s60 Then If ((s38 + 1) < s60) AndAlso ((s38 + 1) > s58) Then lowDValue += list(s38 + 1) End If ElseIf (s38 + 2) > s60 Then lowDValue += highDValue ElseIf ((s38 + 1) < s60) AndAlso ((s38 + 1) > s58) Then lowDValue += list(s38 + 1) End If If s58 > s60 Then If ((s40 - 1) < s58) AndAlso ((s38 + 1) > s58) Then lowDValue -= list(s58) ElseIf (s38 < s58) AndAlso ((s38 + 1) > s60) Then lowDValue -= list(s38) End If Else If ((s38 + 1) > s58) AndAlso ((s40 - 1) < s58) Then lowDValue -= list(s58) ElseIf (s40 > s58) AndAlso (s40 < s60) Then lowDValue -= list(s40) End If End If End If If s58 <= s60 Then If s58 >= s60 Then list(s60) = highDValue Else For j As Integer = s58 + 1 To (s60 - 1) list(j - 1) = list(j) Next list(s60 - 1) = highDValue End If Else For j As Integer = s58 - 1 To s60 Step -1 list(j + 1) = list(j) Next list(s60) = highDValue End If If cycleLimit <= 127 Then lowDValue = 0 For j As Integer = s40 To s38 lowDValue += list(j) Next End If If (loopCriteria + 1) > 31 Then loopCriteria = 31 Else loopCriteria += 1 End If JMATempValue = 0 sqrtDivider = 0 sqrtDivider = sqrtParam / (sqrtParam + 1.0) If loopCriteria <= 30 Then If (sValue - paramA) > 0 Then paramA = sValue Else paramA = sValue - (sValue - paramA) * sqrtDivider End If If (sValue - paramB) < 0 Then paramB = sValue Else paramB = sValue - (sValue - paramB) * sqrtDivider End If JMATempValue = series If loopCriteria = 30 Then fC0Buffer(k) = series intPart = 0 rightPart = 0 leftInt = 0 If Math.Ceiling(sqrtParam) >= 1 Then intPart = CInt(Math.Ceiling(sqrtParam)) Else intPart = 1 End If leftInt = CInt(intPart) If Math.Floor(sqrtParam) >= 1 Then intPart = CInt(Math.Floor(sqrtParam)) Else intPart = 1 End If rightPart = CInt(intPart) If (leftInt = rightPart) Then dValue = 1.0 Else dValue = (sqrtParam - rightPart) / (leftInt - rightPart) End If upshift = 0 dnshift = 0 If (rightPart <= 29) Then upshift = rightPart Else upshift = 29 End If If (leftInt <= 29) Then dnshift = leftInt Else dnshift = 29 End If fA8Buffer(k) = (series - buffer(loopParam - upshift)) * (1 - dValue) / rightPart + _ (series - buffer(loopParam - CInt(dnshift))) * dValue / leftInt Else powerValue = 0 squareValue = 0 dValue = lowDValue / (s38 - s40 + 1) If 0.5 <= logParam - 2.0 Then powerValue = logParam - 2.0 Else powerValue = 0.5 End If If logParam >= Math.Pow(absValue / dValue, powerValue) Then dValue = Math.Pow(absValue / dValue, powerValue) Else dValue = logParam End If If dValue < 1 Then dValue = 1 End If powerValue = Math.Pow(sqrtDivider, Math.Sqrt(dValue)) If sValue - paramA > 0 Then paramA = sValue Else paramA = sValue - (sValue - paramA) * powerValue End If If sValue - paramB < 0 Then paramB = sValue Else paramB = sValue - (sValue - paramB) * powerValue End If End If End If 'END OF BIG CYCLE If loopCriteria > 30 Then JMATempValue = JMAValueBuffer(k - 1) 'CHANGED powerValue = Math.Pow(lengthDivider, dValue) squareValue = Math.Pow(powerValue, 2) fC0Buffer(k) = (1 - powerValue) * series + powerValue * fC0Buffer(k - 1) 'CHANGED fC8Buffer(k) = (series - fC0Buffer(k)) * (1 - lengthDivider) + lengthDivider * fC8Buffer(k - 1) 'CHANGED fA8Buffer(k) = (phaseParam * fC8Buffer(k) + fC0Buffer(k) - JMATempValue) * (powerValue * (-2.0) + squareValue + 1) + squareValue * fA8Buffer(k - 1) 'CHANGED JMATempValue += fA8Buffer(k) End If JMAValue = JMATempValue Next If (loopParam <= 30) Then JMAValue = 0 JMAValueBuffer(k) = Math.Round(JMAValue, 4) Next Return JMAValueBuffer End Function