-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruleFactory.js
More file actions
588 lines (516 loc) · 18.7 KB
/
ruleFactory.js
File metadata and controls
588 lines (516 loc) · 18.7 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
const Rule = require("./rule");
// indicators
const CurrentCandle = require("./indicators/CurrentCandle");
const SMA = require("./indicators/SMA");
const EMA = require("./indicators/EMA");
const VWAP = require("./indicators/VWAP");
const Interval = require("./indicators/Interval");
const Signal = require("./indicators/Signal");
const Gap = require("./indicators/Gap");
const PreviousNCandles = require("./indicators/PreviousNCandles");
const Up = require("./indicators/Up");
const Down = require("./indicators/Down");
const PreviousCandleHigh = require("./indicators/PreviousCandleHigh");
const PreviousCandleLow = require("./indicators/PreviousCandleLow");
const HigherVolume = require("./indicators/HigherVolume");
const LowerVolume = require("./indicators/LowerVolume");
const HigherRange = require("./indicators/HigherRange");
const LowerRange = require("./indicators/LowerRange");
const HighOfEntryBar = require("./indicators/HighOfEntryBar");
const LowOfEntryBar = require("./indicators/LowOfEntryBar");
const HighOfFirstNMinutes = require("./indicators/HighOfFirstNMinutes");
const LowOfFirstNMinutes = require("./indicators/LowOfFirstNMinutes");
const HighOfLastNMinutes = require("./indicators/HighOfLastNMinutes");
const LowOfLastNMinutes = require("./indicators/LowOfLastNMinutes");
const AtLeastNTimesRange = require("./indicators/AtLeastNTimesRange");
const AtMostNTimesRange = require("./indicators/AtMostNTimesRange");
const AtMostNTimesVolume = require("./indicators/AtMostNTimesVolume");
const AtLeastNTimesVolume = require("./indicators/AtLeastNTimesVolume");
const LongTopTail = require("./indicators/LongTopTail");
const LongBottomTail = require("./indicators/LongBottomTail");
const ProfitTarget = require("./indicators/ProfitTarget");
const StopLoss = require("./indicators/StopLoss");
const NMinutes = require("./indicators/NMinutes");
const NPercent = require("./indicators/NPercent");
const NthCandle = require("./indicators/NthCandle");
// comparators
const Closes = require("./comparators/Closes");
const ClosesAbove = require("./comparators/ClosesAbove");
const ClosesBelow = require("./comparators/ClosesBelow");
const BreaksAbove = require("./comparators/BreaksAbove");
const BreaksBelow = require("./comparators/BreaksBelow");
const Has = require("./comparators/Has");
const BouncesHigherOff = require("./comparators/BouncesHigherOff");
const BouncesLowerOff = require("./comparators/BouncesLowerOff");
const FallsTo = require("./comparators/FallsTo");
const RisesTo = require("./comparators/RisesTo");
const GivenInFirst = require("./comparators/GivenInFirst");
const UpByAtLeast = require("./comparators/UpByAtLeast");
const UpByAtMost = require("./comparators/UpByAtMost");
const DownByAtLeast = require("./comparators/DownByAtLeast");
const DownByAtMost = require("./comparators/DownByAtMost");
const FallByAtLeast = require("./comparators/FallByAtLeast");
const FallByAtMost = require("./comparators/FallByAtMost");
const RiseByAtLeast = require("./comparators/RiseByAtLeast");
const RiseByAtMost = require("./comparators/RiseByAtMost");
const CrossesAbove = require("./comparators/CrossesAbove");
const CrossesBelow = require("./comparators/CrossesBelow");
function RuleFactory()
{
this.generateRule = function(indicator1Name, indicator1Params, indicator2Name, indicator2Params, comparatorName)
{
let indicator1;
let indicator2;
let comparator;
if (indicator1Name == "CurrentCandle" || indicator2Name == "CurrentCandle")
{
if (indicator1Name == "CurrentCandle")
{
indicator1 = new CurrentCandle(indicator1Params);
}
if (indicator2Name == "CurrentCandle")
{
indicator2 = new CurrentCandle(indicator2Params);
}
}
if (indicator1Name == "Up" || indicator2Name == "Up")
{
if (indicator1Name == "Up")
{
indicator1 = new Up(indicator1Params);
}
if (indicator2Name == "Up")
{
indicator2 = new Up(indicator2Params);
}
}
if (indicator1Name == "Down" || indicator2Name == "Down")
{
if (indicator1Name == "Down")
{
indicator1 = new Down(indicator1Params);
}
if (indicator2Name == "Down")
{
indicator2 = new Down(indicator2Params);
}
}
if (indicator1Name == "SMA" || indicator2Name == "SMA")
{
if (indicator1Name == "SMA")
{
indicator1 = new SMA(indicator1Params);
}
if (indicator2Name == "SMA")
{
indicator2 = new SMA(indicator2Params);
}
}
if (indicator1Name == "EMA" || indicator2Name == "EMA")
{
if (indicator1Name == "EMA")
{
indicator1 = new EMA(indicator1Params);
}
if (indicator2Name == "EMA")
{
indicator2 = new EMA(indicator2Params);
}
}
if (indicator1Name == "VWAP" || indicator2Name == "VWAP")
{
if (indicator1Name == "VWAP")
{
indicator1 = new VWAP(indicator1Params);
}
if (indicator2Name == "VWAP")
{
indicator2 = new VWAP(indicator2Params);
}
}
if (indicator1Name == "Interval" || indicator2Name == "Interval")
{
if (indicator1Name == "Interval")
{
indicator1 = new Interval(indicator1Params);
}
if (indicator2Name == "Interval")
{
indicator2 = new Interval(indicator2Params);
}
}
if (indicator1Name == "PreviousCandleHigh" || indicator2Name == "PreviousCandleHigh")
{
if (indicator1Name == "PreviousCandleHigh")
{
indicator1 = new PreviousCandleHigh(indicator1Params);
}
if (indicator2Name == "PreviousCandleHigh")
{
indicator2 = new PreviousCandleHigh(indicator2Params);
}
}
if (indicator1Name == "PreviousCandleLow" || indicator2Name == "PreviousCandleLow")
{
if (indicator1Name == "PreviousCandleLow")
{
indicator1 = new PreviousCandleLow(indicator1Params);
}
if (indicator2Name == "PreviousCandleLow")
{
indicator2 = new PreviousCandleLow(indicator2Params);
}
}
if (indicator1Name == "HigherVolume" || indicator2Name == "HigherVolume")
{
if (indicator1Name == "HigherVolume")
{
indicator1 = new HigherVolume(indicator1Params);
}
if (indicator2Name == "HigherVolume")
{
indicator2 = new HigherVolume(indicator2Params);
}
}
if (indicator1Name == "LowerVolume" || indicator2Name == "LowerVolume")
{
if (indicator1Name == "LowerVolume")
{
indicator1 = new LowerVolume(indicator1Params);
}
if (indicator2Name == "LowerVolume")
{
indicator2 = new LowerVolume(indicator2Params);
}
}
if (indicator1Name == "LowerRange" || indicator2Name == "LowerRange")
{
if (indicator1Name == "LowerRange")
{
indicator1 = new LowerRange(indicator1Params);
}
if (indicator2Name == "LowerRange")
{
indicator2 = new LowerRange(indicator2Params);
}
}
if (indicator1Name == "HigherRange" || indicator2Name == "HigherRange")
{
if (indicator1Name == "HigherRange")
{
indicator1 = new HigherRange(indicator1Params);
}
if (indicator2Name == "HigherRange")
{
indicator2 = new HigherRange(indicator2Params);
}
}
if (indicator1Name == "HighOfEntryBar" || indicator2Name == "HighOfEntryBar")
{
if (indicator1Name == "HighOfEntryBar")
{
indicator1 = new HighOfEntryBar(indicator1Params);
}
if (indicator2Name == "HighOfEntryBar")
{
indicator2 = new HighOfEntryBar(indicator2Params);
}
}
if (indicator1Name == "LowOfEntryBar" || indicator2Name == "LowOfEntryBar")
{
if (indicator1Name == "LowOfEntryBar")
{
indicator1 = new LowOfEntryBar(indicator1Params);
}
if (indicator2Name == "LowOfEntryBar")
{
indicator2 = new LowOfEntryBar(indicator2Params);
}
}
if (indicator1Name == "HighOfFirstNMinutes" || indicator2Name == "HighOfFirstNMinutes")
{
if (indicator1Name == "HighOfFirstNMinutes")
{
indicator1 = new HighOfFirstNMinutes(indicator1Params);
}
if (indicator2Name == "HighOfFirstNMinutes")
{
indicator2 = new HighOfFirstNMinutes(indicator2Params);
}
}
if (indicator1Name == "LowOfFirstNMinutes" || indicator2Name == "LowOfFirstNMinutes")
{
if (indicator1Name == "LowOfFirstNMinutes")
{
indicator1 = new LowOfFirstNMinutes(indicator1Params);
}
if (indicator2Name == "LowOfFirstNMinutes")
{
indicator2 = new LowOfFirstNMinutes(indicator2Params);
}
}
if (indicator1Name == "HighOfLastNMinutes" || indicator2Name == "HighOfLastNMinutes")
{
if (indicator1Name == "HighOfLastNMinutes")
{
indicator1 = new HighOfLastNMinutes(indicator1Params);
}
if (indicator2Name == "HighOfLastNMinutes")
{
indicator2 = new HighOfLastNMinutes(indicator2Params);
}
}
if (indicator1Name == "LowOfLastNMinutes" || indicator2Name == "LowOfLastNMinutes")
{
if (indicator1Name == "LowOfLastNMinutes")
{
indicator1 = new LowOfLastNMinutes(indicator1Params);
}
if (indicator2Name == "LowOfLastNMinutes")
{
indicator2 = new LowOfLastNMinutes(indicator2Params);
}
}
if (indicator1Name == "AtLeastNTimesRange" || indicator2Name == "AtLeastNTimesRange")
{
if (indicator1Name == "AtLeastNTimesRange")
{
indicator1 = new AtLeastNTimesRange(indicator1Params);
}
if (indicator2Name == "AtLeastNTimesRange")
{
indicator2 = new AtLeastNTimesRange(indicator2Params);
}
}
if (indicator1Name == "AtMostNTimesRange" || indicator2Name == "AtMostNTimesRange")
{
if (indicator1Name == "AtMostNTimesRange")
{
indicator1 = new AtMostNTimesRange(indicator1Params);
}
if (indicator2Name == "AtMostNTimesRange")
{
indicator2 = new AtMostNTimesRange(indicator2Params);
}
}
if (indicator1Name == "AtMostNTimesVolume" || indicator2Name == "AtMostNTimesVolume")
{
if (indicator1Name == "AtMostNTimesVolume")
{
indicator1 = new AtMostNTimesVolume(indicator1Params);
}
if (indicator2Name == "AtMostNTimesVolume")
{
indicator2 = new AtMostNTimesVolume(indicator2Params);
}
}
if (indicator1Name == "AtLeastNTimesVolume" || indicator2Name == "AtLeastNTimesVolume")
{
if (indicator1Name == "AtLeastNTimesVolume")
{
indicator1 = new AtLeastNTimesVolume(indicator1Params);
}
if (indicator2Name == "AtLeastNTimesVolume")
{
indicator2 = new AtLeastNTimesVolume(indicator2Params);
}
}
if (indicator1Name == "LongTopTail" || indicator2Name == "LongTopTail")
{
if (indicator1Name == "LongTopTail")
{
indicator1 = new LongTopTail(indicator1Params);
}
if (indicator2Name == "LongTopTail")
{
indicator2 = new LongTopTail(indicator2Params);
}
}
if (indicator1Name == "LongBottomTail" || indicator2Name == "LongBottomTail")
{
if (indicator1Name == "LongBottomTail")
{
indicator1 = new LongBottomTail(indicator1Params);
}
if (indicator2Name == "LongBottomTail")
{
indicator2 = new LongBottomTail(indicator2Params);
}
}
if (indicator1Name == "ProfitTarget" || indicator2Name == "ProfitTarget")
{
if (indicator1Name == "ProfitTarget")
{
indicator1 = new ProfitTarget(indicator1Params);
}
if (indicator2Name == "ProfitTarget")
{
indicator2 = new ProfitTarget(indicator2Params);
}
}
if (indicator1Name == "StopLoss" || indicator2Name == "StopLoss")
{
if (indicator1Name == "StopLoss")
{
indicator1 = new StopLoss(indicator1Params);
}
if (indicator2Name == "StopLoss")
{
indicator2 = new StopLoss(indicator2Params);
}
}
if (indicator1Name == "Signal" || indicator2Name == "Signal")
{
if (indicator1Name == "Signal")
{
indicator1 = new Signal(indicator1Params);
}
if (indicator2Name == "Signal")
{
indicator2 = new Signal(indicator2Params);
}
}
if (indicator1Name == "NMinutes" || indicator2Name == "NMinutes")
{
if (indicator1Name == "NMinutes")
{
indicator1 = new NMinutes(indicator1Params);
}
if (indicator2Name == "NMinutes")
{
indicator2 = new NMinutes(indicator2Params);
}
}
if (indicator1Name == "Gap" || indicator2Name == "Gap")
{
if (indicator1Name == "Gap")
{
indicator1 = new Gap(indicator1Params);
}
if (indicator2Name == "Gap")
{
indicator2 = new Gap(indicator2Params);
}
}
if (indicator1Name == "NPercent" || indicator2Name == "NPercent")
{
if (indicator1Name == "NPercent")
{
indicator1 = new NPercent(indicator1Params);
}
if (indicator2Name == "NPercent")
{
indicator2 = new NPercent(indicator2Params);
}
}
if (indicator1Name == "PreviousNCandles" || indicator2Name == "PreviousNCandles")
{
if (indicator1Name == "PreviousNCandles")
{
indicator1 = new PreviousNCandles(indicator1Params);
}
if (indicator2Name == "PreviousNCandles")
{
indicator2 = new PreviousNCandles(indicator2Params);
}
}
if (indicator1Name == "NthCandle" || indicator2Name == "NthCandle")
{
if (indicator1Name == "NthCandle")
{
indicator1 = new NthCandle(indicator1Params);
}
if (indicator2Name == "NthCandle")
{
indicator2 = new NthCandle(indicator2Params);
}
}
//comparators
if (comparatorName == "Closes")
{
comparator = new Closes(indicator1, indicator2)
}
else if (comparatorName == "ClosesAbove")
{
comparator = new ClosesAbove(indicator1, indicator2)
}
else if (comparatorName == "ClosesBelow")
{
comparator = new ClosesBelow(indicator1, indicator2)
}
else if (comparatorName == "BreaksAbove")
{
comparator = new BreaksAbove(indicator1, indicator2)
}
else if (comparatorName == "BreaksBelow")
{
comparator = new BreaksBelow(indicator1, indicator2)
}
else if (comparatorName == "Has")
{
comparator = new Has(indicator1, indicator2)
}
else if (comparatorName == "BouncesHigherOff")
{
comparator = new BouncesHigherOff(indicator1, indicator2)
}
else if (comparatorName == "BouncesLowerOff")
{
comparator = new BouncesLowerOff(indicator1, indicator2)
}
else if (comparatorName == "FallsTo")
{
comparator = new FallsTo(indicator1, indicator2)
}
else if (comparatorName == "RisesTo")
{
comparator = new RisesTo(indicator1, indicator2)
}
else if (comparatorName == "GivenInFirst")
{
comparator = new GivenInFirst(indicator1, indicator2)
}
else if (comparatorName == "UpByAtLeast")
{
comparator = new UpByAtLeast(indicator1, indicator2)
}
else if (comparatorName == "UpByAtMost")
{
comparator = new UpByAtMost(indicator1, indicator2)
}
else if (comparatorName == "DownByAtLeast")
{
comparator = new DownByAtLeast(indicator1, indicator2)
}
else if (comparatorName == "DownByAtMost")
{
comparator = new DownByAtMost(indicator1, indicator2)
}
else if (comparatorName == "FallByAtLeast")
{
comparator = new FallByAtLeast(indicator1, indicator2)
}
else if (comparatorName == "FallByAtMost")
{
comparator = new FallByAtMost(indicator1, indicator2)
}
else if (comparatorName == "RiseByAtMost")
{
comparator = new RiseByAtMost(indicator1, indicator2)
}
else if (comparatorName == "RiseByAtLeast")
{
comparator = new RiseByAtLeast(indicator1, indicator2)
}
else if (comparatorName == "CrossesAbove")
{
comparator = new CrossesAbove(indicator1, indicator2)
}
else if (comparatorName == "CrossesBelow")
{
comparator = new CrossesBelow(indicator1, indicator2)
}
return new Rule(indicator1, indicator2, comparator);
}
}
module.exports = RuleFactory;