Skip to content

Commit

Permalink
added signalcount-while
Browse files Browse the repository at this point in the history
  • Loading branch information
wizard50 committed Sep 26, 2024
1 parent db6a7b0 commit 86f15f5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/indicator/src/ta/indicator/signal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@
:else ; prior=false signal=true => reset to 0.
(vreset! prior 0))))))

(defn signalcount-while
"while condition is true, count the number of signals"
[active signal]
(assert (= (count active) (count signal)))
(let [c (volatile! 0)
n (count active)]
; dtype/clone is essential. otherwise on large datasets, the mapping will not
; be done in sequence, which means that the stateful mapping function will fail.
(dtype/clone
(dtype/make-reader
:int64 n
(if (active idx)
(if (signal idx)
(vswap! c inc)
@c)
(vreset! c 0))))))

(comment

(buyhold-signal-bar-length 5)
Expand Down Expand Up @@ -182,5 +199,8 @@

(price-when (:price ds) (:signal ds))

(signalcount-while [false true true true false false true true false]
[false true false true false true false true true])

;
)

0 comments on commit 86f15f5

Please sign in to comment.