Converging Diverging |
IsConverging (IsDiverging) predicate receives two input lines and generates a signal if during the specified period these lines converge(diverge). Note that the predicate IsApproachingAbove(IsApproachingBelow) can be easily constructed using the predicates IsConverging (IsDiverging), IsAbove(IsBelow):
IsApproachingAbove(TimeSeries, Value) = IsConverging(TimeSeries, Value) and IsAbove(TimeSeries, Value)
These predicates can be used in a strategy with the following constructors:
creates new instance of the IsConverging / IsDiverging predicate with default period equal to 14.
creates new instance of the IsConverging / IsDiverging predicate with point window.
creates new instance of the IsConverging / IsDiverging 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, Apple Inc. stock price(bar close price) is used; for the second series, Sma with the period of 10 is used. The predicates period is set to 5.
1public partial class InstrumentExecutor : InstrumentExecutorBase 2{ 3- #region LocalVariables 4 5 //Sma indicator 6 Sma sma; 7 //Is Converging indicator 8 IsConverging isConverging; 9 //chart lines 10 Line isConvergingLine, smaLine; 11 12 #endregion 13 14- #region Events 15 public override void OnInit() 16 { 17 //init indicators 18 sma = new Sma(20); 19 isConverging = new IsConverging(5); 20 21 //init lines 22 smaLine = Charting.CreateLine("Sma", "", Symbol, Pens.Blue, LineStyle.Line, Charting.PriceChart, 1); 23 24 isConvergingLine = Charting.CreateLine("IsConverging", "", 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 isConverging.Add(CurrentPrice, sma.SMA, CurrentTime); 32 33 //get values and chart 34 smaLine.Draw(CurrentTime, sma.SMA); 35 isConvergingLine.Draw(CurrentTime, isConverging.Converging); 36 } 37 #endregion 38}