-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQMATRSLTP.cs
114 lines (96 loc) · 2.69 KB
/
QMATRSLTP.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
113
114
using ATAS.Indicators.Drawing;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace ATAS.Indicators.Technical
{
[DisplayName("QM ATR SL&TP")]
public class QMATRSLTP : Indicator
{
#region Fields
private readonly ATR _atr = new()
{
Period = 5
};
private bool _showAsTicks = true;
private decimal _multiplier = 1.0M;
private decimal _crv = 2.0M;
private readonly ValueDataSeries _renderSeriesATR = new("Visualisierung ATR")
{
Color = DefaultColors.Blue.Convert()
};
private readonly ValueDataSeries _renderSeriesSL = new("Visualisierung Stop Loss")
{
Color = DefaultColors.Red.Convert()
};
private readonly ValueDataSeries _renderSeriesTP = new("Visualisierung Take Profit")
{
Color = DefaultColors.Green.Convert()
};
#endregion
#region Properties
[DisplayName("ATR Periode")]
[Range(1, 10000)]
public int Period
{
get => _atr.Period;
set
{
_atr.Period = value;
RecalculateValues();
}
}
[DisplayName("Show as Ticks")]
public bool ShowAsTicks
{
get => _showAsTicks;
set
{
_showAsTicks = 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 QMATRSLTP() : base(true)
{
Panel = IndicatorDataProvider.NewPanel;
Add(_atr);
DataSeries[0] = _renderSeriesATR;
DataSeries.Add(_renderSeriesSL);
DataSeries.Add(_renderSeriesTP);
}
#endregion
protected override void OnCalculate(int bar, decimal value)
{
var atr = ((ValueDataSeries)_atr.DataSeries[0])[bar];
var sl = atr * _multiplier;
var tp = sl * _crv;
if (_showAsTicks)
{
sl /= InstrumentInfo.TickSize;
tp /= InstrumentInfo.TickSize;
}
_renderSeriesATR[bar] = atr;
_renderSeriesSL[bar] = sl;
_renderSeriesTP[bar] = tp;
}
}
}