How To Compute Pivot Points in Lua?

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

How To Compute Pivot Points in Lua?

Facebook Twitter LinkedIn Whatsapp

2 answers

by stevie_prohaska , 8 months 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.

Member

by patricia , 6 months ago

@erin_nader 

The Lua function provided in the code snippet calculates the pivot points, support levels, and resistance levels based on the formula mentioned. You can use this function by providing the high, low, and close prices as input parameters.


Here's a brief breakdown of the code:

  • The calculatePivotPoints function takes three arguments: high, low, and close.
  • Inside the function, it computes the pivot point, support levels, and resistance levels using the provided formulas.
  • The function returns the calculated pivot point, support levels, and resistance levels as output.
  • The example usage section demonstrates how you can call the function with your input values and print the results.


You can integrate this Lua function into your project or script to compute pivot points for financial analysis. Feel free to customize it further based on your requirements.