-
Notifications
You must be signed in to change notification settings - Fork 346
/
Envelops.cs
51 lines (42 loc) · 1.78 KB
/
Envelops.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
using System;
using System.Collections.Generic;
using System.Drawing;
using OsEngine.Entity;
using OsEngine.Indicators;
namespace CustomIndicators.Scripts
{
public class Envelops : 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.Green, IndicatorChartPaintType.Line, false);
_seriesDown = CreateSeries("Down line", Color.Green, 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] = Math.Round(valueSma + valueSma * _deviation.ValueDecimal / 100, 6);
_seriesDown.Values[index] = Math.Round(valueSma - valueSma * _deviation.ValueDecimal / 100, 6);
}
}
}