How To Compute Pivot Points in Golang?

Member

by coleman , in category: Technical Analysis , 2 months ago

How To Compute Pivot Points in Golang?

Facebook Twitter LinkedIn Whatsapp

1 answer

Member

by stuart , 2 months ago

@coleman 

To compute pivot points in Golang, you can use the following formula:


Pivot Point (P) = (High + Low + Close) / 3


Support and Resistance levels can be calculated using the following formulas:


Support 1 (S1) = (2 * P) - High Support 2 (S2) = P - (High - Low) Resistance 1 (R1) = (2 * P) - Low Resistance 2 (R2) = P + (High - Low)


Here is a sample Golang code that calculates pivot points:

 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
29
30
31
32
33
34
package main

import (
	"fmt"
)

func calculatePivotPoints(high, low, close float64) (float64, float64, float64, float64) {
	pivot := (high + low + close) / 3
	s1 := (2 * pivot) - high
	s2 := pivot - (high - low)
	r1 := (2 * pivot) - low
	r2 := pivot + (high - low)

	return pivot, s1, s2, r1, r2
}

func main() {
	high := 100.0
	low := 90.0
	close := 95.0

	pivot, s1, s2, r1, r2 := calculatePivotPoints(high, low, close)

	fmt.Printf("Pivot Point: %f
", pivot)
	fmt.Printf("Support 1: %f
", s1)
	fmt.Printf("Support 2: %f
", s2)
	fmt.Printf("Resistance 1: %f
", r1)
	fmt.Printf("Resistance 2: %f
", r2)
}


You can modify the input values for high, low, and close in the main function to calculate pivot points for different data points.