-
Notifications
You must be signed in to change notification settings - Fork 344
/
AccumulationDistribution.cs
44 lines (37 loc) · 1.17 KB
/
AccumulationDistribution.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
using System;
using System.Collections.Generic;
using System.Drawing;
using OsEngine.Entity;
using OsEngine.Indicators;
namespace CustomIndicators.Scripts
{
public class AccumulationDistribution : Aindicator
{
private IndicatorDataSeries _series;
public override void OnStateChange(IndicatorState state)
{
if (state == IndicatorState.Configure)
{
_series = CreateSeries("A D", Color.Aqua, IndicatorChartPaintType.Line, true);
}
}
public override void OnProcess(List<Candle> candles, int index)
{
_series.Values[index] = GetValue(candles, index);
}
private decimal GetValue(List<Candle> candles, int index)
{
if (index == 0 ||
candles.Count <= index)
{
return 0;
}
Candle c = candles[index];
if ((c.High - c.Low) == 0)
{
return _series.Values[index - 1];
}
return Math.Round(c.Volume * ((c.Close - c.Low) - (c.High - c.Close)) / (c.High - c.Low) + _series.Values[index - 1], 0);
}
}
}