Lean  $LEAN_TAG$
InternalBarStrength.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 
19 {
20  /// <summary>
21  /// The InternalBarStrenght indicator is a measure of the relative position of a period's closing price
22  /// to the same period's high and low.
23  /// The IBS can be interpreted to predict a bullish signal when displaying a low value and a bearish signal when presenting a high value.
24  /// </summary>
26  {
27 
28  /// <summary>
29  /// Gets a flag indicating when this indicator is ready and fully initialized
30  /// </summary>
31  public override bool IsReady => Samples > 0;
32 
33  /// <summary>
34  /// Required period, in data points, for the indicator to be ready and fully initialized.
35  /// </summary>
36  public int WarmUpPeriod => 1;
37 
38  /// <summary>
39  /// Creates a new InternalBarStrenght indicator using the specified period and moving average type
40  /// </summary>
41  /// <param name="name">The name of this indicator</param>
42  public InternalBarStrength(string name)
43  : base(name)
44  {
45  }
46 
47  /// <summary>
48  /// Creates a new InternalBarStrenght indicator using the specified period and moving average type
49  /// </summary>
51  : this($"IBS()")
52  {
53  }
54 
55  /// <summary>
56  /// Computes the next value of this indicator from the given state
57  /// </summary>
58  /// <param name="input">The input given to the indicator</param>
59  /// <returns>A new value for this indicator</returns>
60  protected override decimal ComputeNextValue(IBaseDataBar input)
61  {
62  if (input.High == input.Low)
63  {
64  return 0.5m;
65  }
66  else
67  {
68  return (input.Close - input.Low) / (input.High - input.Low);
69  }
70  }
71  }
72 }