Click or drag to resize

More Listeners

More Listeners

Besides DistributionListener there are four more listeners in FinancialAnalysis library: StatisticsListener, MaximizerListener, MinimizerListener and SummatorListener.  

StatisticsListener – duplicates DistributionListener functionality except for some procedures that require more heavyweight operations with data.

MaximizerListener - finds maxima of the data recorded in the structure.

MinimizerListener - finds minima of the data recorded in the structure.

SummatorListener – calculates sums of the data recorded in the structure.

Consider an example showing how to calculate statistics for Atr indicator using listeners described above:

C#
 1using System;
 2using FinAnalysis.Base;
 3using FinAnalysis.TA;
 4using FinAnalysis.Listeners;
 5
 6//Indicator:
 7public Atr atr;
 8
 9//Listeners:
10StatisticsListener statistics;
11MinimizerListener minimizer;
12MaximizerListener maximizer;
13SummatorListener summator;
14
15//Init indicator:
16atr = new Atr(30);
17
18//Define queue length
19atr.HistoryCapacity = 30;
20
21//Init listeners
22statistics = new StatisticsListener();
23minimizer = new MinimizerListener();
24maximizer = new MaximizerListener();
25summator = new SummatorListener();
26
27//Connect listeners to the data queue
28atr.SetQueueListener(statistics);
29atr.SetQueueListener(minimizer);
30atr.SetQueueListener(maximizer);
31atr.SetQueueListener(summator);
32
33private OnBarClose(Bar bar)
34{
35        //modify indicator
36        atr.Add(bar.Open, bar.High, bar.Low, bar.Close, bar.Volume);
37
38        //get statistics from listeners:
39        Console.WriteLine(statistics.ExpectedValue.ToString());
40
41        Console.WriteLine(minimizer.Value.ToString());
42
43        Console.WriteLine(maximizer.Value.ToString());
44
45        Console.WriteLine(summator.Value.ToString());
46}