-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQMATRSLTPOverlay.cs
112 lines (92 loc) · 2.84 KB
/
QMATRSLTPOverlay.cs
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
using ATAS.Indicators.Drawing;
using OFT.Rendering;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace ATAS.Indicators.Technical
{
[DisplayName("QM ATR SL&TP (Overlay)")]
public class QMATRSLTPOverlay : Indicator
{
#region Fields
private readonly ATR _atr = new()
{
Period = 5
};
private decimal _multiplier = 1.0M;
private decimal _crv = 2.0M;
private readonly ValueDataSeries _renderSeriesLongSL = new("Long SL")
{
Color = DefaultColors.Red.SetTransparency(0.8M).Convert()
};
private readonly ValueDataSeries _renderSeriesLongTP = new("Long TP")
{
Color = DefaultColors.Green.SetTransparency(0.8M).Convert()
};
private readonly ValueDataSeries _renderSeriesShortSL = new("Short SL")
{
Color = DefaultColors.Red.SetTransparency(0.8M).Convert()
};
private readonly ValueDataSeries _renderSeriesShortTP = new("Short TP")
{
Color = DefaultColors.Green.SetTransparency(0.8M).Convert()
};
#endregion
#region Properties
[DisplayName("ATR Periode")]
[Range(1, 10000)]
public int Period
{
get => _atr.Period;
set
{
_atr.Period = value;
RecalculateValues();
}
}
[DisplayName("Multiplier")]
public decimal Multiplier
{
get => _multiplier;
set
{
_multiplier = value;
RecalculateValues();
}
}
[DisplayName("CRV")]
public decimal CRV
{
get => _crv;
set
{
_crv = value;
RecalculateValues();
}
}
public QMATRSLTPOverlay() : base(true)
{
Add(_atr);
DataSeries[0] = _renderSeriesLongSL;
DataSeries.Add(_renderSeriesLongTP);
DataSeries.Add(_renderSeriesShortSL);
DataSeries.Add(_renderSeriesShortTP);
}
#endregion
protected override void OnCalculate(int bar, decimal value)
{
var atr = ((ValueDataSeries)_atr.DataSeries[0])[bar];
var sl = atr * _multiplier;
var tp = sl * _crv;
var candle = GetCandle(bar);
var pocPrice = candle.MaxVolumePriceInfo.Price;
var longTP = pocPrice + tp;
var longSL = pocPrice - sl;
var shortTP = pocPrice - tp;
var shortSL = pocPrice + sl;
_renderSeriesLongTP[bar] = longTP;
_renderSeriesLongSL[bar] = longSL;
_renderSeriesShortTP[bar] = shortTP;
_renderSeriesShortSL[bar] = shortSL;
}
}
}