How To Compute Williams %R in Julia?

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

How To Compute Williams %R in Julia?

Facebook Twitter LinkedIn Whatsapp

1 answer

by ayana_reilly , a month ago

@paris_marquardt 

To compute Williams %R in Julia, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
using Statistics

function williams_r(data, period)
    length_data = length(data)
    wr = fill(missing, length_data)
    
    for i in period:length_data
        max_high = maximum(data[i - period + 1:i])
        min_low = minimum(data[i - period + 1:i])
        wr[i] = ((max_high - data[i]) / (max_high - min_low)) * -100
    end
    
    return wr
end

# Example usage
data = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
period = 5
result = williams_r(data, period)
println(result)


In this code snippet, we define a function williams_r that takes in a data array and a period parameter. The function calculates Williams %R values for each data point based on the given period. It then returns an array of Williams %R values.


You can test this code snippet by providing your own dataset and period values.