-
Notifications
You must be signed in to change notification settings - Fork 8
/
pattern_harami.R
104 lines (86 loc) · 1.87 KB
/
pattern_harami.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# script: Harami Patterns
# date: 2024-02-10
# author: Serkan Korkmaz, serkor1@duck.com
# objective: Collect Harami Patterns
# script start;
#' Determine bearish harami pattern using a OHLC price series
#'
#' @description
#'
#' `r lifecycle::badge("experimental")`
#'
#'
#' @param ohlc OHLC prices.
#'
#' @family harami-patterns
#' @family 2-day patterns
#'
#' @returns A [logical]-vector of same length
#'
#' @author Chiu-Yu Ko
#'
#' @export
bearish_harami <- function(
ohlc) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
body_top <- body_feature(
ohlc = ohlc,
feature = "top"
)
body_bottom <- body_feature(
ohlc = ohlc,
feature = "bottom"
)
l_body_top <- xts::lag.xts(body_top)
l_body_bottom <- xts::lag.xts(body_bottom)
bull_candle <- bullish_candle(ohlc = ohlc)
bear_candle <- bearish_candle(ohlc = ohlc)
l_bull_candle <- xts::lag.xts(bull_candle)
bear_candle &
l_bull_candle &
body_top <= l_body_top &
body_bottom >= l_body_bottom
}
#' Determine bullish harami pattern using a OHLC price series
#'
#' @description
#'
#' `r lifecycle::badge("experimental")`
#'
#'
#' @param ohlc OHLC prices.
#'
#' @family harami-patterns
#' @family 2-day patterns
#'
#' @returns A [logical]-vector of same length
#'
#' @author Chiu-Yu Ko
#'
#' @export
bullish_harami <- function(
ohlc) {
# check ohlc input
# before anything
is_ohlc(ohlc = ohlc)
body_top <- body_feature(
ohlc = ohlc,
feature = "top"
)
body_bottom <- body_feature(
ohlc = ohlc,
feature = "bottom"
)
l_body_top <- xts::lag.xts(body_top)
l_body_bottom <- xts::lag.xts(body_bottom)
bull_candle <- bullish_candle(ohlc = ohlc)
bear_candle <- bearish_candle(ohlc = ohlc)
l_bear_candle <- xts::lag.xts(bear_candle)
bull_candle &
l_bear_candle &
body_top <= l_body_top &
body_bottom >= l_body_bottom
}
# script end;