This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathHL.js
130 lines (108 loc) · 3.26 KB
/
HL.js
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
var method = {};
method.init = function() {
this.name = 'Scalper';
this.addTulipIndicator('ps', 'psar', {optInAcceleration:0.25,
optInMaximum:0.50
});
this.candle_queue = [];
this.is_buyin = false;
}
var barscount = 0;
var DarvasHigh = 0;
var DarvasLow = 0;
method.update = function(candle) {
this.psar = this.tulipIndicators.ps.result.result;
if(candle.low < DarvasLow){DarvasLow = candle.low;}
if(candle.high < DarvasHigh){DarvasHigh = candle.low;}
this.candle_queue.push(candle);
barscount++;
if(this.candle_queue.length>0){
candle.delta = candle.close - this.candle_queue[0].close;
}
}
// var percent = 35;
// var distance = 3;
var Period = 25;
// var lastcolor = 0;
var Min = [];
var MovingTR = [];
var NoTradedSince = 0;
IsReversalUp = function(min,candle){
var c1 = this.candle_queue[this.candle_queue.length -2];
return (candle.low < min && candle.close > c1.close);
}
var MoveCycle = [];
var LowTopDif = [];
method.check = function(candle) {
if (this.candle_queue.length >= Period)
{
//Get Min Max
runningMin = 99999999;
runningMax = 0;
for (let barsBack = Math.min(this.candle_queue.length, Period - 1); barsBack > 0; barsBack--)
{
var bar = this.candle_queue[barsBack];
if(bar.close <= runningMin)
{
runningMin = bar.close;
}
}
Min.push(runningMin);
for (let barsBack = Math.min(this.candle_queue.length, Period - 1); barsBack > 0; barsBack--)
{
var bar = this.candle_queue[barsBack];
if(bar.close >= runningMax)
{
runningMax = bar.close;
}
}
//Get Min Max EOF
// var LowerLow = Min[Min.length -1] > Min[0];
var CandeLow = this.candle.close < runningMin && (this.candle.close - runningMin) / 100;
MoveCycle.push((this.candle.close - runningMin) / 100);
// var Downslow = MoveCycle[MoveCycle.length -1] > MoveCycle[0];
var c1 = this.candle_queue[this.candle_queue.length -2];
var TrueRange = Math.max(runningMax,c1.close) - Math.min(runningMin,c1.close);
var valid = TrueRange / (candle.close - c1.close);
// var Range = 100 * ((valid - runningMin) / (runningMax - runningMin));
MovingTR.push(valid);
// var MovingSlower = MovingTR[MovingTR.length -2] > valid;
// var RangeControl = valid !== Infinity;
LowTopDif.push((runningMin - runningMax) / 100);
// var BoxExpanding = LowTopDif[LowTopDif.length -2] < LowTopDif[LowTopDif.length -1];
// log.debug('Min: ',runningMin);
// log.debug('Max: ',runningMax);
if(CandeLow && valid > 0 &&! this.is_buyin)
{
// this.price_buyin = candle.close;
this.candle_queue.length = 0;
runningMin = 0;
runningMax = 0;
Min = [];
MovingTR = [];
this.is_buyin = true;
return this.advice("long");
}
else if (candle.close >= runningMax && this.is_buyin )
{
this.candle_queue.length = 0;
runningMin = 0;
runningMax = 0;
Min = [];
MovingTR = [];
this.is_buyin = false;
return this.advice("short");
}
if(NoTradedSince > 2 &&! this.is_buyin)
{
this.candle_queue.length = 0;
runningMin = 0;
Min = [];
runningMax = 0;
MovingTR = [];
NoTradedSince = 0;
}
NoTradedSince++;
}
}
module.exports = method;