Click or drag to resize

Near

IsNear predicate receives two input lines and generates a signal if the distance between them does not exceed a predefined value over a certain period(1 by default). The distance between the lines is calculated in relation to their average and expressed in percent(2% by default).

Implementation and Usage

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

IsNear - Creates new instance of the IsNear predicate with default period equal to 1 and deviation level equal to 2.0%.

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

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

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

Add(Double, Double)

Add(Double, Double, DateTime)

Use

Near - property to get the current value.

Example

The predicate IsNear for Apple Inc. stock price(Bar close price) and Sma with period of 10. Period for the predicate was set to 10, distance equals 0.5%:

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

Near 001