Approaching From Above Approaching From Below |
IsApproachingAbove(IsApproachingBelow) predicate receives one input line and generates a signal if the value of this line decreases(increases), remaining higher(lower) of the defined level. The smallest value of the interval that the predicate supports equals 2.
These predicates can be used in a strategy with the following constructors:
creates new instance of the IsApproachingAbove / IsApproachingBelow predicate with default period equal to 14 and zero level.
IsApproachingAbove(Int32, Double)
IsApproachingBelow(Int32, Double)
creates new instance of the IsApproachingAbove / IsApproachingBelow predicate with point window.
IsApproachingAbove(TimeSpan, Double)
IsApproachingBelow(TimeSpan, Double)
creates new instance of the IsApproachingAbove / IsApproachingBelow predicate with time window.
The value of the indicators is updated by simple prototype of method Add():
Use
properties to get the current value.
For the input series, Apple Inc. stock price(bar close price) is used, the defined level equals 236. The period is set to 5.
1public partial class InstrumentExecutor : InstrumentExecutorBase 2{ 3- #region LocalVariables 4 5 //Is Approaching Above indicator 6 IsApproachingAbove isAppAbove; 7 //chart line 8 Line isAppAboveLine; 9 10 #endregion 11 12- #region Events 13 public override void OnInit() 14 { 15 //init indicator 16 isAppAbove = new IsApproachingAbove(5, 236); 17 //init line 18 isAppAboveLine = Charting.CreateLine("IsAbove", "", Symbol, Pens.Black, LineStyle.Line, Charting.PriceChart, 2); 19 } 20 21 public override void OnBarClose() 22 { 23 //update value of the indicator 24 isAppAbove.Add(CurrentPrice, CurrentTime); 25 //chart 26 isAppAboveLine.Draw(CurrentTime,isAppAbove.ApproachingAbove); 27 } 28 #endregion 29}