The “Use TriggerCustomEvent to Sync Logic on Data Series” Action block makes it possible to use no-code functions and features that require accurate market data and indicator data in seven advanced sections in Quagensia N Edition Strategies where accurate market data and indicator data are not guaranteed to be available by default.
Of the ten subsections in the “When Advanced NinjaScript® Events Occur” section of a Quagensia N Edition Strategy, seven of them are not guaranteed to have accurate market data and indicator data by default, and runtime errors would occur for various reasons if no-code functions and features that use market data were allowed to be used in these sections without an extra layer of protection.
To fix this, Quagensia N Edition has a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block that allows no-code functions and features that use market data to be used in these sections so long as the no-code functions and features are used inside of a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block, just like no-code trading logic can be added inside of an “If Block”.
The “Use TriggerCustomEvent to Sync Logic on Data Series” Action block is not needed and not allowed in the “When Bar Updates”, “When OnMarketData Occurs”, “When OnMarketDepth Occurs”, and “When Button Control is Clicked” sections, and these sections already unconditionally allow no-code functions and features that use market data to be used in them.
However, the following sections require that no-code functions and features that use market data be used inside of a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block:
- When OnOrderUpdate Occurs
- When OnExecutionUpdate Occurs
- When OnPositionUpdate Occurs
- When OnAccountItemUpdate Occurs
- When OnConnectionStatusUpdate Occurs
- When NinjaTrader® ATM Strategy Callback Occurs
- When OnOrderTrace Occurs
When you click on a location in one of the seven sections above that is not in a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block, you will see a greatly reduced list of no-code functions and features in the context menu that appears. The choices you will see will be those choices that are most likely safe to use in a location not guaranteed to have accurate market data and indicator data. You will not see choices for prices, indicators, Editable Time Series, and no-code functions that either require market data or might require market data. Included in the list of no-code functions and features you will not see in context menus when you click on such a location are those related to drawing on the chart and the “Control Panels” features that allow you to add buttons, check boxes, text boxes, and labels to charts on which your strategies are applied. While it may seem like “Control Panels” features and some other no-code functions and features shouldn’t need market data, in our tests we found that runtime errors occur intermittently when these no-code functions and features are used in one of the seven sections listed above without also being inside of a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block, so these no-code functions and features were removed from the acceptable list of options in context menus that open when you click on such a location.
How to Add a “Use TriggerCustomEvent to Sync Logic on Data Series” Action Block to One of the Seven Sections that May Need It and How to Configure It
STEP #1: Add a “Use TriggerCustomEvent to Sync Logic on Data Series” Action Block to a Strategy
To add a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block to one of the seven sections listed above, click on a location in one of these sections where an Action is allowed, and select the “Use TriggerCustomEvent to Sync Logic on Data Series” Action block from the “More Actions” folder of the context menu that appears.
Once the “Use TriggerCustomEvent to Sync Logic on Data Series” Action block is added to your Quagensia N Edition Strategy’s workspace, you have three decisions to make about how it should be configured. These decisions are explained in STEP #2, 3, and 4 below.
STEP #2: Enter a number of bars in the “Once all data series have at least the following number of bars…” field.
In the numeric text box beneath the label that reads “Once all data series have at least the following number of bars…”, enter the number of bars that must be present in both the primary data series and all secondary data series before the actions inside this Action block will be executed. This is very important because unlike the “When Bar Updates” section, which by default only executes once the number of bars to which the “Bars required to trade” field in the NinjaTrader® user interface is set are present in both the primary data series and all secondary data series, all ten advanced sections (even those that are guaranteed to have accurate price and indicator data by default) are completely unfiltered and will execute whenever the underlying NinjaScript® “event-driven method” is executed. Out of an abundance of caution, it is recommended that you treat all ten of the advanced sections of a Quagensia N Edition Strategy as having the potential to be called at any time after the strategy is configured and is ready to accept market data and before the strategy has received any market data. And for the special case of the most advanced and probably least useful “When OnOrderTrace Occurs” section, you should treat it as having the possibility of executing even before the strategy is configured and is ready to accept market data. Note that for the special case of the “When OnOrderTrace Occurs” section, trading logic that is inside of a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block will only execute when the strategy is fully configured and ready to accept market data as well, so this Action block solves this second problem that exists by default in the “When OnOrderTrace Occurs” section.
STEP #3: Enter a data series index in the “Use TriggerCustomEvent to synchronize the logic below on the data series whose Data Series Index (Primary=0, First Secondary=1) is…” field.
If your Quagensia N Edition Strategy does not have any secondary data series, i.e. it does not have a “Secondary Price Bars” Internal Variable, this number should be 0, since the data series index of the primary data series is 0. Even if your strategy has multiple data series, this number can still be 0 if you want the actions that execute in this Action block to behave as similar as possible as they would if they were in the “When Bar Updates” section of your Quagensia N Edition Strategy that was being executed for the primary data series.
However, if your strategy does have a secondary data series and you want the actions that execute in this Action block to behave as similar as possible as they would if they were in the “When Bar Updates” section of your Quagensia N Edition Strategy that was being executed for a specific secondary data series, then set the value of this field to 1 to represent the first secondary data series, i.e. the “Secondary Price Bars” Internal Variable that is above all other Secondary Price Bar Internal Variables in the “Internal Variables” section of your strategy, set the value of this field to 2 to represent the data series represented by the second “Secondary Price Bars” Internal Variable from the top of the “Internal Variables” grid, and so on.
Usually 0 is a fine choice for this field and it should only be changed if you have a very specific reason why it should be changed.
STEP #4: Set the “And after the logic below executes call ‘ForceRefresh()’ to request that the chart visuals should be refreshed if the value below is set to ‘True’…” field to True or False.
If you set this field to True, the NinjaScript® function named “ForceRefresh()” will execute after all other actions in this Action block in order to inform the NinjaTrader® platform that some changes were made by the trading logic in this Action block that may require the visuals on the chart upon which this strategy is applied to be refreshed as soon as possible.
You can learn more about the NinjaScript® function named “ForceRefresh()” on the official NinjaTrader® help page titled ForceRefresh().
It is recommended to set this field to True if your trading logic in this Action block includes any logic that may change any button, check box, text box, or label that it added to the chart, if the logic draws any “Drawing Object” to the chart (like a tiny shape, line, or piece of text), or if the logic changes the value of an Editable Time Series that is being plotted either directly or indirectly as an input into an indicator, or if the logic does anything else that should change the appearance of the chart in any way.
Note that calling the NinjaScript® function named “ForceRefresh()” comes with a performance penalty, so it is best to only set this field to True if your logic really may change the visuals on the chart. If your logic is submitting orders or doing things that may draw markers or lines on the chart but the drawing of which is not explicitly done in your logic, you can set this field to False, because when the NinjaTrader® platform does things like submit an order or draw a fill marker on the chart, it handles the refreshing of the visuals on the chart on its own.
STEP #5: Add your trading logic to this Action block by adding it in the area below the label that reads “And permit the use of most logic components that are normally allowed in the ‘When Bar Updates’ section in the area below…”.
When you click on locations in this area, the context menu that appears will include all the no-code functions and features that either require or might require accurate market data or indicator data and that are allowed to be used in the section.
More Information About the “Use TriggerCustomEvent to Sync Logic on Data Series” Action Block
Using the “Use TriggerCustomEvent to Sync Logic on Data Series” Action block comes with a performance penalty, so you should only use it in the seven sections that might need it if you really do need to use one or more of the no-code functions or features that do not show up in the context menus that appear when you click in one of those seven sections that might need it but that do appear in context menus that appear when you click inside of an “Use TriggerCustomEvent to Sync Logic on Data Series” Action block.
The decision of whether or not to use this Action block can be simplified if you start to build your trading logic in one of these seven sections without using this Action block. If you are able to finish building your trading logic without using this Action block, then you shouldn’t need to move your trading logic into one of these Action blocks. But if you get to a point where you are not seeing a no-code function or feature in a context menu that opens when you click on a location that is not inside of a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block, then you should add a “Use TriggerCustomEvent to Sync Logic on Data Series” Action block below all your trading logic that may need to be in such an Action block, then cut the Actions that may need to be inside such an Action block and paste them into the “Use TriggerCustomEvent to Sync Logic on Data Series” Action block using a multi-action cut followed by a multi-action paste.
You can learn more about the NinjaScript® TriggerCustomEvent function, which is used by the Quagensia N Edition “Use TriggerCustomEvent to Sync Logic on Data Series” Action block, on the official NinjaTrader® help page titled TriggerCustomEvent().