-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae02c7e
commit 81ab492
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
06 LEAN Engine/02 Contributions/03 Indicators/10 Moving Average.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<p>Moving average is a special type of indicator that smoothes out the fluctuations in a security's price or market data. It calculates the average value of a security's price over a specified period with a special smoothing function, helping traders to identify denoised trend.</p> | ||
|
||
<p>Moving averages can also be used in conjunction with other technical indicators to make more informed trading decisions and identify potential support or resistance levels in the market. Lean has extra abstraction interface for indicators to implement a specific type of moving average. Therefore, if you are contributing a moving average indicator, additional steps are required:</p> | ||
<ol> | ||
<li>Provide a new <code>enum</code> in <a href="https://github.com/QuantConnect/Lean/blob/master/Indicators/MovingAverageType.cs">MovingAverageType.cs</a></li> | ||
<div class="section-example-container"> | ||
<pre class="csharp">namespace QuantConnect.Indicators | ||
{ | ||
public enum MovingAverageType | ||
{ | ||
... | ||
/// <summary> | ||
/// Description of the custom moving average indicator (<the next enum number>) | ||
/// </summary> | ||
<CustomMovingAverageEnum>, | ||
} | ||
}</pre> | ||
</div> | ||
|
||
<li>Add a new case of your custom moving average indicator in each method of <a href="https://github.com/QuantConnect/Lean/blob/master/Indicators/MovingAverageTypeExtensions.cs">MovingAverageTypeExtensions.cs</a></li> | ||
<div class="section-example-container"> | ||
<pre class="csharp">namespace QuantConnect.Indicators | ||
{ | ||
public static class MovingAverageTypeExtensions | ||
{ | ||
public static IndicatorBase<IndicatorDataPoint> AsIndicator(this MovingAverageType movingAverageType, int period) | ||
{ | ||
switch (movingAverageType) | ||
{ | ||
... | ||
case MovingAverageType.CustomMovingAverageEnum: | ||
return new CustomMovingAverage(period); | ||
} | ||
} | ||
|
||
public static IndicatorBase<IndicatorDataPoint> AsIndicator(this MovingAverageType movingAverageType, string name, int period) | ||
{ | ||
switch (movingAverageType) | ||
{ | ||
... | ||
case MovingAverageType.CustomMovingAverageEnum: | ||
return new CustomMovingAverage(name, period); | ||
} | ||
} | ||
} | ||
}</pre> | ||
</div> | ||
|
||
<li>Add a new test case of your custom moving average indicator in <a href="https://github.com/QuantConnect/Lean/blob/master/Tests/Indicators/MovingAverageTypeExtensionsTests.cs">MovingAverageTypeExtensionsTests.cs</a> to assert the indicator being instantiated correctly through the abstraction method.</li> | ||
<div class="section-example-container"> | ||
<pre class="csharp">namespace QuantConnect.Tests.Indicators | ||
{ | ||
[TestFixture] | ||
public class MovingAverageTypeExtensionsTests | ||
{ | ||
[Test] | ||
public void CreatesCorrectAveragingIndicator() | ||
{ | ||
... | ||
var indicator = MovingAverageType.CustomMovingAverageEnum.AsIndicator(1); | ||
Assert.IsInstanceOf(typeof(CustomMovingAverage), indicator); | ||
... | ||
string name = string.Empty; | ||
... | ||
indicator = MovingAverageType.CustomMovingAverageEnum.AsIndicator(name, 1); | ||
Assert.IsInstanceOf(typeof(CustomMovingAverage), indicator); | ||
} | ||
} | ||
}</pre> | ||
</div> | ||
</ol> |