-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTraderSmarts_QT1.cs
More file actions
272 lines (238 loc) · 9.86 KB
/
TraderSmarts_QT1.cs
File metadata and controls
272 lines (238 loc) · 9.86 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Numerics;
using TradingPlatform.BusinessLayer;
using System.Diagnostics.Metrics;
using TradingPlatform.BusinessLayer.Utils;
using TradingPlatform.BusinessLayer.Chart;
using System.Drawing.Text;
using System.Linq;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Reflection;
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.IO;
namespace TraderSmarts_QT
{
public class TraderSmarts_QT : Indicator
{
#region VARIABLES
private const string sVersion = "1.1";
private bool bUseAlerts = true;
private bool bAlertWick = false;
private bool bDrawn = false;
private bool bProcessing = false;
private struct days
{
public string label;
public double price1;
public double price2;
public Color c;
}
private List<days> lsDays = new List<days>();
#endregion
#region SETTINGS
[InputParameter("Show Line Labels")]
public bool bShowLabels = true;
[InputParameter("Font Size")]
public int iFontSize = 8;
[InputParameter("Show MTS")]
public bool bShowMTS = true;
[InputParameter("Show TS")]
public bool bShowTS = true;
[InputParameter("Input File")]
public System.String txtFile = @"c:\temp\tradersmarts.txt";
[InputParameter("Font Color")]
public Brush txtBrush = Brushes.White;
[InputParameter("Long Color")]
public Color cLong = Color.Lime;
[InputParameter("Short Color")]
public Color cShort = Color.Red;
[InputParameter("Line in Sand Color")]
public Color cSand = Color.FromArgb(255, 143, 83, 237);
[InputParameter("MTS Color")]
public Color cMTS = Color.Beige;
[InputParameter("TS Color")]
public Color cTS = Color.DodgerBlue;
#endregion
public TraderSmarts_QT()
: base()
{
Name = "TraderSmarts QT";
Description = "TraderSmarts for Quantower";
SeparateWindow = false;
}
protected override void OnInit()
{
FetchData();
bDrawn = false;
}
public override void OnPaintChart(PaintChartEventArgs args)
{
if (CurrentChart == null || this.HistoricalData == null)
return;
if (bProcessing)
return;
Graphics gr = args.Graphics;
IChartWindow mainWindow = CurrentChart.MainWindow;
HistoryItemBar bar1 = new HistoryItemBar();
for (int i = (int)mainWindow.CoordinatesConverter.GetBarIndex(mainWindow.CoordinatesConverter.GetTime(mainWindow.ClientRectangle.Left)); i <= (int)Math.Ceiling(mainWindow.CoordinatesConverter.GetBarIndex(mainWindow.CoordinatesConverter.GetTime(mainWindow.ClientRectangle.Right))); i++)
if (i > 0 && i < this.HistoricalData.Count && this.HistoricalData[i, SeekOriginHistory.Begin] is HistoryItemBar bar)
bar1 = (HistoryItemBar)this.HistoricalData[i - 1, SeekOriginHistory.Begin];
SolidBrush redLarge = new SolidBrush(Color.FromArgb(122, 176, 74, 19));
SolidBrush greenLarge = new SolidBrush(Color.FromArgb(128, 103, 224, 4));
SolidBrush purple = new SolidBrush(Color.FromArgb(108, 123, 48, 242));
foreach (days st in lsDays)
{
SolidBrush howdy = st.label.Contains("Short") ? redLarge :
st.label.Contains("Long") ? greenLarge : purple;
int iY1 = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartY(st.price1));
int iY2 = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartY(st.price2));
int iX = (int)Math.Round(mainWindow.CoordinatesConverter.GetChartX(bar1.TimeRight) - (CurrentChart.BarsWidth / 2) + 30);
int iRight = mainWindow.ClientRectangle.Right - 20;
if (iY1 != iY2)
{
if (iY2 > iY1)
{
//if (! gr.IsVisible(new RectangleF(0, iY1, iRight, iY2 - iY1)))
{
gr.FillRegion(howdy, new Region(new RectangleF(0, iY1, iRight, iY2 - iY1)));
gr.DrawString(st.label, new Font("Arial", iFontSize), txtBrush, iX, iY1);
}
}
else
{
//if (!gr.IsVisible(new RectangleF(0, iY1, iRight, iY2 - iY1)))
{
gr.FillRegion(howdy, new Region(new RectangleF(0, iY2, iRight, iY1 - iY2)));
gr.DrawString(st.label, new Font("Arial", iFontSize), txtBrush, iX, iY2);
}
}
}
else
gr.DrawString(st.label, new Font("Arial", iFontSize), txtBrush, iX, iY1);
//gr.DrawRectangle(new Pen(Brushes.Red), new Rectangle(iX, iY, 500, 550));
//gr.FillRectangle(semiTransparentRedBrush, new Rectangle(0, iY, mainWindow.ClientRectangle.Width - 20, 20));
}
//bDrawn = true;
base.OnPaintChart(args);
}
#region MISC
private void AddRecord(string price, string s, string price2 = "")
{
Color c = new Color();
if (price2 == "") price2 = price;
if (s.Contains("Long")) c = cLong;
else if (s.Contains("Short")) c = cShort;
else if (s.Contains("Sand")) c = cSand;
else if (s.Contains("MTS")) c = cMTS;
else if (s.Contains("TS")) c = cTS;
try
{
days a = new days();
a.c = c;
a.label = s;
a.price1 = Convert.ToDouble(price);
a.price2 = Convert.ToDouble(price2);
lsDays.Add(a);
int iWidth = s.Contains("Sand") ? 4 : 1;
if (a.price1 == a.price2)
{
LineLevel lll = new LineLevel(a.price2, s, c, iWidth, LineStyle.Solid);
if (!LinesLevels.Contains(lll))
this.AddLineLevel(lll);
}
}
catch { }
}
protected bool IsDigit(string s)
{
try
{
double xx = Convert.ToDouble(s);
return true;
}
catch { }
return false;
}
#endregion
#region PROCESS DATA
protected bool FetchData()
{
try
{
string[] lines = File.ReadAllLines(txtFile);
for (int iR = 0; iR < lines.Length; iR += 1)
{
string s = lines[iR];
string s1, s2;
if (s.Contains("Numbers") && bShowMTS)
{
// NQ MTS Numbers: 20390.25, 19501, 19234.75, 18912, 18517, 18420
s = s.Replace("MTS Numbers: ", "").Replace(" ", "");
string[] price = s.Split(',');
foreach (string p in price)
AddRecord(p, "MTS");
}
else if (s.Length > 400 && bShowTS)
{
string[] ass = s.Replace(" ", "").Split(",");
foreach (string p in ass)
if (IsDigit(p))
AddRecord(p, "TS");
}
else if (s.Contains("Short") || s.Contains("Long") || s.Contains("Sand"))
{
if (s.Contains(" - "))
{
// 4610.75 - 4608.75 Range Short
s = s.Replace(" - ", "-");
int i = s.IndexOf(' ');
if (i >= 0)
{
s1 = s.Substring(0, i).Trim();
s2 = " " + s.Substring(i, s.Length - i).Trim();
string[] price = s1.Split('-');
if (IsDigit(price[0]) && IsDigit(price[1]))
AddRecord(price[0], s2, price[1]);
}
}
else
{
// 4597.75 Line in the Sand
int i = s.IndexOf(' ');
if (i >= 0)
{
s1 = s.Substring(0, i).Trim();
s2 = s.Substring(i, s.Length - i).Trim();
if (IsDigit(s1))
AddRecord(s1, s2);
}
}
}
}
}
catch
{
return false;
}
return true;
}
#endregion
protected override void OnUpdate(UpdateArgs args)
{
if (this.Count < 2)
return;
if (args.Reason == UpdateReason.NewBar)
{
bProcessing = true;
//FetchData();
bProcessing = false;
bDrawn = true;
}
}
}
}