-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTripleSmoothedExponentialMovingAverage.cs
55 lines (51 loc) · 1.83 KB
/
TripleSmoothedExponentialMovingAverage.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
//==============================================================================
// Copyright (c) 2012-2023 Fiats Inc. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt in the solution folder for
// full license information.
// https://www.fiats.asia/
// Fiats Inc. Nakano, Tokyo, Japan
//
namespace Financier;
public static partial class IndicatorExtensions
{
/// <summary>
/// Triple exponentially smoothed moving average (TRIX)
/// <see href="https://en.wikipedia.org/wiki/Trix_(technical_analysis)" />
/// </summary>
/// <param name="source"></param>
/// <param name="period"></param>
/// <returns></returns>
public static IObservable<double> TripleSmoothedExponentialMovingAverage(this IObservable<double> source, int period)
{
return source.ExponentialMovingAverage(period)
.ExponentialMovingAverage(period)
.ExponentialMovingAverage(period)
.Buffer(2, 1)
.Select(values =>
{
return (values[1] - values[0]) / values[0];
});
}
public static IObservable<decimal> TripleSmoothedExponentialMovingAverage(this IObservable<decimal> source, int period)
{
return source.ExponentialMovingAverage(period)
.ExponentialMovingAverage(period)
.ExponentialMovingAverage(period)
.Buffer(2, 1)
.Select(values =>
{
return (values[1] - values[0]) / values[0];
});
}
public static IObservable<float> TripleSmoothedExponentialMovingAverage(this IObservable<float> source, int period)
{
return source.ExponentialMovingAverage(period)
.ExponentialMovingAverage(period)
.ExponentialMovingAverage(period)
.Buffer(2, 1)
.Select(values =>
{
return (values[1] - values[0]) / values[0];
});
}
}