# How To Calculate Stochastic Oscillator using Lisp?

, in category: Technical Analysis , 4 months ago

How To Calculate Stochastic Oscillator using Lisp?

Member

by morton , 4 months ago

﻿@shirley.reilly ﻿

Here is a sample code snippet in Lisp to calculate the Stochastic Oscillator for a given set of data points:

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ``` ```(defun calculate_stochastic_oscillator (data-points k-period d-period) (let* ((lowest-low (reduce #'min data-points)) (highest-high (reduce #'max data-points)) (%k-values '()) (%d-values '())) (dotimes (i (- (length data-points) k-period)) (let ((current-data (subseq data-points i (+ i k-period)))) (let ((current-lowest (reduce #'min current-data)) (current-highest (reduce #'max current-data)) (%k-value (/ (- (car (last current-data)) current-lowest) (- current-highest current-lowest)))) (push %k-value %k-values)))) (dotimes (i (- (length %k-values) d-period)) (let ((current-data (subseq %k-values i (+ i d-period)))) (let ((%d-value (/ (reduce #'+ current-data) d-period))) (push %d-value %d-values)))) (list %k-values %d-values))) ;; Example usage: (setq data-points '(14 15 16 17 18 19 18 17 16 15)) (calculate_stochastic_oscillator data-points 5 3) ```

In this code snippet, we define a function `calculate_stochastic_oscillator` that takes in a list of data points, the K-period, and the D-period as input parameters. The function then calculates the %K and %D values based on the Stochastic Oscillator formula. The function returns a list of %K values and %D values.

You can call this function with your data points and specify the K-period and D-period to get the Stochastic Oscillator values.

, 2 months ago

﻿@shirley.reilly ﻿

The provided code snippet in Lisp calculates Stochastic Oscillator values based on the input parameters for data-points, K-period, and D-period. The calculation involves finding the highest high and lowest low within the data points, computing %K values, then further computing %D values. The result is a list containing %K values and %D values.

You can use this code snippet by copying it into your Lisp environment and calling the calculate_stochastic_oscillator function with your desired data points along with the specified K-period and D-period values. The function will return the Stochastic Oscillator values accordingly.

If you have any specific questions or need further assistance in implementing or understanding the Stochastic Oscillator calculation in Lisp, feel free to ask.