Lean  $LEAN_TAG$
CandleSettings.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.Collections.Generic;
17 
19 {
20  /// <summary>
21  /// Candle settings for all candlestick patterns
22  /// </summary>
23  public static class CandleSettings
24  {
25  /// <summary>
26  /// Default settings for all candle setting types
27  /// </summary>
28  private static readonly Dictionary<CandleSettingType, CandleSetting> DefaultSettings = new Dictionary<CandleSettingType, CandleSetting>
29  {
30  { CandleSettingType.BodyLong, new CandleSetting(CandleRangeType.RealBody, 10, 1m) },
31  { CandleSettingType.BodyVeryLong, new CandleSetting(CandleRangeType.RealBody, 10, 3m) },
32  { CandleSettingType.BodyShort, new CandleSetting(CandleRangeType.RealBody, 10, 1m) },
33  { CandleSettingType.BodyDoji, new CandleSetting(CandleRangeType.HighLow, 10, 0.1m) },
34  { CandleSettingType.ShadowLong, new CandleSetting(CandleRangeType.RealBody, 0, 1m) },
35  { CandleSettingType.ShadowVeryLong, new CandleSetting(CandleRangeType.RealBody, 0, 2m) },
36  { CandleSettingType.ShadowShort, new CandleSetting(CandleRangeType.Shadows, 10, 1m) },
37  { CandleSettingType.ShadowVeryShort, new CandleSetting(CandleRangeType.HighLow, 10, 0.1m) },
38  { CandleSettingType.Near, new CandleSetting(CandleRangeType.HighLow, 5, 0.2m) },
39  { CandleSettingType.Far, new CandleSetting(CandleRangeType.HighLow, 5, 0.6m) },
40  { CandleSettingType.Equal, new CandleSetting(CandleRangeType.HighLow, 5, 0.05m) }
41  };
42 
43  /// <summary>
44  /// Returns the candle setting for the requested type
45  /// </summary>
46  /// <param name="type">The candle setting type</param>
47  public static CandleSetting Get(CandleSettingType type)
48  {
49  CandleSetting setting;
50  DefaultSettings.TryGetValue(type, out setting);
51  return setting;
52  }
53 
54  /// <summary>
55  /// Changes the default candle setting for the requested type
56  /// </summary>
57  /// <param name="type">The candle setting type</param>
58  /// <param name="setting">The candle setting</param>
59  public static void Set(CandleSettingType type, CandleSetting setting)
60  {
61  DefaultSettings[type] = setting;
62  }
63  }
64 
65  /// <summary>
66  /// Represents a candle setting
67  /// </summary>
68  public class CandleSetting
69  {
70  /// <summary>
71  /// The candle range type
72  /// </summary>
74  {
75  get;
76  private set;
77  }
78 
79  /// <summary>
80  /// The number of previous candles to average
81  /// </summary>
82  public int AveragePeriod
83  {
84  get;
85  private set;
86  }
87 
88  /// <summary>
89  /// A multiplier to calculate candle ranges
90  /// </summary>
91  public decimal Factor
92  {
93  get;
94  private set;
95  }
96 
97  /// <summary>
98  /// Creates an instance of the <see cref="CandleSetting"/> class
99  /// </summary>
100  /// <param name="rangeType">The range type</param>
101  /// <param name="averagePeriod">The average period</param>
102  /// <param name="factor">The factor</param>
103  public CandleSetting(CandleRangeType rangeType, int averagePeriod, decimal factor)
104  {
105  RangeType = rangeType;
106  AveragePeriod = averagePeriod;
107  Factor = factor;
108  }
109  }
110 }