Cross Up Cross Down |
Predicate IsCrossUp (IsCrossDown) receives two input lines and generates a signal if during the defined period the first line crosses the second upward(downward) only once. The lowest value of the period equals 1, and this value is usually the most frequently used, since in this case, the signal is generated at the moment of crossing.
These predicates can be used in a strategy with the following constructors:
creates new instance of the IsCrossUp / IsCrossDown predicate with default period equal to 1
creates new instance of the IsCrossUp / IsCrossDown predicate with point window.
creates new instance of the IsCrossUp / IsCrossDown 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 period of 10 of Apple Inc. stock price(Bar close price) is used, for the second series the price itself is used. Predicate period is set to 1.
1public partial class InstrumentExecutor : InstrumentExecutorBase 2{ 3- #region LocalVariables 4 5 //Sma indicator 6 Sma sma; 7 //Is Cross Up indicator 8 IsCrossUp isCrossUp; 9 //chart lines 10 Line isCrossUpLine, smaLine; 11 12 #endregion 13 14- #region Events 15 public override void OnInit() 16 { 17 //init indicators 18 sma = new Sma(10); 19 isCrossUp = new IsCrossUp(); 20 21 //init lines 22 smaLine = Charting.CreateLine("Sma", "", Symbol, Pens.Blue, LineStyle.Line, Charting.PriceChart, 1); 23 24 isCrossUpLine = Charting.CreateLine("IsCrossUp", "", 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 isCrossUp.Add(CurrentPrice, sma.SMA, CurrentTime); 32 33 //get values and chart 34 smaLine.Draw(CurrentTime, sma.SMA); 35 isCrossUpLine.Draw(CurrentTime, isCrossUp.CrossUp); 36 } 37 #endregion 38}