-
Notifications
You must be signed in to change notification settings - Fork 344
/
SmaChannel.cs
57 lines (47 loc) · 1.94 KB
/
SmaChannel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using OsEngine.Entity;
using OsEngine.Indicators;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace OsEngine.Charts.CandleChart.Indicators.Indicator
{
// [IndicatorAttribute("SmaChannel")]
internal class SmaChannel : Aindicator
{
private IndicatorParameterInt _lenght;
private IndicatorParameterDecimal _deviation;
private IndicatorDataSeries _seriesUp;
private IndicatorDataSeries _seriesDown;
private IndicatorDataSeries _seriesCenter;
private Aindicator _sma;
public override void OnStateChange(IndicatorState state)
{
if (state == IndicatorState.Configure)
{
_lenght = CreateParameterInt("Length", 21);
_deviation = CreateParameterDecimal("Deviation", 2);
_seriesUp = CreateSeries("Up line", Color.Green, IndicatorChartPaintType.Line, true);
_seriesCenter = CreateSeries("Centre line", Color.LightBlue, IndicatorChartPaintType.Line, false);
_seriesDown = CreateSeries("Down line", Color.Red, IndicatorChartPaintType.Line, true);
_sma = IndicatorsFactory.CreateIndicatorByName("Sma", Name + "Sma", false);
_sma.Parameters[0].Bind(_lenght);
ProcessIndicator("Central SMA", _sma);
}
}
public override void OnProcess(List<Candle> candles, int index)
{
if (index <= _lenght.ValueInt)
{
return;
}
decimal valueSma = _sma.DataSeries[0].Values[index];
_seriesCenter.Values[index] = valueSma;
_seriesUp.Values[index] = valueSma + CalcDeviation(valueSma);
_seriesDown.Values[index] = valueSma - CalcDeviation(valueSma);
}
private decimal CalcDeviation(decimal valueSma)
{
return Math.Round(valueSma * _deviation.ValueDecimal / 100, 6);
}
}
}