Repository navigation
Expand file tree
/
Copy pathDefibrillator.cs
More file actions
233 lines (204 loc) · 10.1 KB
/
Copy pathDefibrillator.cs
File metadata and controls
233 lines (204 loc) · 10.1 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
namespace ATAS_Defibrillator
{
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using ATAS.Indicators;
using ATAS.Indicators.Drawing;
using OFT.Rendering.Context;
using OFT.Rendering.Settings;
using OFT.Rendering.Tools;
using Color = System.Drawing.Color;
[DisplayName("Defibrillator")]
public class Defibrillator : Indicator
{
private float fFontSize = 9;
private int _highBar;
private int _lowBar;
private decimal _highest = 0;
private decimal _lowest = 0;
private decimal A05 = 0;
private decimal A113 = 0;
private decimal A150 = 0;
private decimal A1618 = 0;
private decimal A200 = 0;
private decimal A213 = 0;
private decimal A250 = 0;
private decimal A2618 = 0;
private decimal nA113 = 0;
private decimal nA150 = 0;
private decimal nA1618 = 0;
private decimal nA200 = 0;
private decimal nA213 = 0;
private decimal nA250 = 0;
private decimal nA2618 = 0;
private String _highS = "Euro High";
private String _lowS = "Euro Low";
private bool bShowEuro = false;
private bool bShowOvernight = true;
[Display(Name = "Line", GroupName = "Misc")]
public PenSettings defibPen { get; set; } = new()
{
Color = DefaultColors.Red.Convert(),
Width = 1,
LineDashStyle = LineDashStyle.Dot
};
[Display(Name = "Font Size", GroupName = "Misc", Order = int.MaxValue)]
[Range(1, 90)]
public float TextFont
{
get => fFontSize; set { fFontSize = value; RecalculateValues(); }
}
[Display(GroupName = "Misc", Name = "Show Overnight Session", Description = "Show lines for overnight session (1700 - 800 CST")]
public bool Show_Overnight { get => bShowOvernight; set { bShowOvernight = value; RecalculateValues(); } }
[Display(GroupName = "Misc", Name = "Show Euro Session", Description = "Show lines for Euro session (first hour, 2am - 3am CST. Credit: FighterOfEvil on Discord")]
public bool Show_Euro { get => bShowEuro; set { bShowEuro = value; RecalculateValues(); } }
private void DrawString(RenderContext context, string renderText, int yPrice, Color color)
{
var textSize = context.MeasureString(renderText, new RenderFont("Arial", fFontSize));
context.DrawString(renderText, new RenderFont("Arial", fFontSize), color, Container.Region.Right - textSize.Width - 5, yPrice - textSize.Height);
}
protected override void OnRender(RenderContext context, DrawingLayouts layout)
{
if (ChartInfo is null)
return;
var xH = ChartInfo.PriceChartContainer.GetXByBar(_highBar, false);
var yH = ChartInfo.PriceChartContainer.GetYByPrice(_highest, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, _highS, yH, defibPen.RenderObject.Color);
var xL = ChartInfo.PriceChartContainer.GetXByBar(_lowBar, false);
var yL = ChartInfo.PriceChartContainer.GetYByPrice(_lowest, false);
context.DrawLine(defibPen.RenderObject, xL, yL, Container.Region.Right, yL);
DrawString(context, _lowS, yL, defibPen.RenderObject.Color);
if (bShowOvernight)
{
yH = ChartInfo.PriceChartContainer.GetYByPrice(A05, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "0.5", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A113, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "1.13", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A150, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "1.5", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A1618, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "1.618", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A200, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A213, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2.13", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A250, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2.5", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(A2618, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2.618", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA113, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "1.13", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA150, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "1.5", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA1618, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "1.618", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA200, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA213, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2.13", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA250, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2.5", yH, defibPen.RenderObject.Color);
yH = ChartInfo.PriceChartContainer.GetYByPrice(nA2618, false);
context.DrawLine(defibPen.RenderObject, xH, yH, Container.Region.Right, yH);
DrawString(context, "2.618", yH, defibPen.RenderObject.Color);
}
}
public Defibrillator() :
base(true)
{
Panel = IndicatorDataProvider.CandlesPanel;
DenyToChangePanel = true;
EnableCustomDrawing = true;
SubscribeToDrawingEvents(DrawingLayouts.Final);
}
private void MarkEuroSession(int bar)
{
_highS = "Euro High";
_lowS = "Euro Low";
var candle = GetCandle(bar);
var diff = InstrumentInfo.TimeZone;
var time = candle.Time.AddHours(diff);
if (time.Minute >= 0 && time.Hour >= 2 && time.Hour <= 3)
{
if (candle.High > _highest)
{
_highest = candle.High;
_highBar = bar;
}
if (candle.Low > _lowest)
{
_lowest = candle.Low;
_lowBar = bar;
}
}
}
private void MarkOvernightSession(int bar)
{
_highS = "1";
_lowS = "0";
var candle = GetCandle(bar);
var diff = InstrumentInfo.TimeZone;
var time = candle.Time.AddHours(diff);
if ((time.Minute >= 0 && time.Hour >= 17 && time.Hour <= 24) ||
(time.Minute >= 0 && time.Hour >= 0 && time.Hour <= 7))
{
if (candle.High > _highest)
{
_highest = candle.High;
_highBar = bar;
}
if (candle.Low < _lowest)
{
_lowest = candle.Low;
_lowBar = bar;
}
}
}
protected override void OnCalculate(int bar, decimal value)
{
var candle = GetCandle(bar);
if (IsNewSession(bar))
{
_highest = candle.High;
_lowest = candle.Low;
}
if (bShowEuro)
MarkEuroSession(bar);
if (bShowOvernight)
MarkOvernightSession(bar);
var fibrange = _highest - _lowest;
decimal r = Math.Abs(fibrange);
A05 = _lowest + 0.5m * r;
A113 = _lowest + 1.13m * r;
A150 = _lowest + 1.5m * r;
A1618 = _lowest + 1.618m * r;
A200 = _lowest + 2.00m * r;
A213 = _lowest + 2.13m * r;
A250 = _lowest + 2.5m * r;
A2618 = _lowest + 2.618m * r;
nA113 = _highest - 1.13m * r;
nA150 = _highest - 1.5m * r;
nA1618 = _highest - 1.618m * r;
nA200 = _highest - 2.00m * r;
nA213 = _highest - 2.13m * r;
nA250 = _highest - 2.5m * r;
nA2618 = _highest - 2.618m * r;
}
}
}