-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValueCalculator.java
More file actions
39 lines (33 loc) · 1.02 KB
/
ValueCalculator.java
File metadata and controls
39 lines (33 loc) · 1.02 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
import java.util.LinkedList;
public class ValueCalculator implements Calculator{
public int calculate(LinkedList<Double> chart)
{
return calculate(chart, 7);
}
public int calculate(LinkedList<Double> chart, String sensitivity)
{
if(sensitivity.toLowerCase().equals("high"))
return calculate(chart, 3);
else
return calculate(chart, 40);
}
public int calculate(LinkedList<Double> chart, int sensitivity)
{
double prevTotal = 0;
double newTotal = 0;
for(int i = sensitivity+2; i < (sensitivity+1)*2; i++)
{
prevTotal += chart.get(chart.size() - i);
}
for(int j = 1; j < 1+sensitivity; j++)
{
newTotal += chart.get(chart.size() - j);
}
prevTotal /= sensitivity;
newTotal /= sensitivity;
if(newTotal <= prevTotal)
return 1; // BUY THE DIP
else
return 0; // SELL THE PEAK
}
}