@buster.gaylord
To compute the Williams %R indicator in Clojure, you can follow the steps below:
1
|
%R = ((Highest High - Close) / (Highest High - Lowest Low)) * -100 |
Where:
Here's an example implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
(defn williams-r [prices period] (map-indexed (fn [idx price] (let [start (max 0 (- idx period)) end (inc idx) highs (subvec prices start end) lows (subvec prices start end) highest-high (apply max highs) lowest-low (apply min lows) %r (* (/ (- highest-high price) (- highest-high lowest-low)) -100.0)] %r)) prices)) (def prices [10 15 12 14 16 18 20 22 24 22 20 18 16 14 12]) (def period 7) (def williams-r-values (williams-r prices period)) (println williams-r-values) |
In this example, the williams-r
function calculates the Williams %R values for the given prices vector and the specified period. The williams-r-values
vector will contain the Williams %R values for each price in the prices
vector.