forked from tslab-hub/handlers
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTradeStatisticsUpperEdgeHandler.cs
More file actions
49 lines (43 loc) · 2.03 KB
/
TradeStatisticsUpperEdgeHandler.cs
File metadata and controls
49 lines (43 loc) · 2.03 KB
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
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using TSLab.Script.Handlers.Options;
namespace TSLab.Script.Handlers
{
// TODO: английское описание
[HandlerCategory(HandlerCategories.ClusterAnalysis)]
[HelperName("Trade Statistics Upper Edge", Language = Constants.En)]
[HelperName("Верхний уровень торговой статистики", Language = Constants.Ru)]
[InputsCount(1)]
[Input(0, TemplateTypes.TRADE_STATISTICS | TemplateTypes.LAST_CONTRACTS_TRADE_STATISTICS)]
[OutputsCount(1)]
[OutputType(TemplateTypes.DOUBLE)]
[Description("Блок 'Верхний уровень торговой статистики' позволяет установить в процентном значении отсечки данных по верхнему уровню. Данный блок соединяется с блоком 'Торговая статистика'.")]
[HelperDescription("", Constants.En)]
public sealed class TradeStatisticsUpperEdgeHandler : TradeStatisticsEdgeHandler
{
protected override double GetFirstPrice(IReadOnlyList<ITradeHistogramBar> bars)
{
return bars.Last().MaxPrice;
}
protected override double GetLastPrice(IReadOnlyList<ITradeHistogramBar> bars)
{
return bars.First().MinPrice;
}
protected override IEnumerable<ITradeHistogramBar> GetOrderedBars(IEnumerable<ITradeHistogramBar> bars)
{
return bars.Reverse();
}
protected override double GetPrice(ITradeHistogramBar bar, double coefficient)
{
double result;
if (coefficient < 0.5)
result = bar.MaxPrice + (bar.AveragePrice - bar.MaxPrice) * coefficient * 2;
else if (coefficient > 0.5)
result = bar.AveragePrice + (bar.MinPrice - bar.AveragePrice) * (coefficient - 0.5) * 2;
else
result = bar.AveragePrice;
return result;
}
}
}