Lean  $LEAN_TAG$
PercentagePriceOscillator.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 
17 {
18  /// <summary>
19  /// This indicator computes the Percentage Price Oscillator (PPO)
20  /// The Percentage Price Oscillator is calculated using the following formula:
21  /// PPO[i] = 100 * (FastMA[i] - SlowMA[i]) / SlowMA[i]
22  /// </summary>
24  {
25  /// <summary>
26  /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified name and parameters.
27  /// </summary>
28  /// <param name="name">The name of this indicator</param>
29  /// <param name="fastPeriod">The fast moving average period</param>
30  /// <param name="slowPeriod">The slow moving average period</param>
31  /// <param name="movingAverageType">The type of moving average to use</param>
32  public PercentagePriceOscillator(string name, int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
33  : base(name, fastPeriod, slowPeriod, movingAverageType)
34  {
35  }
36 
37  /// <summary>
38  /// Initializes a new instance of the <see cref="PercentagePriceOscillator"/> class using the specified parameters.
39  /// </summary>
40  /// <param name="fastPeriod">The fast moving average period</param>
41  /// <param name="slowPeriod">The slow moving average period</param>
42  /// <param name="movingAverageType">The type of moving average to use</param>
43  public PercentagePriceOscillator(int fastPeriod, int slowPeriod, MovingAverageType movingAverageType = MovingAverageType.Simple)
44  : this($"PPO({fastPeriod},{slowPeriod})", fastPeriod, slowPeriod, movingAverageType)
45  {
46  }
47 
48  /// <summary>
49  /// Computes the next value of this indicator from the given state
50  /// </summary>
51  /// <param name="input">The input given to the indicator</param>
52  /// <returns>A new value for this indicator</returns>
53  protected override decimal ComputeNextValue(IndicatorDataPoint input)
54  {
55  var value = base.ComputeNextValue(input);
56 
57  return Slow != 0 ? 100 * value / Slow.Current.Value : 0m;
58  }
59  }
60 }