Introduction
The Code Generation Tab is the tab that appears in the pane on the bottom of the Quagensia® Desktop Application’s user interface when a Quagensia Strategy or Quagensia Function is open in a tab and that tab is selected. It is not visible when the Start Page tab is the selected tab. Its tab is labeled “Generate Strategy Code” when a strategy is selected, and “Generate Function Code” when a function is selected.
The primary purpose of the Code Generation Tab in Quagensia N Edition is to allow you to generate a NinjaTrader® strategy code file for your Quagensia N Edition strategy and get this file into NinjaTrader®.
Note: NinjaTrader®’s programming language is called “NinjaScript®“, but Quagensia N Edition documentation usually uses the term “NinjaTrader® code” instead of “NinjaScript® code” since more people understand the term “NinjaTrader®” than understand the term “NinjaScript®“.
The primary purpose of the Code Generation Tab in Quagensia T Edition is to allow you to generate the TradeStation® strategy code for your Quagensia T Edition strategy and get this TradeStation® strategy’s code into TradeStation® by copying and pasting the outputted code into TradeStation®’s EasyLanguage® Editor.
Note: TradeStation®’s programming language is called “EasyLanguage®”, but Quagensia T Edition documentation usually uses the term “TradeStation® code” instead of “EasyLanguage® code” since more people understand the term “TradeStation®” than understand the term “EasyLanguage®”.
The “Set NinjaTrader® Strategy Code Folder Path” Button (Quagensia N Edition Only)
When you generate code, the code file is saved in a subfolder of your Quagensia User Folder. In order to use this strategy inside of NinjaTrader®, you will need to copy the NinjaTrader® strategy code file into the NinjaTrader® strategy code folder. You can do this by hand, outside of Quagensia N Edition, using File Explorer in Windows 10 or 11 or Windows Explorer in earlier versions of Windows, or you can do it with a single button click from within Quagensia N Edition if either the folder path of the NinjaTrader® strategy code folder is the same as the usual default location or if you inform Quagensia N Edition of the location of the NinjaTrader® strategy code folder by entering the folder path in the “Code Generation” tab of the Options window.
If the folder path of the NinjaTrader® strategy code folder is different than the usual default location and does not exist and you haven’t yet configured Quagensia N Edition to be able to send NinjaTrader® strategy code files directly to the NinjaTrader® strategy code folder at the non-default location, and you haven’t unchecked the “If The NinjaTrader® strategy code folder Path Is Invalid Then Please Remind Me To Fix This Problem” check box in the “Code Generation” tab of the Options window, you can click the “Set NinjaTrader® strategy code folder Path” button to open the Options window from where you can either enter a non-default location for the NinjaTrader® strategy code folder path or uncheck the “If The NinjaTrader® strategy code folder Path Is Invalid Then Please Remind Me To Fix This Problem” check box if you don’t want to set this folder path and instead want the “Set NinjaTrader® strategy code folder Path” button to no longer be displayed.
Some users may want to set this folder path to some other folder than the actual platform’s strategy code folder.
For instance, users who want to share certain code files with their co-workers in a networked environment, but also want to keep the rest of their work secret can set this folder path to a shared network drive.
Also, some users may have very strict testing or code review procedures for generated code files that must occur before a strategy is allowed to be placed in the NinjaTrader® platform’s code folder.
Note that you may have to run Quagensia N Edition as Administrator if your computer blocks Quagensia N Edition from automatically copying files to your preferred destination folder.
The “Generate Code and Copy Code File to NinjaTrader® Strategy Code Folder” Button (Quagensia N Edition Only)
Pressing this button in Quagensia N Edition when a Quagensia N Edition Strategy is selected causes the same two things to occur as when you press the “Generate Code” button followed by the “Copy Code File to NinjaTrader® Strategy Code Folder” button. See below for explanations of these two buttons.
The “Generate Code and Copy to Clipboard” Button (Quagensia T Edition Only)
Pressing this button in Quagensia T Edition when a Quagensia T Edition Strategy is selected causes the same two things to occur as when you press the “Generate Code” button followed by the “Copy to Clipboard” button. See below for explanations of these two buttons.
The “Generate Code” Button
Press the Quagensia N Edition’s “Generate Code” button to generate your Quagensia N Edition strategy’s NinjaTrader® code for use inside of NinjaTrader®.
Press the Quagensia T Edition’s “Generate Code” button to generate your Quagensia T Edition strategy’s TradeStation® code for use inside of TradeStation®.
When you press the “Generate Code” button for a Quagensia Strategy, a file containing the generated NinjaTrader® or TradeStation® strategy code is saved to a subfolder of your Quagensia User Directory’s “Code” folder. The name of the subfolder in which the file containing the strategy code is saved is the strategy’s “Strategy Name Inside of NinjaTrader® & Used in Quagensia Code Archive File & Folder Names” field (Quagensia N Edition) or “Strategy Name Used in Quagensia Code Archive File & Folder Names” (Quagensia T Edition). If you are generating the pseudo-code of a Quagensia Function (see below), the name of the subfolder in which the file containing the function pseudo-code is saved is the function’s “Function Name Used in Quagensia Code Archive File & Folder Names”.
A note to Quagensia Function authors: The “code” generated for your Quagensia Function is pseudo-code that is not meant to be used inside of NinjaTrader® or TradeStation®. This is because the nature of Quagensia Functions is that they are meant to be used by other Quagensia Algorithms, such as Quagensia Strategies and other Quagensia Functions, rather than being used by themselves in isolation. When this function is used by another Quagensia Algo, portions of the generated pseudo-code will be seamlessly embedded into different parts of the file of the non-function file that calls it (either directly, or indirectly through one of more functions that call each other), while other portions of the generated pseudo-code code are merely meant to help you understand where the code is meant to go and won’t be used at all when this function is used in the context of another algorithm. The generated pseudo-code will likely have further differences due to the nature of the context of the algo that calls it, such as the possible replacement of input parameter variable names with the actual resolved expression that is passed to the function via that parameter.
The generated Quagensia Function pseudo-code is still useful for two purposes:
- It makes it easier to understand the internal logic and construction of the function.
- Advanced users also may want to generate this code for consumption by a source control system, in order to determine if the function code output has changed, and therefore needs to be tested carefully again. This is a valuable quality control step that algorithmic traders can use to decrease the risk that a change made to the Quagensia Desktop Application or to the function logic itself causes unintended backtest results or causes actual money-losing trading errors if traded live with real money.
The “View Generated Code Folder” and “View Generated Code File” Buttons
The Code Generation Tab displays a button that says either “View Generated Code Folder” or “View Generated Code File”.
Clicking this button opens the folder to which an algo’s code is written when the “Generate Code” button is clicked, if this folder exists. See the discussion about the “Generate Code” Button directly above this section to learn how this folder’s name is determined. If this folder doesn’t exist, your Quagensia User Directory’s “Code” folder will be opened instead.
The “Copy Code File To NinjaTrader® Strategy Code Folder” Button (Quagensia N Edition Only)
Once you’ve generated the code for a Quagensia Algo, the “Copy Code File to NinjaTrader® Strategy Code Folder” button appears so long as either the folder path of the NinjaTrader® strategy code folder is the same as the usual default location or if you inform Quagensia N Edition of the location of the NinjaTrader® strategy code folder by entering the folder path in the “Code Generation” tab of the Options window. Click this button to copy the generated code file from your Quagensia User Folder into the NinjaTrader® strategy code folder. If a file with the same name already exists in the NinjaTrader® strategy code folder, you will be asked if you want to overwrite the file or cancel the operation.
The “Open NinjaTrader® Strategy Code Folder” Button (Quagensia N Edition Only)
The “Open NinjaTrader® Strategy Code Folder” button is displayed so long as either the folder path of the NinjaTrader® Strategy Code Folder is the same as the usual default location or if you inform Quagensia N Edition of the location of the NinjaTrader® Strategy Code Folder by entering the folder path in the “Code Generation” tab of the Options window. Click this button to open the NinjaTrader® Strategy Code Folder.
The “Copy To Clipboard” Button (Quagensia N Edition Instructions)
Once you’ve generated the code for a Quagensia N Edition algo, the “Copy To Clipboard” button appears. Click it to copy the generated NinjaTrader® strategy code (or function pseudo-code if you are generating the pseudo-code of a Quagensia Function) as text to the clipboard.
Once you’ve copied the code of a NinjaTrader® strategy code to the clipboard, you can paste it into an open NinjaTrader® strategy code file in NinjaTrader®’s NinjaScript® Editor in the way that you would normally paste text from the clipboard into any text file.
WARNING: If you use the clipboard to paste NinjaTrader® strategy code into a preexisting NinjaTrader® strategy code file, make sure that the name of the file without its file extension in the NinjaTrader® strategy code directory and the name of the strategy in the generated code are the same, or else you risk having two NinjaTrader® strategy code “classes” with the same name inside of the same instance of NinjaTrader®, which will cause a compilation error when NinjaTrader® attempts to compile all of the NinjaTrader® strategy code “classes” in all of the NinjaTrader® strategy code files in the NinjaTrader® strategy code folder.
For example, if the name of the strategy “class” in the generated code is “Q_MyStrategy”, you should only paste it into a NinjaTrader® strategy file whose name is “Q_MyStrategy.cs”. You can find the name of the strategy “class” by finding the line of code near the top of the generated code that is displayed in the Code Generation Tab’s large scrollable text box that looks like “public class Q_MyStrategy : Strategy” in the event that your strategy is called “MyStrategy”.
If you ever accidentally create a second strategy class with the same name and therefore cause compilation errors when NinjaTrader® attempts to compile all of the NinjaTrader® strategy code “classes”, you can easily fix this by either opening up the NinjaTrader® strategy code folder and deleting one of the two strategies or by changing the name of the strategy class in one of the NinjaTrader® strategy code files to match the file name of the code file without the “.cs” extension.
The “Copy To Clipboard” Button (Quagensia T Edition Instructions)
Once you’ve generated the code for a Quagensia T Edition algo, the “Copy To Clipboard” button appears. Click it to copy the generated TradeStation® strategy code (or function pseudo-code if you are generating the pseudo-code of a Quagensia Function) as text to the clipboard.
Once you’ve copied the TradeStation® strategy code to the clipboard, you can paste it into an open EasyLanguage® strategy document inside of TradeStation®’s EasyLanguage® Editor in the way that you would normally paste text from the clipboard into any text file.
The “Help” Button
Click the “Help” button to learn about the Code Generation Tab and the entire code generation process.
The “Quagensia N Edition Runtime Setup Assistant” Button
Click the “Quagensia N Edition Runtime Setup Assistant” button to open the Quagensia N Edition Runtime Setup Assistant. This assistant will guide you through the quick and easy process of selecting your preference of Quagensia N Edition Runtime license type (either email address-based or NinjaTrader® Machine ID-based licensing), importing a QuagensiaNEditionRuntime.zip NinjaScript® add-on file that comes with Quagensia N Edition into NinjaTrader®, and (if your free trial has expired) requesting and obtaining a Quagensia N Edition Runtime license based on your email address or Quagensia N Edition Runtime licenses for each of the NinjaTrader® Machine IDs of NinjaTrader® installed on your up to two machines to ensure that you are empowered to use the full power of Quagensia N Edition from within your NinjaTrader® strategies.
The “Options” Button
Click on the “Options” button to view or modify the code generation options in the Options window.
The “Version of NinjaTrader® (or TradeStation®) In Which This Code Will Be Used” Drop-Down List
The main purpose of this drop-down list is to prevent those users who prefer to use older versions of NinjaTrader® or TradeStation® from accidentally using programmable features of their trading platform from within the Quagensia Desktop Application that were added in a version of their trading platform that was released after the older version of the trading platform that they prefer to use.
Currently, only Quagensia N Edition has built-in Quagensia Algos that have been marked as only working in a certain version of NinjaTrader® or above, because while NinjaTrader®’s release notes are publicly available on the NinjaTrader® Release Notes page, the complete release notes for TradeStation® 9.5 and TradeStation® 10 are not publicly available. If we are able to gain access to the complete release notes for TradeStation® 9.5 and TradeStation® 10 we will do the same thing for Quagensia T Edition that we did for Quagensia N Edition for the benefit of users of older versions of TradeStation® 9.5 and TradeStation® 10. That said, Quagensia T Edition users should still set this drop-down list’s value correctly for protection from the above described problem that may occur due to one of at least three other possible scenarios, including 1) Quagensia Algos obtained from third-party Content Creators and other users who may mark their Quagensia Algos as only working in newer versions of the trading platform in order to protect you and other end users, 2) Quagensia Algos built into future versions of Quagensia T Edition by default and available from future versions of the Quagensia Algo Database that have been marked as not working in older versions of TradeStation®, and 3) Quagensia Algos that already exist in the Quagensia Algo Database and that are not currently marked as not working in older versions of TradeStation® for the reason described in the first part of this paragraph but that we mark as not working in older versions of TradeStation® at a later date when we discover that certain Quagensia Algos don’t work in older versions of TradeStation®.
Programmable features are sometimes added to the newest version of NinjaTrader® or TradeStation®, and sometimes programmable features may even be changed or removed.
When features are added to NinjaTrader® or TradeStation® we may release a new version of Quagensia N Edition or Quagensia T Edition that has additional Quagensia Functions and Quagensia Strategies that allow you to use the newest programmable features of NinjaTrader® or TradeStation®. When the programmable features of NinjaTrader® or TradeStation® are changed or removed, we may release a new version of Quagensia N Edition or Quagensia T Edition whose related Quagensia Functions and Quagensia Strategies are changed or removed.
When we include additional Quagensia Functions in new versions of Quagensia N Edition or Quagensia T Edition that allow you to use the newest programmable features of NinjaTrader® or TradeStation® or when we provide Quagensia Strategies that use these newly included Quagensia Functions, we set the “Minimum Supported Version of NinjaTrader® (or TradeStation®)” field’s value of each of these Quagensia Functions and Quagensia Strategies to the version of NinjaTrader® or TradeStation® that first included the new programmable features so that the Quagensia Desktop Application’s code generation engine is able to determine that these new Quagensia Functions and Quagensia Strategies are incompatible with versions of NinjaTrader® or TradeStation® that are lower than this minimum supported version.
Set the value of the “Version of NinjaTrader® (or TradeStation®) In Which This Code Will Be Used” drop-down list to the version of the NinjaTrader® or TradeStation® platform in which the generated code will be used.
If the version of the trading platform is the newest version or if it is higher than the highest version shown in this drop-down list’s choices then set the value of this drop-down list to “The Newest Version”.
When you or the end user of your Quagensia Functions and Quagensia Strategies sets the value of this field to the version of the trading platform in which the generated code will be used, you or your end user are telling the Quagensia Desktop Application’s code generation engine that it should stop you or your end user from generating code for Quagensia Functions or Quagensia Strategies whose minimum supported version is higher, or whose maximum supported version is lower, than the version of the trading platform in which the generated code will be used.
When you or your end user attempt to generate code for any version-incompatible Quagensia Function or Quagensia Strategy, the code will not be generated, and descriptive validation errors will be displayed that inform you or your end user that in order to generate the code you or they will need to first install a compatible version of NinjaTrader® or TradeStation®, then change the “Version of NinjaTrader® (or TradeStation®) In Which This Code Will Be Used” drop-down list’s value to the newly installed version, then regenerate the code. When these steps are taken, the code will be generated and the validation errors pertaining to version-incompatibility will not be displayed.
The purpose of stopping you or your end user from generating version-incompatible code is to prevent you or your end user from experiencing frustrating compilation errors and frustrating and dangerous run-time errors and undesired run-time behaviors that might possibly occur inside of the trading platform if you or your end user attempt to compile or run a trading strategy whose code uses programmable features that only exist in versions of NinjaTrader® or TradeStation® that are newer or older than the version of the NinjaTrader® or TradeStation® platform for which the generated code is intended.
If code generated by Quagensia N Edition or Quagensia T Edition compiles in an older version of NinjaTrader® or TradeStation® it will almost always compile in newer versions. The much more likely type of problems that correctly setting this field prevents are compilation errors, run-time errors, and undesired run-time behaviors that could occur when you generate code using a version of Quagensia N Edition or Quagensia T Edition that was released after your version of NinjaTrader® or TradeStation® if the newer version of Quagensia N Edition or Quagensia T Edition generates code for programmable features that are only in versions of NinjaTrader® or TradeStation® that are newer than your version of NinjaTrader® or TradeStation®.
If you create a Quagensia Function or Quagensia Strategy that you know doesn’t work in certain versions of NinjaTrader® or TradeStation® or if you are distributing the Quagensia Function or Quagensia Strategy to end users and want to protect them from the possibility that your Quagensia Function or Quagensia Strategy doesn’t compile or run properly in certain versions of NinjaTrader® or TradeStation®, such as really old versions, we recommend that you do the following things:
- Check the check box near the top of your Quagensia Algo titled “Only Works in Specific Versions of NinjaTrader® (or TradeStation®)”, then check the check boxes titled “Has a Minimum Supported Version of NinjaTrader® (or TradeStation®)” and/or “Has a Maximum Supported Version of NinjaTrader® (or TradeStation®)”.
- Then, enter the minimum or maximum supported versions in the text boxes that appear beneath the check boxes when you check them. Note that valid version numbers are made up of between one and four positive whole numbers, separated by periods. The only characters allowed in version numbers are the digits 0 through 9 and periods. For example, the following version numbers are valid: 8.0.99.1, 8.0.99, 8.0, and 8. To find the four-part version number for an installation of NinjaTrader®, click on the “About…” menu item of the “Help” main menu item. The version number will have four positive whole numbers, separated by three periods, like “8.0.22.2”. To make it easier for TradeStation® users, instead of using the more confusing but technically correct version number, Quagensia T Edition uses four-part version numbers that look like “10.0.7.0” for “TradeStation® 10.0 Update 7”, “10.0.0.0” for the TradeStation® 10.0 original release, or “9.5.7.0” for “TradeStation® 9.5 Update 7”. You can find the number of the “Update” of TradeStation® 9.5 (or 10.0) by clicking on the “About TradeStation® 9.5” or “About TradeStation®” menu item of the “Help” main menu item.
- We recommend that in addition to setting the minimum and maximum version fields that you actually name your Quagensia Function or Quagensia Strategy in a way that makes it impossible to miss that it only works in certain versions of NinjaTrader® or TradeStation®. An example of this practice would be naming a function that only works in NinjaTrader® version 8.0.15.0 or above like “Draw Polygon (With 4 Vertices) (NT8 v. 8.0.15.0+)”.