How To Compute Support and Resistance levels in Visual Basic?

Member

by annalise , in category: Technical Analysis , 3 months ago

How To Compute Support and Resistance levels in Visual Basic?

Facebook Twitter LinkedIn Whatsapp

2 answers

by ayana_reilly , 3 months ago

@annalise 

To compute support and resistance levels in Visual Basic, you can follow these steps:

  1. Define your data: Get historical price data for the stock or security you are analyzing. Define a period of time for which you want to calculate support and resistance levels (e.g. 20 days, 50 days, etc.).
  2. Calculate the Pivot Point: To calculate the Pivot Point, add the high, low, and close prices of the previous day and divide the sum by 3. Pivot Point = (Previous High + Previous Low + Previous Close) / 3
  3. Calculate Support and Resistance levels: Calculate the first support level: S1 = (2 * Pivot Point) - Previous High Calculate the second support level: S2 = Pivot Point - (Previous High - Previous Low) Calculate the first resistance level: R1 = (2 * Pivot Point) - Previous Low Calculate the second resistance level: R2 = Pivot Point + (Previous High - Previous Low)
  4. Implement the calculations in your Visual Basic code: Write Visual Basic functions or subroutines to compute the Pivot Point, support, and resistance levels based on the historical price data. Use loops to iterate through the historical price data and calculate the support and resistance levels for each period. You can also create a user interface to input the historical price data and display the calculated support and resistance levels.
  5. Test and validate your code: Test your code with different historical price data and compare the calculated support and resistance levels with the actual levels observed in the market. Make adjustments to your code as needed to improve accuracy and reliability.


By following these steps, you can compute support and resistance levels in Visual Basic for a given security or stock based on historical price data.

by darby_thiel , 12 days ago

@annalise 

Here is an example of how you can implement the above steps in Visual Basic:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Module SupportResistanceCalculator

    Public Sub CalculateSupportResistance(data As List(Of Double), period As Integer)
        Dim pivotPoint As Double

        For i As Integer = period To data.Count - 1
            pivotPoint = (data(i - 1) + data(i - 2) + data(i - 3)) / 3
            Dim support1 As Double = 2 * pivotPoint - data(i - 1)
            Dim support2 As Double = pivotPoint - (data(i - 1) - data(i - 2))
            Dim resistance1 As Double = 2 * pivotPoint - data(i - 2)
            Dim resistance2 As Double = pivotPoint + (data(i - 1) - data(i - 2))

            Console.WriteLine("Pivot Point: " & pivotPoint)
            Console.WriteLine("Support 1: " & support1)
            Console.WriteLine("Support 2: " & support2)
            Console.WriteLine("Resistance 1: " & resistance1)
            Console.WriteLine("Resistance 2: " & resistance2)
        Next
    End Sub

    Sub Main()
        Dim priceData As New List(Of Double) From {50.0, 48.0, 52.0, 47.0, 49.0, 51.0, 53.0, 55.0, 48.0, 52.0, 54.0}
        Dim period As Integer = 3 ' You can change the period as needed

        CalculateSupportResistance(priceData, period)
    End Sub

End Module


In this code snippet, we first define a CalculateSupportResistance function that takes a list of historical price data and a period as input. The function calculates the support and resistance levels using the Pivot Point formula and prints them out for each period.


In the Main subroutine, we create a sample list of price data and call the CalculateSupportResistance function with the provided data and period to calculate and display the support and resistance levels.


You can modify this code snippet according to your requirements, such as reading historical price data from a file or user input, enhancing the UI for better user interaction, or applying additional filtering or smoothing techniques to the data before calculating support and resistance levels.