Click or drag to resize

Equal

IsEqual predicate generates a signal when the values of two given time series are equal with given precision during the given interval.

Implementation and Usage

This predicate can be used in a strategy with the following constructors:

IsEqual - Creates new instance of the IsEqual predicate with default period equal to 1 and precision equal to 1.0E-6.

IsEqual(Int32, Double) - Creates new instance of the IsEqual predicate with point window.

IsEqual(TimeSpan, Double) - Creates new instance of the IsEqual predicate with time window.

The value of the indicator is updated by two series type of method Add():

Add(Double, Double)

Add(Double, Double, DateTime)

Use

Equal - property to get the current value.

Example

For the first series, Sma with period of 10 of Apple Inc. stock price(Bar close price) is used, for the second series Sma with period of 30. Predicate period is set to 2 and the distance equals 0.3.

C#
 1public partial class InstrumentExecutor : InstrumentExecutorBase
 2{
 3-    #region LocalVariables
 4 
 5     //Sma indicators
 6     Sma sma1, sma2;
 7     //Is Equal indicator
 8     IsEqual isEqual;
 9     //chart lines
10     Line isEqualLine, smaLine1, smaLine2;
11 
12     #endregion
13
14-    #region Events
15     public override void OnInit()
16     {
17         //init indicators
18         sma1 = new Sma(10);
19         sma2 = new Sma(30);
20         isEqual = new IsEqual(1, 0.3);
21 
22         //init lines
23         smaLine1 = Charting.CreateLine("Sma1", "", Symbol, Pens.Blue, LineStyle.Line, Charting.PriceChart, 1);
24 
25         smaLine2 = Charting.CreateLine("Sma2", "", Symbol, Pens.Black, LineStyle.Line, Charting.PriceChart, 1);
26 
27         isEqualLine = Charting.CreateLine("IsEqual", "", Symbol, Pens.Black, LineStyle.Line, Charting.PriceChart, 2);
28     }
29 
30     public override void OnBarClose()
31     {
32         //update values of the indicators
33         sma1.Add(CurrentPrice, CurrentTime);
34         sma2.Add(CurrentPrice, CurrentTime);
35         isEqual.Add(sma1.SMA, sma2.SMA, CurrentTime);
36 
37         //get values and chart
38         smaLine1.Draw(CurrentTime, sma1.SMA);
39         smaLine2.Draw(CurrentTime, sma2.SMA);
40         isEqualLine.Draw(CurrentTime, isEqual.Equal);
41     }
42     #endregion
43}
Chart

Equal 001