Click or drag to resize

In Interval

IsInInterval predicate generates a signal if all values of the series at the current moment lie in a given interval. Note that this predicate can be composed of IsGreater and IsLess predicates.

Implementation and Usage

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

IsInInterval - Creates new instance of the IsInInterval predicate with default zero value for the left endpoint and 1.0 for the right endpoint of the interval.

IsInInterval(Double, Double) - Creates new instance of the IsInInterval predicate with the given values for endpoints of the interval.

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

Add(Double)

Add(Double, DateTime)

Use

InInterval - property to get the current value.

Example

IsInInterval predicate for Apple Inc. stock price(Bar close price) with interval from 271 to 273.

C#
 1public partial class InstrumentExecutor : InstrumentExecutorBase
 2{
 3-    #region LocalVariables
 4 
 5     //Is In Interval indicator
 6     IsInInterval isInInterval;
 7     //chart line
 8     Line isInIntervalLine;
 9 
10     #endregion
11
12-    #region Events
13     public override void OnInit()
14     {
15         //init indicator
16         isInInterval = new IsInInterval(271, 273);
17         //init line
18         isInIntervalLine = Charting.CreateLine("IsInInterval", "", Symbol, Pens.Black, LineStyle.Line, Charting.PriceChart, 2);
19     }
20 
21     public override void OnBarClose()
22     {
23         //update value of the indicator
24         isInInterval.Add(CurrentPrice, CurrentTime);
25         //chart
26         isInIntervalLine.Draw(CurrentTime,isInInterval.InInterval);
27     }
28     #endregion
29}
Chart

In Interval 001