Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

Sub CalculateStochasticRSI() ’ Set the parameters for the Stochastic RSI calculation…

  1. User

    Sub Calculate_Stochastic_RSI()

    ’ Set the parameters for the Stochastic RSI calculation Const RSI_length As Integer = 14 Const Stoch_length As Integer = 14 Const SmoothK_length As Integer = 3 Const SmoothD_length As Integer = 3

    ’ Define the range for the RSI values Dim RSI_Range As Range Set RSI_Range = Range(“F15:F” & Cells(Rows.Count, “F”).End(xlUp).row)

    ’ Iterate through the RSI values and calculate the Stochastic RSI values Dim i As Long For i = RSI_length + Stoch_length - 1 To RSI_Range.Rows.Count ’ Get the maximum and minimum RSI values for the Stochastic period Dim MaxRSI As Double, MinRSI As Double MaxRSI = Application.WorksheetFunction.Max(RSI_Range.Cells(i - Stoch_length + 1, 1).Resize(Stoch_length, 1)) MinRSI = Application.WorksheetFunction.Min(RSI_Range.Cells(i - Stoch_length + 1, 1).Resize(Stoch_length, 1))

    ’ Calculate the %K value RSI_Range.Cells(i, 2) = (RSI_Range.Cells(i, 1) - MinRSI) / (MaxRSI - MinRSI)

    ’ Calculate the smoothed %K value using the SmoothK_length If i >= RSI_length + Stoch_length + SmoothK_length - 2 Then RSI_Range.Cells(i, 3) = Application.WorksheetFunction.Average(RSI_Range.Cells(i - SmoothK_length + 1, 2).Resize(SmoothK_length, 1)) End If

    ’ Calculate the %D value using the SmoothD_length If i >= RSI_length + Stoch_length + SmoothK_length + SmoothD_length - 3 Then RSI_Range.Cells(i, 4) = Application.WorksheetFunction.Average(RSI_Range.Cells(i - SmoothD_length + 1, 3).Resize(SmoothD_length, 1)) End If Next i

    End Sub if rsi is in column e modify the code

  2. Assistant

    Sub Calculate_Stochastic_RSI()

    ’ Set the parameters for the Stochastic RSI calculation Const RSI_length As Integer = 14 Const Stoch_length As Integer = 14 Const SmoothK_length As Integer = 3 Const SmoothD_length As Integer = 3

    ’ Define the range for the RSI values Dim RSI_Range As Range Set RSI_Range = Range("E15:E" & Cells(Rows.Count, "E").End(xlUp).row)

    ’ Iterate through the RSI values and calculate the Stochastic RSI values Dim i As Long For i = RSI_length + Stoch_length - 1 To RSI_Range.Rows.Count ’ Get the maximum and minimum RSI values for the Stochastic period Dim MaxRSI As Double, MinRSI As Double MaxRSI = Application.WorksheetFunction.Max(RSI_Range.Cells(i - Stoch_length + 1, 1).Resize(Stoch_length, 1)) MinRSI = Application.WorksheetFunction.Min(RSI_Range.Cells(i - Stoch_length + 1, 1).Resize(Stoch_length, 1))

    ’ Calculate the %K value RSI_Range.Cells(i, 2) = (RSI_Range.Cells(i, 1) - MinRSI) / (MaxRSI - MinRSI)

    ’ Calculate the smoothed %K value using the SmoothK_length If i >= RSI_length + Stoch_length + SmoothK_length - 2 Then RSI_Range.Cells(i, 3) = Application.WorksheetFunction.Average(RSI_Range.Cells(i - SmoothK_length + 1, 2).Resize(SmoothK_length, 1)) End If

    ’ Calculate the %D value using the SmoothD_length If i >= RSI_length + Stoch_length + SmoothK_length + SmoothD_length - 3 Then RSI_Range.Cells(i, 4) = Application.WorksheetFunction.Average(RSI_Range.Cells(i - SmoothD_length + 1, 3).Resize(SmoothD_length, 1)) End If Next i

    End Sub