-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.inp
153 lines (128 loc) · 5.57 KB
/
patterns.inp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Patterns functions
# ==================
function series hammer(const bundle d, scalar l[0:1:0])
series isBlack = !is_white(d)
series shortBody = is_body_short(d)
series longBottomShadow = is_bottom_shadow_long(d)
series shortUpShadow = top_shadow_len(d) <= (l * body_len(d))
series trend = lag(1, d.trend) < 0
series notDoji = !is_doji(d)
list l_and = isBlack shortBody longBottomShadow shortUpShadow trend notDoji
series out = and(l_and)
set_description(&out, sprintf("Hammer - l = %g",l))
return out
end function
function series dark_cloud_cover(const bundle d)
series precWhite = lag(1, is_white(d))
series currentBlack = !is_white(d)
series precLong = lag(1, is_body_long(d))
series openAbovePrec = d.open > lag(1,body_top(d))
series closeBelowMeanPrec = d.close < lag(1, mean_price(d))
series trend = lag(2, d.trend) > 0
series notDoji = !is_doji(d)
list l_and = precWhite currentBlack precLong openAbovePrec closeBelowMeanPrec trend notDoji
series out = and(l_and)
set_description(&out, "Dark Cloud Cover")
return out
end function
function series piercing_lines(const bundle d)
series precBlack = lag(1, !is_white(d))
series currentWhite = is_white(d)
series precLong = lag(1, is_body_long(d))
series openBelowPrec = d.open < lag(1,body_bottom(d))
series closeAboveMeanPrec = d.close > lag(1, mean_price(d))
series trend = lag(2, d.trend) < 0
series notDoji = !is_doji(d)
list l_and = precBlack currentWhite precLong openBelowPrec closeAboveMeanPrec trend notDoji
series out = and(l_and)
set_description(&out, "Piercing Lines")
return out
end function
function series evening_star(const bundle d)
series firstWhite = lag(2, is_white(d))
series firstLong = lag(2, is_body_long(d))
series secondBlack = !lag(1, is_white(d))
series seconShort = lag(1, is_body_short(d))
series lastBlack = !is_white(d)
series lastLong = is_body_long(d)
series gapFirstSecond = lag(2, body_top(d)) <= lag(1, body_bottom(d))
series gapSecondLast = lag(1, body_bottom(d)) >= body_top(d)
series trend = lag(3, d.trend) > 0
series notDoji = !is_doji(d)
list l_and = firstWhite firstLong secondBlack seconShort lastBlack lastLong gapFirstSecond gapSecondLast time notDoji
out = and(l_and)
set_description(&out, "Evening Star")
return out
end function
function series morning_star(const bundle d)
series firstBlack = !lag(2, is_white(d))
series firstLong = lag(2, is_body_long(d))
series secondBlack = !lag(1, is_white(d))
series seconShort = lag(1, is_body_short(d))
series lastWhite = is_white(d)
series lastLong = is_body_long(d)
series gapFirstSecond = lag(2, body_bottom(d)) >= lag(1, body_top(d))
series gapSecondLast = lag(1, body_top(d)) <= body_bottom(d)
series trend = lag(3, d.trend) < 0
series notDoji = !is_doji(d)
list l_and = firstBlack firstLong secondBlack seconShort lastWhite lastLong gapFirstSecond gapSecondLast time notDoji
out = and(l_and)
set_description(&out, "Morning Star")
return out
end function
function series rising_three(const bundle d, scalar days[3::3], scalar w[::0], bool inBody[0])
#days numero di giorni tra la prima e ultima candela bianca
#w numero di candele bianche che possono esserci tra primo e ultimo
series firstWhite = lag(days+1, is_white(d))
series firstLong = lag(days+1, is_body_long(d))
series lastWhite = is_white(d)
series lastLong = is_body_long(d)
series notDoji = !is_doji(d)
list tempL = firstWhite firstLong lastWhite lastLong notDoji
list blackCandles = null
loop t=1..days
series isBodyShort_$t = lag(t, is_body_short(d))
series isBlack_$t = lag(t, !is_white(d))
tempL += isBodyShort_$t
blackCandles += isBlack_$t
if inBody
series maxBelow_$t = lag((days + 1), body_top(d)) > lag(t, body_top(d))
series minOver_$t = lag((days + 1), body_bottom(d)) < lag(t, body_bottom(d))
tempL += maxBelow_$t minOver_$t
endif
endloop
series nBlack = ( sum(blackCandles) >= (days - w) )
series trend = lag(days + 2, d.trend) > 0
tempL += nBlack trend
series out = and(tempL)
set_description(&out, sprintf("Rising Three, days: %d, w: %d, inBody: %d", days, w, inBody))
return out
end function
function series falling_three(const bundle d, scalar days[3::3], scalar b[::0], bool inBody[0])
# days: days between first and last black candle
# b: max number of black candles allow between first and last
series firstBlack = lag(days+1, !is_white(d))
series firstLong = lag(days+1, is_body_long(d))
series lastBlack = !is_white(d)
series lastLong = is_body_long(d)
series notDoji = !is_doji(d)
list tempL = firstBlack firstLong lastBlack lastLong notDoji
list whiteCandles = null
loop t=1..days
series isBodyShort_$t = lag(t, is_body_short(d))
series isWhite_$t = lag(t, is_white(d))
tempL += isBodyShort_$t
whiteCandles += isWhite_$t
if inBody
series maxBelow_$t = lag((days + 1), body_top(d)) > lag(t, body_top(d))
series minOver_$t = lag((days + 1), body_bottom(d)) < lag(t, body_bottom(d))
tempL += maxBelow_$t minOver_$t
endif
endloop
series nWhite = ( sum(whiteCandles) >= (days - b) )
series trend = lag(days + 2, d.trend) < 0
tempL += nWhite trend
series out = and(tempL)
set_description(&out, sprintf("Falling Three, days: %d, b: %d, inBody: %d", days, b, inBody))
return out
end function