So far, our
moving-average function only gives us a partitioned list of prices (or ticks). Now, we only need to visit a sliced list at each increment and calculate each increment's price average. The
reduce function provides a way of accumulating (or folding over) each item in a list and producing a result based on those values. We'll take our partitioned list and have
reduce apply an accumulator function on each sublist. The form looks roughly like this:
(reduce (fn [accumulated-result-so-far each-item-list] ;; ** single line comments come after semi-colons ;; do stuff, return accumulated result ;; for each item iteration ) initial-list-of-accumulated-values initial-list-of-input-values)
Our accumulator function only has ...