-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathQT_Tester.cs
More file actions
281 lines (240 loc) · 10.3 KB
/
QT_Tester.cs
File metadata and controls
281 lines (240 loc) · 10.3 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.ConstrainedExecution;
using TradingPlatform.BusinessLayer;
using TradingPlatform.BusinessLayer.Chart;
namespace Oscillators;
public class Imbalance
{
public HistoryItemBar begin;
public HistoryItemBar end;
public Imbalance(HistoryItemBar b, HistoryItemBar e)
{
this.begin = b;
this.end = e;
}
}
public class Bars
{
public enum HiLo
{
Long, Short, None
}
public HistoryItemBar bar;
public HiLo setupDefault = HiLo.None;
public int barIndex;
public Color color;
public int endBarIndex;
public Bars(HistoryItemBar b, int i, HiLo s, Color color)
{
this.bar = b;
this.barIndex = i;
this.color = color;
}
}
public sealed class IndicatorOmnibus : Indicator, IWatchlistIndicator
{
private Indicator fastSMA;
private Indicator slowSMA;
private Indicator signal;
private Indicator Rsi;
private Indicator ma;
private Indicator BB;
private Indicator SAR;
private Indicator waddahFast;
private Indicator waddahSlow;
public List<Bars> barslist = new List<Bars>();
public List<Imbalance> volImb = new List<Imbalance>();
public String sNextAlert = string.Empty;
[InputParameter("Play Alert Sounds")]
public bool bAlerts = true;
[InputParameter("Sound Directory")]
public String sWavDir = @"C:\temp\sounds";
public int MinHistoryDepths => this.MaxEMAPeriod + 16;
private int MaxEMAPeriod => Math.Max(3, 9);
public IndicatorOmnibus()
: base()
{
this.Name = "Omnibus";
}
protected override void OnInit()
{
// LINDA MACD
this.fastSMA = Core.Indicators.BuiltIn.SMA(3, PriceType.Typical);
this.slowSMA = Core.Indicators.BuiltIn.SMA(9, PriceType.Typical);
this.signal = Core.Indicators.BuiltIn.SMA(16, PriceType.Typical);
this.ma = Core.Indicators.BuiltIn.MA(20, PriceType.Close, MaMode.SMA, Indicator.DEFAULT_CALCULATION_TYPE);
this.AddIndicator(this.fastSMA);
this.AddIndicator(this.slowSMA);
this.AddIndicator(this.signal);
this.AddIndicator(this.ma);
// WADDAH EXPLOSION
waddahFast = Core.Indicators.BuiltIn.SMA(20, PriceType.Close);
waddahSlow = Core.Indicators.BuiltIn.SMA(40, PriceType.Close);
AddIndicator(waddahFast);
AddIndicator(waddahSlow);
// REMAINDER
this.Rsi = Core.Indicators.BuiltIn.RSI(14, PriceType.Close, RSIMode.Exponential, MaMode.EMA, 10);
this.BB = Core.Indicators.BuiltIn.BB(20, 2, PriceType.Close, MaMode.EMA);
this.SAR = Core.Indicators.BuiltIn.SAR(0.02, 0.2);
this.AddIndicator(this.Rsi);
this.AddIndicator(this.BB);
this.AddIndicator(this.SAR);
}
public override void OnPaintChart(PaintChartEventArgs args)
{
base.OnPaintChart(args);
if (CurrentChart == null)
return;
Graphics graphics = args.Graphics;
IChartWindow mainWindow = CurrentChart.MainWindow;
volImb.FindAll(item => true)
.ForEach(item =>
{
int xCoord = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartX(item.begin.TimeRight));
int yy = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartY(item.begin.Close));
int iEnd = xCoord + 10000;
if (item.end != null)
iEnd = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartX(item.end.TimeRight) -
(CurrentChart.BarsWidth / 2));
Pen dashPen = new Pen(Color.FromArgb(255, 139, 188, 252), 2);
dashPen.DashPattern = new float [] { 5, 1, 3, 1 };
graphics.DrawLine(dashPen, xCoord, yy, iEnd, yy);
});
barslist.FindAll(item => true)
.ForEach(item =>
{
double drawingPrice = item.setupDefault == Bars.HiLo.Long ? item.bar.Low : item.bar.High;
int xCoord = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartX(item.bar.TimeRight) - (CurrentChart.BarsWidth / 2));
int yCoord = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartY(drawingPrice));
graphics.FillEllipse(new SolidBrush(item.color), xCoord - 5, yCoord - 12, 5, 5);
//graphics.DrawString("TR", new Font("Arial", 11, FontStyle.Bold), new SolidBrush(Color.Yellow), xCoord - 10, yCoord);
});
}
private void SendAlert(String sSound)
{
sNextAlert = string.Empty;
try
{
System.Diagnostics.Process.Start("cmd.exe", "/c " + sWavDir + "\\" + sSound + ".wav");
}
catch { }
}
protected override void OnUpdate(UpdateArgs args)
{
if (this.Count < this.MaxEMAPeriod)
return;
if (args.Reason == UpdateReason.NewBar && sNextAlert != string.Empty)
SendAlert(sNextAlert);
if (args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar)
{
HistoryItemBar candle = (HistoryItemBar)HistoricalData[Count - 1, SeekOriginHistory.Begin];
HistoryItemBar prev = (HistoryItemBar)HistoricalData[Count - 2, SeekOriginHistory.Begin];
// WADDAH EXPLOSION
var fastMinusSlowCurr = waddahFast.GetValue(0) - waddahSlow.GetValue(0);
var fastMinusSlowPrev = waddahFast.GetValue(1) - waddahSlow.GetValue(1);
var fastMinusSlowMorePrev = waddahFast.GetValue(2, 0) - waddahSlow.GetValue(2, 0);
var t1 = (fastMinusSlowCurr - fastMinusSlowPrev) * 150;
var t1Prev = (fastMinusSlowPrev - fastMinusSlowMorePrev) * 150;
var e1 = BB.GetValue(0, 0) - BB.GetValue(0, 2);
var trendUp = t1 >= 0 ? t1 : 0;
var trendUpPrev = t1Prev >= 0 ? t1Prev : 0;
var trendDown = t1 < 0 ? (t1 * -1) : 0;
var trendDownPrev = t1Prev < 0 ? (t1Prev * -1) : 0;
bool bWaddahUp = t1 > 0;
bool bWaddahDown = t1 <= 0;
// LINDA MACD
double fast = this.fastSMA.GetValue();
double slow = this.slowSMA.GetValue();
double sig = this.signal.GetValue();
double macdLine = fast - slow;
double histogram = macdLine - sig;
//if (macdLine > 0 && bWaddahUp)
//{
// Bars b = new Bars(candle, 1, Bars.HiLo.Long, Color.Lime);
// if (!barslist.Contains(b))
// barslist.Add(b);
//}
// VOLUME IMBALANCE RESOLUTION
volImb.FindAll(item => true).ForEach(item =>
{
if (item.end == null && High() > item.begin.Close && Low() < item.begin.Close)
{
if (args.Reason == UpdateReason.NewBar &&
Low() < item.begin.Close &&
Open() > item.begin.Close &&
Close() < Open())
sNextAlert = "volimbfill";
if (args.Reason == UpdateReason.NewBar &&
High() > item.begin.Close &&
Close() < item.begin.Close &&
Close() > Open())
sNextAlert = "volimbfill";
item.end = candle;
}
});
// Manually calculate BB 20/2
double maValue = this.ma.GetValue();
double sum = 0.0;
for (int i = 0; i < 20; i++)
sum += Math.Pow(this.GetPrice(PriceType.Close, i) - maValue, 2);
sum = 2 * Math.Sqrt(sum / 20);
double ub = maValue + sum;
double lb = maValue - sum;
bool c0G = Close() > Open();
bool c1G = Close(1) > Open(1);
bool c2G = Close(2) > Open(2);
bool c0R = Close() < Open();
bool c1R = Close(1) < Open(1);
bool c2R = Close(2) < Open(2);
double c0Body = Math.Abs(Close() - Open());
double c1Body = Math.Abs(Close(1) - Open(1));
// VOLUME IMBALANCE
if ((c0G && c1G && Open() > Close(1)) || (c0R && c1R && Open() < Close(1)))
{
Imbalance b = new Imbalance(prev, null);
if (!volImb.Contains(b))
volImb.Add(b);
sNextAlert = "volimb";
}
if ((Low() < lb || Low(1) < lb) &&
(c0Body > c1Body) && (c1R && c0G) &&
(Open() < Close(1) || Open() == Close(1)))
{
//Bars b = new Bars(candle, 1, Bars.HiLo.Long, Color.White);
//if (!barslist.Contains(b))
// barslist.Add(b);
SetBarColor(Color.White);
sNextAlert = "engulf";
}
if ((High() > ub || High(1) > ub || High(2) > ub) &&
(c0Body > c1Body) && (c1G && c0R) &&
(Close() < Open(1) || Open() == Close(1)))
{
//Bars b = new Bars(candle, 1, Bars.HiLo.Short, Color.White);
//if (!barslist.Contains(b))
// barslist.Add(b);
SetBarColor(Color.White);
sNextAlert = "engulf";
}
double rsi = Rsi.GetValue();
double rsi1 = Rsi.GetValue(1);
double rsi2 = Rsi.GetValue(2);
// TRAMPOLINE
if (c0R && c1R && Close() < Close(1) && (rsi >= 70 || rsi1 >= 70 || rsi2 >= 70) && c2G && High(2) >= ub)
{
//Bars b = new Bars(candle, 1, Bars.HiLo.Short, Color.White);
//if (!barslist.Contains(b))
// barslist.Add(b);
}
if (c0G && c1G && candle.Close > Close(1) && (rsi < 25 || rsi1 < 25 || rsi2 < 25) && c2R && Low(2) <= lb)
{
//Bars b = new Bars(candle, 1, Bars.HiLo.Long, Color.White);
//if (!barslist.Contains(b))
// barslist.Add(b);
}
}
}
}