@cristobal
To compute Williams %R using Scala, you can follow the steps below:
1 2 3 4 5 6 7 8 |
def williamsR(highPrices: List[Double], lowPrices: List[Double], closePrices: List[Double], period: Int): List[Double] = { highPrices.zip(lowPrices).zip(closePrices).map { case ((high, low), close) => val hh = highPrices.slice(0, period).max val ll = lowPrices.slice(0, period).min ((hh - close) / (hh - ll)) * -100 } } |
1 2 3 4 5 6 7 |
val highPrices = List(10.0, 12.0, 15.0, 14.0, 16.0) val lowPrices = List(8.0, 10.0, 12.0, 11.0, 12.0) val closePrices = List(9.0, 11.0, 14.0, 13.0, 15.0) val period = 5 val williamsRValues = williamsR(highPrices, lowPrices, closePrices, period) println(williamsRValues) |
This is a basic implementation of how to compute Williams %R using Scala. You can further customize or optimize the code based on your specific requirements or use case.