Lean
$LEAN_TAG$
MovingAverageTypeExtensions.cs
1
/*
2
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
16
using
System;
17
18
namespace
QuantConnect.Indicators
19
{
20
/// <summary>
21
/// Provides extension methods for the MovingAverageType enumeration
22
/// </summary>
23
public
static
class
MovingAverageTypeExtensions
24
{
25
/// <summary>
26
/// Creates a new indicator from the specified MovingAverageType. So if MovingAverageType.Simple
27
/// is specified, then a new SimpleMovingAverage will be returned.
28
/// </summary>
29
/// <param name="movingAverageType">The type of averaging indicator to create</param>
30
/// <param name="period">The smoothing period</param>
31
/// <returns>A new indicator that matches the MovingAverageType</returns>
32
public
static
IndicatorBase<IndicatorDataPoint>
AsIndicator
(
this
MovingAverageType
movingAverageType,
int
period)
33
{
34
switch
(movingAverageType)
35
{
36
case
MovingAverageType
.Simple:
37
return
new
SimpleMovingAverage
(period);
38
39
case
MovingAverageType
.Exponential:
40
return
new
ExponentialMovingAverage
(period);
41
42
case
MovingAverageType
.Wilders:
43
return
new
WilderMovingAverage
(period);
44
45
case
MovingAverageType
.LinearWeightedMovingAverage:
46
return
new
LinearWeightedMovingAverage
(period);
47
48
case
MovingAverageType
.DoubleExponential:
49
return
new
DoubleExponentialMovingAverage
(period);
50
51
case
MovingAverageType
.TripleExponential:
52
return
new
TripleExponentialMovingAverage
(period);
53
54
case
MovingAverageType
.Triangular:
55
return
new
TriangularMovingAverage
(period);
56
57
case
MovingAverageType
.T3:
58
return
new
T3MovingAverage
(period);
59
60
case
MovingAverageType
.Kama:
61
return
new
KaufmanAdaptiveMovingAverage
(period);
62
63
case
MovingAverageType
.Hull:
64
return
new
HullMovingAverage
(period);
65
66
case
MovingAverageType
.Alma:
67
return
new
ArnaudLegouxMovingAverage
(period);
68
69
case
MovingAverageType
.Zlema:
70
return
new
ZeroLagExponentialMovingAverage
(period);
71
72
case
MovingAverageType
.MGD:
73
return
new
McGinleyDynamic
(period);
74
75
default
:
76
throw
new
ArgumentOutOfRangeException(nameof(movingAverageType));
77
}
78
}
79
80
/// <summary>
81
/// Creates a new indicator from the specified MovingAverageType. So if MovingAverageType.Simple
82
/// is specified, then a new SimpleMovingAverage will be returned.
83
/// </summary>
84
/// <param name="movingAverageType">The type of averaging indicator to create</param>
85
/// <param name="name">The name of the new indicator</param>
86
/// <param name="period">The smoothing period</param>
87
/// <returns>A new indicator that matches the MovingAverageType</returns>
88
public
static
IndicatorBase<IndicatorDataPoint>
AsIndicator
(
this
MovingAverageType
movingAverageType,
string
name,
int
period)
89
{
90
switch
(movingAverageType)
91
{
92
case
MovingAverageType
.Simple:
93
return
new
SimpleMovingAverage
(name, period);
94
95
case
MovingAverageType
.Exponential:
96
return
new
ExponentialMovingAverage
(name, period);
97
98
case
MovingAverageType
.Wilders:
99
return
new
WilderMovingAverage
(name, period);
100
101
case
MovingAverageType
.LinearWeightedMovingAverage:
102
return
new
LinearWeightedMovingAverage
(name, period);
103
104
case
MovingAverageType
.DoubleExponential:
105
return
new
DoubleExponentialMovingAverage
(name, period);
106
107
case
MovingAverageType
.TripleExponential:
108
return
new
TripleExponentialMovingAverage
(name, period);
109
110
case
MovingAverageType
.Triangular:
111
return
new
TriangularMovingAverage
(name, period);
112
113
case
MovingAverageType
.T3:
114
return
new
T3MovingAverage
(name, period);
115
116
case
MovingAverageType
.Kama:
117
return
new
KaufmanAdaptiveMovingAverage
(name, period);
118
119
case
MovingAverageType
.Hull:
120
return
new
HullMovingAverage
(name, period);
121
122
case
MovingAverageType
.Alma:
123
return
new
ArnaudLegouxMovingAverage
(name, period);
124
125
case
MovingAverageType
.Zlema:
126
return
new
ZeroLagExponentialMovingAverage
(name, period);
127
128
case
MovingAverageType
.MGD:
129
return
new
McGinleyDynamic
(name, period);
130
131
default
:
132
throw
new
ArgumentOutOfRangeException(nameof(movingAverageType));
133
}
134
}
135
}
136
}
Indicators
MovingAverageTypeExtensions.cs
Generated by
1.8.17