Introduction
The “Standard Condition” expression Allows you to compare values with each other in various ways, and return a Boolean (true or false) value based on how the values compare.
For example, you can compare two simple values and determine if they are equal or if one is greater than the other.
You can also determine if a simple value is between two values or if a value is within a certain distance of another value.
You can also compare two time series and determine if one crossed above or below the other.
Standard conditions can be used in any location where a Boolean expression is expected, not just as a condition in the condition expression of a Conditional Trading Logic action, a “Do Once If” action (Quagensia® T Edition only), or a loop action. For instance, you can set the value of a Boolean internal variable to the result of a standard condition or you can pass a standard condition expression into a Boolean input parameter of a Quagensia® Function.
The following types of standard conditions are supported:
- Is Equal To
- Is Not Equal To
- Is Greater Than
- Is Greater Than Or Equal To
- Is Less Than
- Is Less Than Or Equal To
- Is Between (Including The Two Values Entered)
- Is Between (Excluding The Two Values Entered)
- Is Not “Between (Including The Two Values Entered)”
- Is Not “Between (Excluding The Two Values Entered)”
- Is Within X Of Y
- Is Within X% Of Y
- Is Not Within X Of Y
- Is Not Within X% Of Y
- Crossed Above A Time Series
- Crossed Above A Time Series (Both Going Up)
- Crossed Above A Time Series (Both Going Down)
- Crossed Above A Time Series (While Time Series Shown on Left Going Up)
- Crossed Above A Time Series (While Time Series Shown on Left Going Down)
- Crossed Above A Time Series (While Time Series Shown on Right Going Up)
- Crossed Above A Time Series (While Time Series Shown on Right Going Down)
- Crossed Above A Time Series (While Time Series Shown on Left Going Up And Other Going Down)
- Crossed Above A Time Series (While Time Series Shown on Left Going Down And Other Going Up)
- Crossed Above A Fixed Threshold
- Crossed Below A Time Series
- Crossed Below A Time Series (Both Going Down)
- Crossed Below A Time Series (Both Going Up)
- Crossed Below A Time Series (While Time Series Shown on Left Going Down)
- Crossed Below A Time Series (While Time Series Shown on Left Going Up)
- Crossed Below A Time Series (While Time Series Shown on Right Going Down)
- Crossed Below A Time Series (While Time Series Shown on Right Going Up)
- Crossed Below A Time Series (While Time Series Shown on Left Going Down And Other Going Up)
- Crossed Below A Time Series (While Time Series Shown on Left Going Up And Other Going Down)
- Crossed Below A Fixed Threshold
Depending on your edition of Quagensia, the “Conditions” context menu folder that appears whenever you click on a location that expects a Boolean expression will also have an “More Conditions” folder that will allow you to do advanced comparisons such as comparing text on a case-sensitive or case-insensitive basis or comparing numbers in more advanced ways.
You can do If-Then-Else logic at locations where expressions of any of Quagensia N Edition’s many simple data types are allowed that returns one expression if a condition is True and returns another expression if the condition is False.
If you want to do any of the following types of logic in a Quagensia N Edition Strategy without using the functions described in this section, you have to use an actual “Conditional Trading Logic (If-Then-Else)” block:
- Use an Order Quantity of 100 under normal circumstances but use an Order Quantity of 200 when a specific condition or set of conditions is True.
- Draw a blue diamond 1% above the high of the current price bar if one condition or set of conditions is True but draw a red diamond 1% below the low of the current price bar if that condition or set of conditions is False.
- Flatten a position by 2:00 PM on all weekdays except Friday but on Friday flatten a position at 1:00 PM.
Quagensia N Edition includes functions that allow you to do all of the above types of logic without the need for an actual “Conditional Trading Logic (If-Then-Else)” block. When you click on a location where one of Quagensia N Edition’s many simple data types are allowed and navigate to the “Conditions > More Conditions > If True Return X, Else Return Y” context menu subfolder, you will see one or more functions in either the root of that subfolder or in a subfolder of it that return one expression if a condition or set of conditions is True and return another expression if the condition or set of conditions is False. There are many of these functions but you will only see the function or functions that return expressions of the subset of the many simple data types that are allowed at the location you clicked. For instance, if you click on a location that only allows colors, you will only see one of these many functions, which will be named “If True Return One Color Else Return Another Color”, and it will be under the “Conditions > More Conditions > If True Return X, Else Return Y > Advanced Data Types” context menu subfolder. Continuing with this example, if you select the “If True Return One Color Else Return Another Color” function at a location where a color is allowed, you can then set its “Condition To Check” input parameter to a set of conditions that you build, set its “Color Expression To Return If True” input parameter to the color “Blue” or to a color that you create programmatically (which is described more in the next section of these release notes), and set its “Color Expression To Return If False” input parameter to the color “Red” or to a color that you create programmatically.
Note that in the example above, you did not need to use an actual “Conditional Trading Logic (If-Then-Else)” block to use one color if a set of conditions is True but another color if a set of conditions is false.
There are two advantages to using “If True Return X, Else Return Y” functions like we did in the example above at locations where an expression of a given type (like the “Color” type) is allowed:
- You will be able to make your trading logic simpler by using less “Conditional Trading Logic (If-Then-Else)” blocks in the “When Bar Updates” and “Money Management (Protective Stops and Profit Targets)” sections of your Quagensia N Edition Strategies.
- You will be able to use this kind of logic in the “Internal Variables” section of your Quagensia N Edition Strategies, which is impossible using only built-in functions and features of Quagensia N Edition without using these built-in “If True Return X, Else Return Y” functions. Using this kind of logic in the “Internal Variables” section allows you do to things like set an indicator’s plot color to one of two different colors based on the value of an input parameter or set the initial value of internal variable to one of two different values.
Note that Quagensia N Edition supports nesting function calls inside of one another, so you are not limited to returning one of two values based on if a single set of conditions is True or False. For instance, in the example with colors above, if you kept nesting “If True Return One Color Else Return Another Color” function calls in the “Color Expression To Return If True” and “Color Expression To Return If False” input parameters, you could return one of many different colors.
You can do If-Then-Else logic at locations where expressions of Quagensia T Edition’s “Decimal Number”, “Boolean (True or False)”, or “Text” data types are allowed that returns one expression if a condition is True and returns another expression if the condition is False.
If you want to do any of the following types of logic in a Quagensia T Edition Strategy without using the functions described in this section, you have to use an actual “Conditional Trading Logic (If-Then-Else)” block:
- Draw a dot 1% above the high of the current price bar if one condition or set of conditions is True but draw a dot 1% below the low of the current price bar if that condition or set of conditions is False.
- Print text on the chart that reads “Trading Signal” on price bars whose characteristics may warrant a trade but print “X” on price bars whose characteristics do not warrant a trade.
Quagensia T Edition includes functions that allow you to do the above types of logic without the need for an actual “Conditional Trading Logic (If-Then-Else)” block. When you click on a location where expressions of “Decimal Number”, “Boolean (True or False)”, or “Text” data types are allowed and navigate to the “Conditions > More Conditions > IFF (If True Return X, Else Return Y)” context menu subfolder, you will see one or more functions in that subfolder that return one expression if a condition or set of conditions is True and return another expression if the condition or set of conditions is False. There are three of these functions but you will only see the function or functions that return expressions of the subset of the three data types that are allowed at the location you clicked. For instance, if you click on a location that only allows Decimal Numbers, you will only see one of these three functions, which will be named “IFF (Return One Of Two Decimal Expressions Based On Whether A Condition Is True Or False)”. Continuing with this example, if you select the “IFF (Return One Of Two Decimal Expressions Based On Whether A Condition Is True Or False)” function at a location where a Decimal Number is allowed, you can then set its “Condition To Check” input parameter to a set of conditions that you build, set its “Decimal Expression To Return If True” input parameter to a calculation that returns a Decimal Number that is 1% above the high of the current price bar, and set its “Decimal Expression To Return If False” input parameter to a calculation that returns a Decimal Number that is 1% below the low of the current price bar.
Note that in the example above, you did not need to use an actual “Conditional Trading Logic (If-Then-Else)” block to use one Decimal Number if a set of conditions is True but another Decimal Number if a set of conditions is false.
There are two advantages to using “IFF (If True Return X, Else Return Y)” functions like we did in the example above at locations where an expression of a given type (like the “Decimal Number” type) is allowed:
- You will be able to make your trading logic simpler by using less “Conditional Trading Logic (If-Then-Else)” blocks in the “When Bar Updates” section of your Quagensia T Edition Strategies.
- You will be able to use this kind of logic in the “Internal Variables” section of your Quagensia T Edition Strategies, which is impossible using only built-in functions and features of Quagensia T Edition without using these built-in “IFF (If True Return X, Else Return Y)” functions. Using this kind of logic in the “Internal Variables” section allows you do to things like set the initial value of an internal variable of type “Decimal Number” to one of two different values.
Note that Quagensia T Edition supports nesting function calls inside of one another, so you are not limited to returning one of two values based on if a single set of conditions is True or False. For instance, in the example with Decimal Numbers above, if you kept nesting “IFF (Return One Of Two Decimal Expressions Based On Whether A Condition Is True Or False)” function calls in the “Decimal Expression To Return If True” and “Decimal Expression To Return If False” input parameters, you could return one of many different Decimal Numbers.
Determining if two decimal numbers are exactly equal is more difficult than it may seem.
By far, the most popular way that decimal numbers are stored in most programming languages that are used to program trading strategies for use in most trading platforms is by using a numeric data type called the “double-precision floating point number”. Variables of this type are usually referred to as “doubles” by programmers and “decimals” or “decimal numbers” in the user interfaces of programs that handle numeric values. The code output from all editions of Quagensia use the “double-precision floating point number” data type to store decimal values, since this is the most common way that the platforms that Quagensia supports handle decimal numbers.
The most counterintuitive thing that non-programmers may not already know about the “double-precision floating point number” data type is that the exact value of almost every decimal number that can be written on a piece of paper cannot be stored in a “double-precision floating point number” object. “Double-precision floating point number” objects hold inexact approximations of most decimal numbers. This issue becomes exacerbated when these decimal-valued objects are combined together using multiplication, addition, or any other kinds of numeric operations that takes decimal numbers as inputs, calculates a series of intermediate results, and then returns a different number. The implication of this is that two “double-precision floating point number” expressions will likely be considered not equal even if the two numbers should be logically equal based on basic mathematical reasoning. The two numbers that logically should be equal based on simple logic may be almost exactly equal but not exactly equal.
What this means for you is that your trading strategy should not depend on two decimal-valued numbers being exactly equal. Instead, if you need to check if two decimal numbers are “approximately equal”, you should either round the two numbers to a specified number of decimal places, round the two numbers to the nearest tick of the instrument being traded, determine if the absolute value of the difference of the two numbers is less than a specified threshold, or round the two numbers in some other way before comparing them.
Note that this is less of an issue with the TradeStation® platform than the NinjaTrader® platform since TradeStation®’s EasyLanguage® “double-precision floating point numbers” are rounded to a certain number of decimal places by default whereas “double-precision floating point numbers” in NinjaTrader®’s NinjaScript® are stored without rounding to a certain number of decimal places, but it is still advised to leave nothing to chance and use one of the techniques above to check if two decimal numbers are “approximately equal” rather than exactly equal regardless of the trading platform on which your trading strategy will run.
Quagensia N & T Editions have built-in advanced condition functions.
The no-code advanced condition functions built into Quagensia N & T Editions are listed below with links to their help pages. Each function is displayed in the same subfolder in which you can find it in the Quagensia Desktop Application’s Algo Explorer and in the context menu that appears when you click on a location on your Quagensia Algo’s workspace where the expression function or action function is allowed to be used.
The next section lists the advanced condition expression functions built into Quagensia N Edition. You can also scroll down to the list of advanced condition expression functions and advanced condition action functions built into Quagensia T Edition further down on this page.