-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLineBounces.java
More file actions
386 lines (338 loc) · 15.7 KB
/
LineBounces.java
File metadata and controls
386 lines (338 loc) · 15.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
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="LineBounces2",
rb="TraderOracle.nls.strings", // locale specific strings are loaded from here
name="Line Bounces2",
label="Line Bounces2",
desc="Line Bounces2",
menu="TraderOracle",
overlay=true,
studyOverlay=true,
signals=true)
public class LineBounces extends Study
{
//region VARIABLES
enum Values { UP, DOWN, TREND }
//enum Signals { KP_WICK, KP_TOUCH, TS_WICK,TS_TOUCH, MQ_WICK, MQ_TOUCH, MAN_WICK, MAN_TOUCH }
enum Signals { WICK, TOUCH }
private static final Color RED = new Color(255, 0, 0);
private static final Color GREEN = new Color(0, 255, 0);
private static final Color WHITE = new Color(255, 255, 255);
private static final Color YELLOW = new Color(255, 0, 0);
private Map<Double, String> kpMap;
private Map<Double, String> mqMap;
private Map<Double, String> bsMap;
private List<RangeEntry> tsRange;
private int currIndex = 0;
private int gIndex = 0;
private String sMsg = "";
public static class RangeEntry {
private final double start;
private final double end;
private final String text;
public RangeEntry(double start, double end, String text) {
this.start = start;
this.end = end;
this.text = text;
}
public boolean between(double number) {
return number >= start && number <= end;
}
public String getText() {
return text;
}
}
//endregion
//region ON BAR CLOSE
@Override
public void onBarClose(DataContext ctx)
{
var s = ctx.getDataSeries();
int index = s.getEndIndex();
this.clearFigures();
Box bx = new Box();
addFigure(bx);
boolean bShowKillpips = getSettings().getBoolean("SHOWKP");
boolean bShowMenthorQ = getSettings().getBoolean("SHOWMQ");
boolean bShowTS = getSettings().getBoolean("SHOWTS");
double close = s.getClose();
double open = s.getOpen();
double hi = s.getHigh();
double lo = s.getLow();
boolean c0G = s.getClose() > s.getOpen();
boolean c0R = s.getClose() < s.getOpen();
if (bShowTS) {
//sTSMsg = "";
for (RangeEntry tsi : tsRange) {
// Single value
if (tsi.start == tsi.end){
if (hi > tsi.start && lo < tsi.start) {
String sQ = tsi.text;
//if (tsi.text == "MTS")
sQ += " " + tsi.start;
sMsg = "TraderSmarts Touched " + sQ;
ctx.signal(index, Signals.TOUCH, "TraderSmarts Touched " + sQ, close);
break;
}
else if ((c0G && hi > tsi.start && close < tsi.start) ||
(c0G && lo < tsi.start && open > tsi.start) ||
(c0R && hi > tsi.start && open < tsi.start) ||
(c0R && lo < tsi.start && close > tsi.start)){
sMsg = "TraderSmarts Wicking " + tsi.text;
ctx.signal(index, Signals.WICK, "TraderSmarts Wick " + tsi.text, close);
break;
}
}
// Range values
if (tsi.start > tsi.end && close > tsi.end && close < tsi.start) {
sMsg = "TraderSmarts Inside " + tsi.text;
ctx.signal(index, Signals.TOUCH, "TraderSmarts Inside " + tsi.text, close);
break;
}
if (tsi.start < tsi.end && close < tsi.end && close > tsi.start) {
sMsg = "TraderSmarts Inside " + tsi.text;
ctx.signal(index, Signals.TOUCH, "TraderSmarts Inside " + tsi.text, close);
break;
}
}
}
if (bShowKillpips) {
String sKPMsg = getTouch(ctx, kpMap, s.getHigh(), s.getLow(), s.getOpen(), s.getClose());
if (sKPMsg != "") {
sMsg = "Killips " + sKPMsg;
ctx.signal(index, Signals.TOUCH, "Killips " + sKPMsg, close);
}
}
if (bShowMenthorQ) {
String sMQMsg = getTouch(ctx, mqMap, s.getHigh(), s.getLow(), s.getOpen(), s.getClose());
if (sMQMsg != "") {
sMsg = "MenthorQ " + sMQMsg;
ctx.signal(index, Signals.TOUCH, "MenthorQ " + sMQMsg, close);
}
String sMQMsg2 = getTouch(ctx, bsMap, s.getHigh(), s.getLow(), s.getOpen(), s.getClose());
if (sMQMsg2 != "") {
sMsg = "MenthorQ " + sMQMsg2;
ctx.signal(index, Signals.TOUCH, "MenthorQ " + sMQMsg2, close);
}
}
}
//endregion
private class Box extends Figure
{
@Override
public void draw(Graphics2D gc, DrawContext ctx)
{
try {
Font font = new Font("Dialog", Font.PLAIN, 14);
gc.setFont(font);
gc.setColor(WHITE);
gc.drawString(sMsg, 450, 40);
} catch (java.lang.Exception e){}
}
}
//region TRADER SMARTS
private void FillTraderSmarts()
{
//debug("FillTraderSmarts = " + src + ", " + xx);
tsRange.clear();
String tsMTS = "";
String ts = getSettings().getString("TS");
//debug("FillTraderSmarts = " + ts);
int idx = ts.indexOf("MTS Numbers:");
if (idx != -1) {
tsMTS = ts.substring(idx + "MTS Numbers:".length()).trim();
tsMTS = tsMTS.replaceAll(", ", ",");
//debug("tsMTS = " + tsMTS);
ts = ts.substring(0, idx).trim();
String[] nums = tsMTS.replaceAll("\\s+", "").split(",");
for (int i = 0; i < nums.length; i++) {
try {
Double nummie = Double.parseDouble(nums[i].trim());
tsRange.add(new RangeEntry(nummie, nummie, "MTS"));
//debug("tsRange.add = " + nummie + " MTS");
} catch (NumberFormatException e) {}
}
}
int idxq = ts.indexOf("Target Zones:");
if (idxq != -1)
ts = ts.substring(idxq + "Target Zones:".length()).trim();
ts = ts.replaceAll("FTD", "");
ts = ts.replaceAll("FTU", "");
ts = ts.replaceAll(" - ", "-");
ts = ts.replaceAll("Short", "Short,");
ts = ts.replaceAll("Long", "Long,");
ts = ts.replaceAll("Sand", "Sand,");
debug("Target Zones: " + ts);
// Values between the commas = 19825.75 Highest Odds Long
String[] nums = ts.split(",");
for (int ip = 0; ip < nums.length; ip++) {
debug("nums " + ip + " = " + nums[ip]);
if (nums[ip].trim().contains("-")) {
// Dash separated range = 20129.50-20111.25 Range Short
Pattern pattern = Pattern.compile("^(\\d+\\.?\\d*)-(\\d+\\.?\\d*) (.+)$");
Matcher matcher = pattern.matcher(nums[ip].trim());
if (matcher.find()) {
double numone = Double.parseDouble(matcher.group(1));
double numtwo = Double.parseDouble(matcher.group(2));
String desc = matcher.group(3);
tsRange.add(new RangeEntry(numone, numtwo, desc));
debug("Dash RangeEntry = " + numone + ", " + numtwo + ", " + desc);
continue;
}
}
else
try {
// Simple strings = 19825.75 Highest Odds Long
Pattern pattern = Pattern.compile("^(\\d+\\.?\\d*) (.+)$");
Matcher matcher = pattern.matcher(nums[ip].trim());
if (matcher.find()) {
double nummie = Double.parseDouble(matcher.group(1));
String desc = matcher.group(2);
tsRange.add(new RangeEntry(nummie, nummie, desc));
debug("RangeEntry = " + nummie + " " + desc);
continue;
}
} catch (NumberFormatException e) {}
}
}
//endregion
//region TOUCH LOGIC
private String getTouch(DataContext ctx, Map<Double, String> map,
double high, double low, double open, double close) {
boolean c0G = close > open;
boolean c0R = close < open;
String sType = (map == kpMap) ? "Killpips " : (map == mqMap || map == bsMap) ? "MenthorQ " : "";
for (Map.Entry<Double, String> entry : map.entrySet()) {
Double price = entry.getKey();
if (high > price && low < price) {
//ctx.signal(gIndex, Signals.TOUCH, "Price touched " + sType + entry.getValue(), close);
return " - Touched " + entry.getValue();
}
else if ((c0G && high > price && close < price) || (c0G && low < price && open > price) ||
(c0R && high > price && open < price) || (c0R && low < price && close > price)) {
//ctx.signal(gIndex, Signals.WICK, "Wick off " + sType + entry.getValue(), close);
return " - WICK off " + entry.getValue();
}
}
return "";
}
private void FillMaps(String src, Map xx)
{
//Instrument sI = getSettings().getInstrument("INSTR");
//debug("FillMaps 1 = " + sI.getUnderlying());
String[] parts = getSettings().getString(src).split(", ");
for (int i = 0; i < parts.length; i++) {
try {
Double nums = Double.parseDouble(parts[i].trim());
String txt = parts[i-1].trim();
xx.put(Double.parseDouble(parts[i].trim()), parts[i-1].trim());
//debug("xx = " + nums + ", " + txt);
} catch (NumberFormatException e) {
}
}
}
//endregion
//region INITIALIZE
@Override
public void initialize(Defaults defaults)
{
this.kpMap = new HashMap<>();
this.mqMap = new HashMap<>();
this.bsMap = new HashMap<>();
this.tsRange = new ArrayList<>();
var sd = createSD();
var tab2 = sd.addTab("Lines");
var grp3 = tab2.addGroup("Show These");
grp3.addRow(new BooleanDescriptor("SHOWKP", "Show Killpips", true));
grp3.addRow(new BooleanDescriptor("SHOWMQ", "Show MenthorQ", true));
grp3.addRow(new BooleanDescriptor("SHOWMANBUY", "Show Mancini Buy", true));
grp3.addRow(new BooleanDescriptor("SHOWMANSELL", "Show Mancini Sell", true));
grp3.addRow(new BooleanDescriptor("SHOWTS", "Show TraderSmarts", true));
grp3.addRow(new BooleanDescriptor("SHOW200", "Show EMA 200 touches", true));
grp3.addRow(new BooleanDescriptor("SHOWVWAP", "Show VWAP touches", true));
var grp2 = tab2.addGroup("Paid Lines");
grp2.addRow(new StringDescriptor("TS", "Values", "YM Execution/Target Zones:41943 - 41909 Extreme Short41368 - 41323 Highest Odds Short FTU41118 Range Short40848 - 40805 Line in the Sand40493 Range Long39771 Highest Odds Long FTD39393 Extreme LongYM MTS Numbers: 43145, 41973, 41370, 40913, 40698, 39807, 39350", 500));
//grp2.addRow(new InstrumentDescriptor("INSTR", "Instrument"));
grp2.addRow(new StringDescriptor("KP", "Killpips Values", "vix r1, 41365, vix r2, 41399, vix s1, 40185, vix s2, 40155, 1DexpMAX, 41425, 1DexpMIN, 40129, RD0, 40892, RD1, 40993, RD2, 41215, SD0, 40665, SD1, 40561, SD2, 40343, HV, 40779, VAH, 41557, VAL, 39994, range daily max, 41643, range daily min, 39911", 500));
grp2.addRow(new StringDescriptor("MQ", "MenthorQ Values", "", 500));
grp2.addRow(new StringDescriptor("MQBS", "MenthorQ Blind Spots", "BL 1, 41534.35, BL 2, 41136.24, BL 3, 39993.99, BL 4, 42346.55, BL 5, 40996.71, BL 6, 40357.81, BL 7, 40728.68, BL 8, 41794.62, BL 9, 39076.64, BL 10, 41451.87", 500));
grp2.addRow(new StringDescriptor("ManciniBuy", "Mancini Buy Values", "", 500));
grp2.addRow(new StringDescriptor("ManciniSell", "Mancini Sell Values", "", 500));
RuntimeDescriptor desc = new RuntimeDescriptor();
setRuntimeDescriptor(desc);
desc.declareSignal(Signals.WICK, "Line Wick");
desc.declareSignal(Signals.TOUCH, "Line Touch");
/*
desc.declareSignal(Signals.KP_WICK, "Killpips Line Wick");
desc.declareSignal(Signals.KP_TOUCH, "Killpips Line Touch");
desc.declareSignal(Signals.TS_WICK, "TraderSmarts Line Wick");
desc.declareSignal(Signals.TS_TOUCH, "TraderSmarts Line Touch");
desc.declareSignal(Signals.MQ_WICK, "MenthorQ Line Wick");
desc.declareSignal(Signals.MQ_TOUCH, "MenthorQ Line Touch");
desc.declareSignal(Signals.MAN_WICK, "Mancini Line Wick");
desc.declareSignal(Signals.MAN_TOUCH, "Mancini Line Touch");
*/
}
@Override
public void onSettingsUpdated(DataContext ctx)
{
}
//endregion
@Override
protected void calculate(int index, DataContext ctx)
{
var series = ctx.getDataSeries();
int last = series.size() - 1;
if (series == null || index < 202 || !series.isBarComplete(index))
return;
// CANDLE CALCULATIONS
double close = series.getClose(index);
double open = series.getOpen(index);
double pclose = series.getClose(index - 1);
double popen = series.getOpen(index - 1);
double ppclose = series.getClose(index - 2);
double ppopen = series.getOpen(index - 2);
double clow = series.getLow(index);
double plow = series.getLow(index - 1);
double high = series.getHigh(index);
double phigh = series.getHigh(index - 1);
boolean c0G = close > series.getOpen(index);
boolean c1G = series.getClose(index - 1) > series.getOpen(index - 1);
boolean c2G = series.getClose(index - 2) > series.getOpen(index - 2);
boolean c0R = close < open;
boolean c1R = series.getClose(index - 1) < series.getOpen(index - 1);
boolean c2R = series.getClose(index - 2) < series.getOpen(index - 2);
double body = Math.abs(open - close);
double pbody = Math.abs(series.getOpen(index - 1) - series.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 (kpMap.size() == 0 && getSettings().getBoolean("SHOWKP"))
FillMaps("KP", kpMap);
if (mqMap.size() == 0 && getSettings().getBoolean("SHOWMQ"))
FillMaps("MQ", mqMap);
if (bsMap.size() == 0 && getSettings().getBoolean("SHOWMQ"))
FillMaps("MQBS", bsMap);
if (tsRange.size() == 0 && getSettings().getBoolean("SHOWTS"))
FillTraderSmarts();
}
}