Logical Predicates |
LogicalAnd - Generates signal when both input values are in signaled state(equal to 1.0).
LogicalAndNot - Generates signal when first input value is in signaled state(equal to 1.0) while second input value is in not signal state(equal to 0.0).
LogicalNot - Generates signal when the input value is not in signal state(equal to 0.0).
LogicalOr - Generates signal when at least one of the input values is in signaled state(equal to 1.0).
LogicalOrNot - Generates signal when either first input value in signaled state(equal to 1.0) either second input value in not signaled state(equal to 0.0).
LogicalXor - Generates signal when only one of input values are in signal state(equal to 1.0).
LogicalXorNot - Generates signal when input logical values has equal state(both signaled or not signaled).
These predicates can be used in a strategy with the following constructors without any input parameters:
The value of the LogicalNot predicate is updated by simple prototype of method Add():
The values of the rest predicates are updated by two series prototype of method Add():
Use
properties to get the current value.
Here is the example of LogicalAndNot predicate. For the first series, IsGreater predicate with level of 243.5 is used; for the second series, IsDropped with period 30 and drop 0.5% is used. IsGreater and IsDropped predicates are calculated for Apple Inc. stock price(Bar close price).
1public partial class InstrumentExecutor : InstrumentExecutorBase 2{ 3- #region LocalVariables 4 5 //Is Greater indicator 6 IsGreater isGreater; 7 //Is Gained indicator 8 IsDropped isDropped; 9 //Logical And Not indicator 10 LogicalAndNot andNot; 11 //chart lines 12 Line isGreaterLine, isDroppedLine, andNotLine; 13 14 #endregion 15 16- #region Events 17 public override void OnInit() 18 { 19 //init indicators 20 isGreater = new IsGreater(243.5); 21 isDropped = new IsDropped(30, 0.5); 22 andNot = new LogicalAndNot(); 23 24 //init lines 25 isGreaterLine = Charting.CreateLine("IsGreater", "", Symbol, Pens.Black, LineStyle.Line, Charting.PriceChart, 2); 26 27 isDroppedLine = Charting.CreateLine("IsDropped", "", Symbol, Pens.Blue, LineStyle.Line, Charting.PriceChart, 3); 28 29 andNotLine = Charting.CreateLine("LogicalAndNot", "", Symbol, Pens.Red, LineStyle.Line, Charting.PriceChart, 4); 30 } 31 32 public override void OnBarClose() 33 { 34 //update value of the indicators 35 isGreater.Add(CurrentPrice, CurrentTime); 36 isDropped.Add(CurrentPrice, CurrentTime); 37 andNot.Add(isGreater.Greater, isDropped.Dropped, CurrentTime); 38 //chart 39 isGreaterLine.Draw(CurrentTime,isGreater.Greater); 40 isDroppedLine.Draw(CurrentTime,isDropped.Dropped); 41 andNotLine.Draw(CurrentTime, andNot.AndNot); 42 } 43 #endregion 44}