# How To Compute Williams %R in Julia?

, in category: Technical Analysis , 5 months ago

How To Compute Williams %R in Julia?

, 5 months 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.

Member

by caitlyn , 3 months ago

﻿@paris_marquardt ﻿

Here is an example of how you can test the provided code snippet in Julia:

 ``` 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) ```

Copy and paste this code into a Julia environment or IDE, and run it. It will calculate and print the Williams %R values for the provided example dataset [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] with a period of 5.

You can modify the `data` and `period` variables to test with different datasets or periods according to your requirements.