Introduction
The “Raw Code Output” expression allows you to add an expression of a specified data type at your chosen location in the code output by providing you with a text box where you can write actual code in the programming language that a given edition of Quagensia outputs, and a list of data types that allows you to indicate the data type of the expression to the Quagensia® Desktop Application.
This is an advanced feature that is used primarily by authors of functions that need to output raw code.
Most Quagensia Expression Functions that come with your edition of Quagensia use a “Raw Code Output” expression as a way to translate the uses of the visual, codeless Quagensia Function in all the Quagensia Algos in your installation of your edition of Quagensia into actual trading strategy code.
Note that you can insert a reference to an input parameter or an internal variable by right clicking in the text box at the desired location, then selecting the input parameter or internal variable whose reference you want to insert at that location.
When you do this, you will notice that a reference of this type looks like {|~Var~The_Name_Of_Your_Variable_Goes_Here~A_Long_String_Of_Letters_And_Numbers_Goes_Here~|}. Although you are free to type this by hand, inserting placeholders via the “Insert Placeholder” context menu is much easier and less error-prone.
The “Raw Code Output (Single or Multiple Statements)” action also fulfills an additional essential role in Quagensia T Edition by enabling Quagensia T Edition action functions to do the kinds of advanced calculations that are not possible in Quagensia T Edition expression functions due to the limitation that Quagensia T Edition expression functions are limited to doing the kinds of calculations that can be done in a single line of code with no local variables to store intermediate results. A detailed discussion of this for Quagensia T Edition users is further down on this page.
Defining Variables in Code (Quagensia T Edition Only)
Unlike Quagensia N Edition, Quagensia T Edition doesn’t have the ability to output function definitions with their own set of local variables, nor does Quagensia T Edition allow you to define local variables by defining them by typing them in code verbatim, nor does Quagensia T Edition allow you to create a Quagensia T Edition Expression Function with anything other than a single “Exit Function With This Return Value” action whose return value is set to an expression (which will often be a “Raw Code Output” expression but doesn’t have to be). Quagensia T Edition does however offer you a way to accomplish something similar to a complex Quagensia N Edition Expression Function containing thousands of lines of code and many local variables by allowing you to create variables that are defined globally in the EasyLanguage® strategy whose code Quagensia T Edition outputs but that you can use inside of the “Raw Code Output” text boxes of “Raw Code Output (Single or Multiple Statements)” actions in Quagensia T Edition Strategies and Functions and then use the variables as though they are “Local to a single Raw Code Output text box” or “Local to all Raw Code Output text boxes in a single algo”, so long as you follow some easy to remember rules.
Defining and using these kinds of “local” variables is not supported in the “Raw Code Output” expression of Quagensia T Edition, but you can accomplish a similar thing using the Raw Code Output (Single or Multiple Statements) action, which allows you to do complex calculations using thousands of lines of code and a very large number of variables, and then set an internal variable in a Quagensia T Edition Strategy or an input parameter passed by reference to a Quagensia T Edition Action Function with the result of the calculation, which then becomes available outside of the “Raw Code Output (Single or Multiple Statements)” action’s “Raw Code Output” text box for use as a standard codeless, visual variable reference that can be used like any other variable reference to any input parameter or internal variable of a Quagensia Algo.
Workarounds for the Inability to Use a Non-Text “Raw Code Output” Expression Directly in a “Text Added Together” Expression
A common task in Quagensia N or T Edition is to build up some Text by “concatenating”, i.e. appending, multiple pieces of Text together, but using expressions of other data types, such as Decimal Number or Boolean (True or False) expressions, at some of the locations in the concatenated pieces of Text. For instance, traders often debug, or troubleshoot, their Quagensia Strategies by appending pieces of Text, Decimal Number expressions like the close price of the current bar or the value of an indicator plot, Boolean (True or False) expressions, and Date and Time expressions together and then printing them out to the NinjaScript® Output Window or the EasyLanguage® Print Log on every “When Bar Updates” event or on “When Bar Updates” events when a certain Set of Conditions is True.
If you try to use a “Raw Code Output” Expression at one of these locations, you will see that when you add it to the canvas that its “Raw Code Output Expression of Type” drop-down list’s value is set to “Text” since every location of a Text concatenation is technically Text.
You probably have noticed that you are able to add non-Text Expressions other than “Raw Code Output” Expressions, such as Decimal Number expressions like the close price of the current bar, at locations in Text concatenations, and that when you do this, the non-Text Expression is “wrapped” in a Quagensia Function named “Convert Non-Text To Text”, which converts the non-Text expression, like the close price of the current bar, into a piece of Text.
You can even click on the non-Text expression that is “wrapped” by the Quagensia Function named “Convert Non-Text To Text” and replace it with another non-Text expression of the same data type or even a different data type, such as a Date and Time. However, when you click on the expression that is “wrapped” by the Quagensia Function named “Convert Non-Text To Text” you will notice that there is no option in the context menu for “Raw Code Output Expression”. This is because both the input parameter of the Quagensia Function named “Convert Non-Text To Text” and the “Raw Code Output Expression” are considered to have a data type of “Wildcard”, i.e. their data type is flexible and defined by another expression or location where an expression can go, specifically their parent expression that they are “wrapped in” or a child expression used as an input parameter of a Wildcard function, but “Wildcard” expressions are not allowed to be “chained together” since neither Wildcard expression knows what its data type should be and so relies on its parent expression or a child expression that is chained together with it.
Here are two workarounds for the inability to use a non-Text “Raw Code Output” Expression Directly in a “Convert Non-Text To Text” function in a Text concatenation:
Workaround #1: Define an internal variable of the data type of the “Raw Code Output” Expression (for example “Decimal Number”), set the internal variable to the value of the “Raw Code Output” Expression, then use the non-Text “Raw Code Output” Expression directly in a “Convert Non-Text To Text” function in a Text concatenation.
Workaround #2: Click on the “Convert Non-Text To Text” function’s input parameter where you would like the non-Text “Raw Code Output” Expression to be placed, then select a function from the context menu that converts an expression of the data type of the non-Text “Raw Code Output” Expression to Text to insert it directly at that location, then click on the relevant input parameter of the function you just added to the Algo’s Workspace and choose “Raw Code Output” Expression from the context menu and enter your non-Text expression in the “Raw Code Output” Expression’s text box. Functions that convert an expression of a non-Text data type to Text can be found in the context menu that appears when you click on the “Convert Non-Text To Text” function’s input parameter, in the following context menu folder:
More Expressions >> Data Type Conversion and Rounding Decimal Numbers >> Convert Non-Text To Text