Click or drag to resize

Further Properties And Methods

Methods

Here follows the description of some other properties and methods that can be also useful when working with indicators.

Method

Description

methodSetOnPopDelegate(HistoryDataQueueTOnPopDelegate)

Sets OnPop method which is called every time when some element is added to the queue.

methodSetOnPushDelegate(HistoryDataQueueTOnPushDelegate)

Sets OnPush method which is called every time when some element is removed from the queue.

methodSetQueueListener(IDataQueueListenerT)

Sets listener to queue capacity. Queue will call OnPop method every time when queue drops some element and OnPush method when queue stores element. Do not use listener with single element queue. Queue supports any number of listeners.

listener - class that implements IDataQueueListenerT interface like SummatorListener, MaximizerListener, MinimizerListener, DistributionListener, etc.

System.InvalidOperationException is thrown when you are trying to set listener on single element queue.

methodGetIndexByTime(DateTime)

Gets offset index of element by element time. If there is no element with such time it returns latest element with time smaller than specified. If no valid index can be found the indicator returns -1.

methodGetTimeByIndex(Int32)

Returns time associated with specified point.

index - get time which was stored with element "index" steps ago.

methodClone

Makes full copy of this instance.

methodCopyTo(Object)

Gets internal state from source object.

A number of indicators support offline computation. Offline computation uses all data for period simultaneously. In some cases can be faster and/or use less memory than online (step-by-step) computation. Note: Indicator cannot be used before and after calling this method.

Method

Description

methodOfflineComputation(Double, T)

methodOfflineComputation(Double, Double, T)

A method parameters are array of values to add and array of new values of the indicator.

methodOfflineComputation(Double, DateTime, T)

methodOfflineComputation(Double, Double, DateTime, T)

A method parameters are array of values to add, DateTime array of corresponding time values, and array of new values of the indicator.

The indicators supporting offline computation:

Properties

Property

Description

PropertyFirstDateTime

Gets first (oldest) data element DateTime stored in container. Note that if there are no elements in queue it returns DafaultDateTime.

PropertyLastDateTime

Gets last data element DateTime stored in container. Note that if there are no elements in queue it returns DafaultDateTime.

PropertyIndicatorNeedDateTime

Equals true if user has to specify DateTime.

PropertyPrevious

Gets previous data element stored in container. Note that if there are no elements in queue it returns DafaultValue. This property is available for every indicator regardless of its capacity or type of history storage (time or point based).

PropertyValueDelayPointPeriod

Sets delay (in points) for indicator's value.

PropertyValueDelayTimePeriod

Sets delay (in TimeSpan) for indicator's value.

PropertyTradeSignal

Trade signal of the indicator.

PropertyTradeSignalType

Characterizes indicator's trade signal values range and meaning.

PropertyValidationStrategy

Indicates what we must do with invalid input values.

Code Sample

Here is the example of SetOnPopDelegate and SetOnPushDelegate usage:

C#
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using FinAnalysis.Base;
 6using FinAnalysis.TA;
 7
 8namespace ListenersSample
 9{
10    public class EmaListener : IDataQueueListener<double>
11    {
12        public void OnPop(ref double data, DateTime time)
13        {
14            Console.WriteLine("Listener.OnPop()");
15        }
16
17        public void OnPush(ref double data, DateTime time)
18        {
19            Console.WriteLine("Listener.OnPush()");
20        }
21    }
22
23    class ListenersSample
24    {
25        const int Steps = 0xFF;
26
27        static void OnPop(ref double data, DateTime time)
28        {
29            Console.WriteLine("OnPop()");
30        }
31
32        static void OnPush(ref double data, DateTime time)
33        {
34            Console.WriteLine("OnPush()");
35        }
36
37        static void Main(string[] args)
38        {
39            Random r = new Random();
40
41            Ema ema = new Ema(0xF);
42
43            ema.SetOnPopDelegate(OnPop);
44            ema.SetOnPushDelegate(OnPush);
45
46            for (int i = 0; i < Steps; ++i)
47            {
48                ema.Add(r.NextDouble());
49            }
50
51            EmaListener listener = new EmaListener();
52
53            ema.SetQueueListener(listener);
54
55            for (int i = 0; i < Steps; ++i)
56            {
57                ema.Add(r.NextDouble());
58            }
59
60        }
61    }
62}