Skip to content

Commit

Permalink
intrabar range, cross with clone
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Sep 25, 2024
1 parent 7381da1 commit db6a7b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
3 changes: 1 addition & 2 deletions lib/indicator/src/ta/indicator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@
(assert (has-col bar-ds :high) "tr needs :high column in bar-ds")
(let [{:keys [high low]} bar-ds
hl (dfn/- high low)]
hl))

hl))

(defn tr
"input: bar-ds with (:low :high :close) columns
Expand Down
42 changes: 24 additions & 18 deletions lib/indicator/src/ta/indicator/signal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@

(defn cross-up [price indicator]
(let [n (count price)]
(dtype/make-reader
:boolean n
(if
(= idx 0)
false
(and (> (price idx)
(indicator idx))
(<= (price (dec idx))
(indicator (dec idx))))))))
; 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
:boolean n
(if
(= idx 0)
false
(and (> (price idx)
(indicator idx))
(<= (price (dec idx))
(indicator (dec idx)))))))))

(defn cross-down [price indicator]
(let [n (count price)]
(dtype/make-reader
:boolean n
(if
(= idx 0)
false
(and (< (price idx)
(indicator idx))
(>= (price (dec idx))
(indicator (dec idx))))))))
; 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
:boolean n
(if
(= idx 0)
false
(and (< (price idx)
(indicator idx))
(>= (price (dec idx))
(indicator (dec idx)))))))))

(defn buy-above [p o]
(if (and p o)
Expand Down

0 comments on commit db6a7b0

Please sign in to comment.