How To Compute Pivot Points in Lua?

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

How To Compute Pivot Points in Lua?

Facebook Twitter LinkedIn Whatsapp

1 answer

by stevie_prohaska , a month ago

@erin_nader 

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


Pivot Point (P) = (High + Low + Close) / 3 Support 1 (S1) = (2P) - High Support 2 (S2) = P - (High - Low) Resistance 1 (R1) = (2P) - Low Resistance 2 (R2) = P + (High - Low)


Here is a simple Lua function that computes pivot points based on the above formula:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
function calculatePivotPoints(high, low, close)
    local pivotPoint = (high + low + close) / 3
    local support1 = (2 * pivotPoint) - high
    local support2 = pivotPoint - (high - low)
    local resistance1 = (2 * pivotPoint) - low
    local resistance2 = pivotPoint + (high - low)
    
    return pivotPoint, support1, support2, resistance1, resistance2
end

-- Example usage
local high = 100
local low = 90
local close = 95

local pivotPoint, support1, support2, resistance1, resistance2 = calculatePivotPoints(high, low, close)

print("Pivot Point: " .. pivotPoint)
print("Support 1: " .. support1)
print("Support 2: " .. support2)
print("Resistance 1: " .. resistance1)
print("Resistance 2: " .. resistance2)


You can input your own values for the high, low, and close prices and call the calculatePivotPoints function to get the pivot points, support levels, and resistance levels.