-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCandleCandies.java
More file actions
155 lines (135 loc) · 4.94 KB
/
CandleCandies.java
File metadata and controls
155 lines (135 loc) · 4.94 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
package TraderOracle;
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.awt.*;
import java.awt.Graphics2D;
import java.awt.geom.*;
import java.util.*;
import java.util.List;
import java.io.*;
import java.net.*;
import com.motivewave.platform.sdk.common.*;
import com.motivewave.platform.sdk.common.desc.*;
import com.motivewave.platform.sdk.common.menu.*;
import com.motivewave.platform.sdk.study.*;
import com.motivewave.platform.sdk.draw.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@StudyHeader(
namespace="com.DickInTheSpleen",
id="CandyCandles",
rb="TraderOracle.nls.strings", // locale specific strings are loaded from here
name="Candy Candles",
label="Candy Candles",
desc="Candy Candles",
menu="TraderOracle",
overlay=true,
studyOverlay=true,
signals=true)
public class CandleCandies extends Study
{
private static final Color RED = new Color(255, 0, 0, 255);
private static final Color GREEN = new Color(0, 255, 0, 255);
private static final Color WHITE = new Color(255, 255, 255, 255);
private static final Color YELLOW = new Color(255, 255, 0, 255);
private static final Color BLUE = new Color(120, 170, 250, 255);
enum Signals { WICK, TOUCH }
//region ON BAR CLOSE
@Override
public void onBarClose(DataContext ctx)
{
var s = ctx.getDataSeries();
int index = s.getEndIndex();
// CANDLE CALCULATIONS
double close = s.getClose(index);
double open = s.getOpen(index);
double pclose = s.getClose(index - 1);
double popen = s.getOpen(index - 1);
double ppclose = s.getClose(index - 2);
double ppopen = s.getOpen(index - 2);
double low = s.getLow(index);
double plow = s.getLow(index - 1);
double high = s.getHigh(index);
double phigh = s.getHigh(index - 1);
boolean c0G = close > s.getOpen(index);
boolean c1G = s.getClose(index - 1) > s.getOpen(index - 1);
boolean c2G = s.getClose(index - 2) > s.getOpen(index - 2);
boolean c0R = close < open;
boolean c1R = s.getClose(index - 1) < s.getOpen(index - 1);
boolean c2R = s.getClose(index - 2) < s.getOpen(index - 2);
double body = Math.abs(open - close);
double pbody = Math.abs(s.getOpen(index - 1) - s.getClose(index - 1));
boolean bGDoji = c1G && pbody < phigh - pclose && pbody < popen - plow;
boolean bRDoji = c1R && pbody < phigh - popen && pbody < pclose - plow;
boolean bDoji = bGDoji || bRDoji;
//endregion
}
//endregion
//region INITIALIZE
@Override
public void initialize(Defaults defaults)
{
var sd = createSD();
var tab2 = sd.addTab("Lines");
var grp3 = tab2.addGroup("Alert on These");
grp3.addRow(new BooleanDescriptor("TOUCH21", "Alert EMA 21 touches", true));
grp3.addRow(new BooleanDescriptor("TOUCH200", "Alert EMA 200 touches", true));
grp3.addRow(new BooleanDescriptor("TOUCHVWAP", "Alert VWAP touches", true));
grp3.addRow(new BooleanDescriptor("WICK21", "Alert EMA 21 WICKs", true));
grp3.addRow(new BooleanDescriptor("WICK200", "Alert EMA 200 WICKs", true));
grp3.addRow(new BooleanDescriptor("WICKVWAP", "Alert VWAP WICKs", true));
RuntimeDescriptor desc = new RuntimeDescriptor();
setRuntimeDescriptor(desc);
desc.declareSignal(Signals.WICK, "Line Wick");
desc.declareSignal(Signals.TOUCH, "Line Touch");
}
@Override
public void onSettingsUpdated(DataContext ctx)
{
}
//endregion
@Override
protected void calculate(int index, DataContext ctx)
{
var s = ctx.getDataSeries();
int last = s.size() - 1;
if (s == null || index < 202 || !s.isBarComplete(index))
return;
// CANDLE CALCULATIONS
double close = s.getClose(index);
double open = s.getOpen(index);
double pclose = s.getClose(index - 1);
double popen = s.getOpen(index - 1);
double ppclose = s.getClose(index - 2);
double ppopen = s.getOpen(index - 2);
double low = s.getLow(index);
double plow = s.getLow(index - 1);
double high = s.getHigh(index);
double phigh = s.getHigh(index - 1);
boolean c0G = close > s.getOpen(index);
boolean c1G = s.getClose(index - 1) > s.getOpen(index - 1);
boolean c2G = s.getClose(index - 2) > s.getOpen(index - 2);
boolean c0R = close < open;
boolean c1R = s.getClose(index - 1) < s.getOpen(index - 1);
boolean c2R = s.getClose(index - 2) < s.getOpen(index - 2);
double body = Math.abs(open - close);
double pbody = Math.abs(s.getOpen(index - 1) - s.getClose(index - 1));
boolean bGDoji = c1G && pbody < phigh - pclose && pbody < popen - plow;
boolean bRDoji = c1R && pbody < phigh - popen && pbody < pclose - plow;
boolean bDoji = bGDoji || bRDoji;
//endregion
if (high < phigh && low > plow){
s.setPriceBarColor(index, YELLOW);
}
else if (high > phigh){
s.setPriceBarColor(index, GREEN);
}
else if (low < plow){
s.setPriceBarColor(index, RED);
}
else{
s.setPriceBarColor(index, BLUE);
}
}
}