forked from jjttjj/trateg
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
awb99
committed
Mar 28, 2024
1 parent
fb54c06
commit ccdbf3e
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns ta.indicator.candles | ||
(:require | ||
[tech.v3.datatype.functional :as dfn] | ||
[ta.indicator :as ind])) | ||
|
||
(defn doji | ||
"A candle is considered Doji if its body height is lower than the average | ||
multiplied by a factor. | ||
http://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:introduction_to_candlesticks#doji</a> | ||
input: options + bar-ds | ||
output: column with doji-signal (boolean)" | ||
[n k bar-ds] | ||
(assert n "doji needs n parameter") | ||
(assert k "doji needs k parameter") | ||
(let [open-close (dfn/- (:close bar-ds) (:open bar-ds)) | ||
avg-open-close (ind/sma {:n n} open-close) | ||
avg-open-close-k (dfn/* avg-open-close k) | ||
prior-avg-open-close-k (ind/prior avg-open-close-k)] | ||
(dfn/< open-close prior-avg-open-close-k))) | ||
|
||
(defn doji-absolute | ||
"doji is a bar with Big range + small movement. | ||
input: options + bar-ds | ||
output: column with doji-signal" | ||
[max-open-close-over-low-high bar-ds] | ||
(assert max-open-close-over-low-high "doji needs max-open-close-over-low-high parameter") | ||
(let [low-high (dfn/- (:high bar-ds) (:low bar-ds)) | ||
open-close (dfn/- (:close bar-ds) (:open bar-ds)) | ||
open-close-over-low-high (dfn// open-close low-high)] | ||
(dfn/< open-close-over-low-high max-open-close-over-low-high))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns ta.indicator.candles-test | ||
(:require [clojure.test :refer :all] | ||
[ta.indicator.util.fuzzy :refer [all-fuzzy=]] | ||
[ta.indicator.util.ta4j :as ta4j] | ||
[ta.indicator.util.data :refer [ds]] | ||
[ta.indicator.candles :as indc])) | ||
|
||
|
||
;; TESTS | ||
|
||
#_(deftest test-doji | ||
(is (all-fuzzy= | ||
0.1 | ||
(ta4j/bar ds :volume/VWAP 2) | ||
(vind/vwap 2 ds)))) | ||
|
||
|
||
(comment | ||
(:close ds) | ||
|
||
(ta4j/bar-bool ds :candles/Doji 2 1) | ||
;; => (true false false true true | ||
;; false false false true true | ||
;; true true false true false) | ||
|
||
|
||
(indc/doji 2 1 ds) | ||
;; => [false false false true true | ||
;; false false true true false | ||
;; true true true false false] | ||
|
||
|
||
|
||
; | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters