-
Notifications
You must be signed in to change notification settings - Fork 2
/
ATR.cs
28 lines (23 loc) · 910 Bytes
/
ATR.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
using System;
namespace PA.Trading.UAPI
{
public class ATRCalculator
{
public static double[] Calculate(int period, UCandle[] timeSeries)
{
var temp = new double[timeSeries.Length];
temp[0] = timeSeries[0].HighPrice - timeSeries[0].LowPrice;
for (var i = 1; i < timeSeries.Length; i++)
{
var diff1 = Math.Abs(timeSeries[i].HighPrice - timeSeries[i - 1].ClosePrice);
var diff2 = Math.Abs(timeSeries[i].LowPrice - timeSeries[i - 1].ClosePrice);
var diff3 = timeSeries[i].HighPrice - timeSeries[i].LowPrice;
var max = Math.Max(diff1, diff3);
// var max = diff1 > diff2 ? diff1 : diff2;
temp[i] = Math.Max(max, diff2); ;
}
var atr = RMACalculator.Calculate(temp, period);
return atr;
}
}
}