-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFairValueGap.java
More file actions
158 lines (145 loc) · 5.42 KB
/
FairValueGap.java
File metadata and controls
158 lines (145 loc) · 5.42 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
package TraderOracle;
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="FairValueGap",
rb="TraderOracle.nls.strings", // locale specific strings are loaded from here
name="Fair Value Gap",
label="Fair Value Gap",
desc="Fair Value Gap",
menu="TraderOracle",
overlay=true,
studyOverlay=true)
public class FairValueGap extends Study
{
//region VARIABLES
enum Signals { FVG_FILLED, FVG_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);
//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("UP", "Show Green FVGs", true));
grp.addRow(new BooleanDescriptor("DOWN", "Show Red FVGs", true));
grp.addRow(new DoubleDescriptor("MINGAP", "Mimimum gap to show", 0.5, 0, 9999, 0.5));
RuntimeDescriptor desc = new RuntimeDescriptor();
setRuntimeDescriptor(desc);
desc.declareSignal(Signals.FVG_CREATED, "FVG Created");
desc.declareSignal(Signals.FVG_FILLED, "FVG Filled");
}
//endregion
//region DRAW LINES
private void DrawLines(DataSeries s)
{
double dMinGap = getSettings().getDouble("MINGAP");
boolean bShowGreen = getSettings().getBoolean("UP");
boolean bShowRed = getSettings().getBoolean("DOWN");
for (int iq = 0; iq < s.size() - 1; iq ++) {
double low = s.getLow(iq);
double pplow = s.getLow(iq-2);
double high = s.getHigh(iq);
double pphigh = s.getHigh(iq - 2);
//region FAIR VALUE RED
if (pplow > high && bShowRed)
{
boolean bFoundEnd = false;
for (int i = iq + 1; i < s.size() - 1; i++) {
if (s.getHigh(i) > high) {
Box lx = new Box(new Coordinate(s.getEndTime(iq-2), (float) s.getLow(iq-2)),
new Coordinate(s.getStartTime(i), (float) s.getHigh(iq)), new PathInfo(
new Color(153, 34, 56, 250), 1, new float[]{1}, true, true, false, 0, 2));
lx.setUnderlay(true);
lx.setFillColor(new Color(153, 34, 56, 148));
lx.setLineColor(new Color(153, 34, 56, 255));
this.addFigure(lx);
bFoundEnd = true;
break;
}
}
if (!bFoundEnd) {
int iStart = s.getStartIndex();
int iEnd = s.getEndIndex();
Box lx = new Box(new Coordinate(s.getEndTime(iq-2), (float) s.getLow(iq-2)), new Coordinate(s.getEndTime(iEnd) + 1000, (double) s.getHigh(iq)), new PathInfo(
new Color(153, 34, 56, 250), 1, new float[]{1}, true, true, false, 0, 2));
lx.setUnderlay(true);
lx.setFillColor(new Color(153, 34, 56, 158));
lx.setLineColor(new Color(153, 34, 56, 255));
this.addFigure(lx);
bFoundEnd = true;
}
}
//endregion
//region FAIR VALUE GREEN
if (low > pphigh && bShowGreen)
{
boolean bFoundEnd = false;
Coordinate cS = new Coordinate(s.getEndTime(iq-2), (float) s.getHigh(iq-2));
for (int i = iq + 1; i < s.size() - 1; i++) {
if (s.getLow(i) < low) {
Box lx = new Box(new Coordinate(s.getEndTime(iq-2), (float) s.getHigh(iq-2)), new Coordinate(s.getStartTime(i), (float) s.getLow(iq)), new PathInfo(
new Color(153, 34, 56, 250), 1, new float[]{1}, true, true, false, 0, 2));
lx.setUnderlay(true);
lx.setFillColor(new Color(50, 153, 34, 148));
lx.setLineColor(new Color(50, 153, 34, 255));
this.addFigure(lx);
bFoundEnd = true;
break;
}
}
if (!bFoundEnd) {
int iStart = s.getStartIndex();
int iEnd = s.getEndIndex();
Box lx = new Box(new Coordinate(s.getEndTime(iq-2), (float) s.getHigh(iq-2)), new Coordinate(s.getEndTime(iEnd) + 1000, (double) s.getLow(iq)), new PathInfo(
new Color(153, 34, 56, 250), 1, new float[]{1}, true, true, false, 0, 2));
lx.setUnderlay(true);
lx.setFillColor(new Color(50, 153, 34, 158));
lx.setLineColor(new Color(50, 153, 34, 255));
this.addFigure(lx);
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
@Override
protected void calculate(int index, DataContext ctx)
{
var s = ctx.getDataSeries();
int last = s.size() - 1;
Object input = getSettings().getInput(Inputs.INPUT);
if (s == null || index < 2 || !s.isBarComplete(index))
return;
}
}