-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVolImb.java
More file actions
292 lines (256 loc) · 10.2 KB
/
VolImb.java
File metadata and controls
292 lines (256 loc) · 10.2 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
package TraderOracle;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
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.*;
@StudyHeader(
namespace="com.DickInTheSpleen",
id="VolumeImbalance",
rb="TraderOracle.nls.strings", // locale specific strings are loaded from here
name="Volume Imbalance",
label="Volume Imbalance",
desc="Volume Imbalance",
menu="TraderOracle",
overlay=true,
studyOverlay=true)
public class VolImb extends Study
{
//region VARIABLES
enum Signals { VOLIMB_FILLED, VOLIMB_WICK, VOLIMB_CREATED }
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 List<Figure> al = new ArrayList<>();
private int candleFirst = 0;
private int candleLast = 0;
//endregion
//region INITIALIZE
@Override
public void initialize(Defaults defaults)
{
var sd = createSD();
var tab = sd.addTab("Settings");
var grp = tab.addGroup("Inputs");
grp.addRow(new BooleanDescriptor("StdMethod", "Use standard candle gap calculation", true));
grp.addRow(new BooleanDescriptor("FVGMethod", "Use FVG calculation, instead", true));
grp.addRow(new BooleanDescriptor("GREEN", "Show Green Vol Imbalances", true));
grp.addRow(new BooleanDescriptor("RED", "Show Red Vol Imbalances", true));
grp.addRow(new BooleanDescriptor("GAPDATA", "Show Gap Data on Line", true));
grp.addRow(new StringDescriptor("NYO", "New York Open Time", "08:30"));
grp.addRow(new StringDescriptor("NYC", "NY Open + 15 mins", "08:45"));
RuntimeDescriptor desc = new RuntimeDescriptor();
setRuntimeDescriptor(desc);
desc.declareSignal(Signals.VOLIMB_CREATED, "Volume Imbalance Created");
desc.declareSignal(Signals.VOLIMB_FILLED, "Volume Imbalance Filled");
desc.declareSignal(Signals.VOLIMB_WICK, "Volume Imbalance Wicked");
}
//endregion
//region DRAW LINES
private void DrawLines(DataSeries s)
{
PathInfo pf = new PathInfo(
new Color(166, 200, 255, 250), 2, new float[]{3, 2, 5}, true, true, false, 0, 2);
for (int iq = 0; iq < s.size() - 1; iq ++) {
int index = iq;
// CANDLE CALCULATIONS
double close = s.getClose(index);
double pclose = s.getClose(index - 1);
double open = s.getOpen(index);
double low = s.getLow(index);
double pplow = s.getLow(index-2);
double high = s.getHigh(index);
double pphigh = s.getHigh(index - 2);
boolean c0G = close > s.getOpen(index);
boolean c1G = s.getClose(index - 1) > s.getOpen(index - 1);
boolean bShowGreen = getSettings().getBoolean("GREEN");
boolean bShowRed = getSettings().getBoolean("RED");
boolean bStdMethod = getSettings().getBoolean("StdMethod");
boolean bFVGMethod = getSettings().getBoolean("FVGMethod");
//endregion
//region FAIR VALUE GAPS GREEN
if (false && bShowGreen && (low > pphigh && bFVGMethod))
{
boolean bFoundEnd = false;
//Coordinate cS = new Coordinate(s.getEndTime(iq-2), (float) s.getHigh(iq-2));
Coordinate cS = new Coordinate(s.getEndTime(iq-2), (float) s.getHigh(iq-2));
for (int i = index + 1; i < s.size() - 1; i++) {
//if (s.getLow(i) < low) {
if (s.getLow(i) < low) {
//new Box(new Coordinate(s.getEndTime(iq-2), (float) s.getHigh(iq-2)),
// new Coordinate(s.getStartTime(i), (float) s.getLow(iq))
var cE = new Coordinate(s.getStartTime(i), (float) s.getLow(iq));
float middle = Math.abs(s.getHigh(iq-2) - s.getLow(iq)) + s.getLow(iq);
var cMidE = new Coordinate(s.getStartTime(i), middle);
Coordinate cMidS = new Coordinate(s.getEndTime(iq-2), middle);
//debug("StartTime(i) " + s.getStartTime(i) + " s.getLow(iq) " + s.getLow(iq) + " s.getHigh(iq-2) " + s.getHigh(iq-2) + " middle " + middle);
Line lk = new Line(cMidS, cMidE, pf);
lk.setExtendRightBounds(false);
lk.setExtendLeftBounds(false);
lk.setText("fvg", new Font("Arial", Font.PLAIN, 12));
this.addFigure(lk);
bFoundEnd = true;
break;
}
}
if (!bFoundEnd) {
int iStart = s.getStartIndex();
int iEnd = s.getEndIndex();
float middle = Math.abs(s.getHigh(iq-2) - s.getLow(iq)) + s.getLow(iq);
var cMidE = new Coordinate(s.getStartTime(iq), middle);
Coordinate cMidS = new Coordinate(s.getEndTime(iq-2), middle);
var cE = new Coordinate(s.getEndTime(iEnd) + 1000, (double) middle);
Line lk = new Line(cMidS, cMidE, pf);
lk.setExtendRightBounds(true);
lk.setText("fvg", new Font("Arial", Font.PLAIN, 12));
this.addFigure(lk);
bFoundEnd = true;
}
}
//endregion
//region VOLUME IMBALANCES GREEN
if (bShowGreen && (c0G && c1G && open > pclose && bStdMethod))
{
boolean bFoundEnd = false;
Coordinate cS = new Coordinate(s.getStartTime(index), (double) s.getOpen(index));
for (int i = index + 1; i < s.size() - 1; i++) {
if (s.getLow(i) < s.getOpen(index)) {
//debug("index " + index + ", lindex " + i);
var cE = new Coordinate(s.getEndTime(i), (double) s.getOpen(index));
Line lk = new Line(cS, cE, pf);
lk.setExtendRightBounds(false);
lk.setExtendLeftBounds(false);
//lk.setText("VolImb", new Font("Arial", Font.PLAIN, 12));
this.addFigure(lk);
bFoundEnd = true;
break;
}
}
if (!bFoundEnd) {
int iStart = s.getStartIndex();
int iEnd = s.getEndIndex();
var cE = new Coordinate(s.getEndTime(iEnd) + 1000, (double) s.getOpen(index));
Line lk = new Line(cS, cE, pf);
lk.setExtendRightBounds(true);
//lk.setText("VolImb", new Font("Arial", Font.PLAIN, 12));
this.addFigure(lk);
bFoundEnd = true;
}
}
//endregion
}
}
//endregion
//region SETTINGS AND BARCLOSE
@Override
public void onSettingsUpdated(DataContext ctx)
{
this.clearFigures();
DrawLines(ctx.getDataSeries());
}
@Override
public void onBarClose(DataContext ctx)
{
this.clearFigures();
DrawLines(ctx.getDataSeries());
}
//endregion
//region TIME CONVERSION
public static long getSecondsSinceMidnight(long epochMillis) {
ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneId.systemDefault());
ZonedDateTime midnight = zdt.truncatedTo(ChronoUnit.DAYS);
return ChronoUnit.SECONDS.between(midnight, zdt);
}
private long convertTimeToSeconds(String timeString) {
String[] parts = timeString.split(":");
int hours = Integer.parseInt(parts[0]);
int minutes = Integer.parseInt(parts[1]);
int totalSeconds = hours * 3600 + minutes * 60;
return (long) totalSeconds;
}
//endregion
@Override
protected void calculate(int index, DataContext ctx)
{
/*
var s = ctx.getDataSeries();
int last = s.size() - 1;
if (s == null || index < last-600 || !s.isBarComplete(index))
return;
long candleStart = getSecondsSinceMidnight(s.getStartTime(index));
long candleEnd = getSecondsSinceMidnight(s.getEndTime(index));
long EightThirty = convertTimeToSeconds("08:30");
long EightFortyFive = convertTimeToSeconds("08:45");
if (EightThirty >= candleStart && EightThirty <= candleEnd) {
candleFirst = index;
s.setPriceBarColor(index, WHITE);
}
if (EightFortyFive >= candleStart && EightFortyFive <= candleEnd) {
candleLast = index;
s.setPriceBarColor(index, WHITE);
}
if (candleFirst > 0 && candleLast > 0){
double howdy = s.lowest(candleLast, candleLast-candleFirst, Enums.BarInput.LOW);
debug("Lowest " + howdy + " last " + last);
}
/*
List<Figure> figures = this.getFigures();
for (Figure figure : figures) {
figure.setPopupMessage("FdsASD");
figure.setUnderlay(false);
}
Object input = getSettings().getInput(Inputs.INPUT);
debug("getLabel " + this.getLabel());
RuntimeDescriptor ts = this.getRuntimeDescriptor();
Plot t = ts.getPricePlot();
t.clearIndicators();
t.clearPaths();
t.clearPriceBars();
//debug("Plot " + t.getTabName());
List<Figure> figures = this.getFigures(t.getName());
//debug("List<Figure> " + figures.size());
Plot t2 = ts.getDefaultPlot();
t2.clearIndicators();
t2.clearPaths();
t2.clearPriceBars();
//debug("Plot " + t2.getTabName());
List<Figure> figures2 = this.getFigures(t2.getName());
debug("List<Figure2> " + figures2.size());
List<Figure> figures3 = this.getFigures();
debug("List<Figure3> " + figures3.size());
//if (figures == null || figures.isEmpty()) return;
//int count = ctx.getBarCount();
//int x = getBarCoordinate(ctx, count-1);
//int y = getYCoordinate(ctx, price);
for (Figure figure : figures) {
debug("figure " + index);
figure.setPopupMessage("FdsASD");
figure.setUnderlay(false);
var rect = figure.getBounds();
double low = s.getLow(index);
double high = s.getHigh(index);
if (rect.contains(s.getEndTime(index), low)){
debug("bounds " + low);
}
//if (isRectangleFigure(figure)) {
//Rectangle bounds = figure.getBounds();
//debug("bounds " + bounds.x);
//if (bounds.contains(x, y)) {
//return true;
//}
//}
}
*/
}
}