-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathpatternMetadata.js
More file actions
324 lines (310 loc) · 8.34 KB
/
patternMetadata.js
File metadata and controls
324 lines (310 loc) · 8.34 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// patternMetadata.js
// Metadata system for pattern confidence and strength
/**
* Pattern metadata definitions
* Each pattern has:
* - type: 'reversal' | 'continuation' | 'neutral'
* - confidence: 0-1 (higher = more reliable)
* - strength: 'weak' | 'moderate' | 'strong'
*/
const patternMetadata = {
// Single candle patterns
hammer: {
type: "reversal",
direction: "bullish",
confidence: 0.7,
strength: "moderate",
description: "Potential bullish reversal with long lower shadow",
},
bullishHammer: {
type: "reversal",
direction: "bullish",
confidence: 0.75,
strength: "moderate",
description: "Bullish hammer with bullish body",
},
bearishHammer: {
type: "reversal",
direction: "bullish",
confidence: 0.65,
strength: "moderate",
description: "Hammer with bearish body (still bullish signal)",
},
invertedHammer: {
type: "reversal",
direction: "bullish",
confidence: 0.65,
strength: "moderate",
description: "Potential bullish reversal with long upper shadow",
},
bullishInvertedHammer: {
type: "reversal",
direction: "bullish",
confidence: 0.7,
strength: "moderate",
description: "Inverted hammer with bullish body",
},
bearishInvertedHammer: {
type: "reversal",
direction: "bullish",
confidence: 0.6,
strength: "weak",
description: "Inverted hammer with bearish body",
},
doji: {
type: "neutral",
direction: "neutral",
confidence: 0.55,
strength: "weak",
description: "Indecision, trend reversal possible",
},
// Two candle patterns
bullishEngulfing: {
type: "reversal",
direction: "bullish",
confidence: 0.85,
strength: "strong",
description: "Strong bullish reversal signal",
},
bearishEngulfing: {
type: "reversal",
direction: "bearish",
confidence: 0.85,
strength: "strong",
description: "Strong bearish reversal signal",
},
bullishHarami: {
type: "reversal",
direction: "bullish",
confidence: 0.7,
strength: "moderate",
description: "Bullish reversal with inside candle",
},
bearishHarami: {
type: "reversal",
direction: "bearish",
confidence: 0.7,
strength: "moderate",
description: "Bearish reversal with inside candle",
},
bullishKicker: {
type: "reversal",
direction: "bullish",
confidence: 0.9,
strength: "strong",
description: "Very strong bullish reversal with gap",
},
bearishKicker: {
type: "reversal",
direction: "bearish",
confidence: 0.9,
strength: "strong",
description: "Very strong bearish reversal with gap",
},
hangingMan: {
type: "reversal",
direction: "bearish",
confidence: 0.75,
strength: "moderate",
description: "Bearish reversal after uptrend",
},
shootingStar: {
type: "reversal",
direction: "bearish",
confidence: 0.75,
strength: "moderate",
description: "Bearish reversal with long upper shadow",
},
piercingLine: {
type: "reversal",
direction: "bullish",
confidence: 0.8,
strength: "strong",
description: "Bullish reversal piercing into bearish candle",
},
darkCloudCover: {
type: "reversal",
direction: "bearish",
confidence: 0.8,
strength: "strong",
description: "Bearish reversal covering bullish candle",
},
// Three candle patterns
morningStar: {
type: "reversal",
direction: "bullish",
confidence: 0.9,
strength: "strong",
description: "Strong bullish reversal with gap and star",
},
eveningStar: {
type: "reversal",
direction: "bearish",
confidence: 0.9,
strength: "strong",
description: "Strong bearish reversal with gap and star",
},
threeWhiteSoldiers: {
type: "continuation",
direction: "bullish",
confidence: 0.85,
strength: "strong",
description: "Strong bullish continuation with three advancing candles",
},
threeBlackCrows: {
type: "continuation",
direction: "bearish",
confidence: 0.85,
strength: "strong",
description: "Strong bearish continuation with three declining candles",
},
// Marubozu patterns
marubozu: {
type: "continuation",
direction: "neutral",
confidence: 0.8,
strength: "strong",
description: "Strong directional move with minimal shadows",
},
bullishMarubozu: {
type: "continuation",
direction: "bullish",
confidence: 0.85,
strength: "strong",
description: "Very strong bullish candle with no shadows",
},
bearishMarubozu: {
type: "continuation",
direction: "bearish",
confidence: 0.85,
strength: "strong",
description: "Very strong bearish candle with no shadows",
},
// Spinning Top patterns
spinningTop: {
type: "neutral",
direction: "neutral",
confidence: 0.6,
strength: "weak",
description: "Indecision candle, potential reversal or consolidation",
},
bullishSpinningTop: {
type: "neutral",
direction: "neutral",
confidence: 0.58,
strength: "weak",
description: "Spinning top with slight bullish bias",
},
bearishSpinningTop: {
type: "neutral",
direction: "neutral",
confidence: 0.58,
strength: "weak",
description: "Spinning top with slight bearish bias",
},
// Tweezers patterns
tweezersTop: {
type: "reversal",
direction: "bearish",
confidence: 0.75,
strength: "moderate",
description: "Bearish reversal with matching highs",
},
tweezersBottom: {
type: "reversal",
direction: "bullish",
confidence: 0.75,
strength: "moderate",
description: "Bullish reversal with matching lows",
},
};
/**
* Get metadata for a pattern
* @param {string} patternName - Name of the pattern
* @return {Object|undefined} Pattern metadata or undefined if not found
*/
function getPatternMetadata(patternName) {
return patternMetadata[patternName];
}
/**
* Enhance pattern chain results with metadata
* @param {Array<Object>} results - Results from patternChain
* @return {Array<Object>} Results with metadata added
*/
function enrichWithMetadata(results) {
return results.map((result) => {
const metadata = getPatternMetadata(result.pattern);
if (metadata) {
return {
...result,
metadata: {
type: metadata.type,
direction: metadata.direction,
confidence: metadata.confidence,
strength: metadata.strength,
description: metadata.description,
},
};
}
return result;
});
}
/**
* Filter pattern results by minimum confidence
* @param {Array<Object>} results - Results with metadata
* @param {number} minConfidence - Minimum confidence threshold (0-1)
* @return {Array<Object>} Filtered results
*/
function filterByConfidence(results, minConfidence = 0.5) {
return results.filter((r) => {
const metadata = r.metadata || getPatternMetadata(r.pattern);
return metadata && metadata.confidence >= minConfidence;
});
}
/**
* Filter pattern results by type
* @param {Array<Object>} results - Results with metadata
* @param {string} type - Pattern type ('reversal', 'continuation', 'neutral')
* @return {Array<Object>} Filtered results
*/
function filterByType(results, type) {
return results.filter((r) => {
const metadata = r.metadata || getPatternMetadata(r.pattern);
return metadata && metadata.type === type;
});
}
/**
* Filter pattern results by direction
* @param {Array<Object>} results - Results with metadata
* @param {string} direction - Pattern direction ('bullish', 'bearish', 'neutral')
* @return {Array<Object>} Filtered results
*/
function filterByDirection(results, direction) {
return results.filter((r) => {
const metadata = r.metadata || getPatternMetadata(r.pattern);
return metadata && metadata.direction === direction;
});
}
/**
* Sort pattern results by confidence (descending)
* @param {Array<Object>} results - Results with metadata
* @return {Array<Object>} Sorted results
*/
function sortByConfidence(results) {
return results.slice().sort((a, b) => {
const metaA = a.metadata || getPatternMetadata(a.pattern);
const metaB = b.metadata || getPatternMetadata(b.pattern);
const confA = metaA ? metaA.confidence : 0;
const confB = metaB ? metaB.confidence : 0;
return confB - confA;
});
}
module.exports = {
patternMetadata,
getPatternMetadata,
enrichWithMetadata,
filterByConfidence,
filterByType,
filterByDirection,
sortByConfidence,
};