Above Below |
IsAbove(IsBelow) predicate receives two input lines and generates a signal if the first line is strictly above(strictly below) the second one during the specified time interval. By default the interval equals 1.
These predicates can be used in a strategy with the following constructors:
creates new instance of the IsAbove / IsBelow predicate with default period equal to 1.
creates new instance of the IsAbove/ IsBelow predicate with point window.
creates new instance of the IsAbove / IsBelow predicate with time window.
The value of the indicators is updated by two series type of method Add():
Use
properties to get the current value.
For the first series, Sma with the period of 20 of the Apple Inc. stock price (bar close price) is used, whereas for the second series the price itself is used. The predicate period in this example is set to 10.
1public partial class InstrumentExecutor : InstrumentExecutorBase 2{ 3- #region LocalVariables 4 5 //Sma indicator 6 Sma sma; 7 //Is Above indicator 8 IsAbove isAbove; 9 //chart lines 10 Line isAboveLine, smaLine; 11 12 #endregion 13 14- #region Events 15 public override void OnInit() 16 { 17 //init indicators 18 sma = new Sma(20); 19 isAbove = new IsAbove(10); 20 21 //init lines 22 smaLine = Charting.CreateLine("Sma", "", Symbol, Pens.Blue, LineStyle.Line, Charting.PriceChart, 1); 23 24 isAboveLine = Charting.CreateLine("IsAbove", "", 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 isAbove.Add(sma.SMA, CurrentPrice, CurrentTime); 32 33 //get values and chart 34 smaLine.Draw(CurrentTime, sma.SMA); 35 isAboveLine.Draw(CurrentTime, isAbove.Above); 36 } 37 #endregion