You can add no-code trading logic to the “When OnOrderTrace Occurs” section of a Quagensia N Edition Strategy that will be executed when the NinjaScript® strategy’s “OnOrderTrace()” event-driven method is executed.
NinjaScript® strategies have an event-driven method (a method is another name for a function) named OnOrderTrace() that is called by the NinjaTrader® platform while the NinjaScript® strategies are running.
To learn more about the OnOrderTrace() method you can read the OnOrderTrace() method’s help page on NinjaTrader’s official website.
You can access the arguments, or “input parameters”, passed to the “OnOrderTrace()” event-driven method by the NinjaTrader® platform from the “When OnOrderTrace Occurs” section without code.
The method signature for the OnOrderTrace() method is as follows:
protected override void OnOrderTrace(DateTime timestamp, string message)
You can add one of the input parameters of the OnOrderTrace() method signature above to the no-code logic in your strategy’s “When OnOrderTrace Occurs” section by clicking in this section at a location where an expression of the specific input parameter’s data type is allowed and selecting it from the “When OnOrderTrace Occurs” folder of the context menu that opens.
The “Use TriggerCustomEvent to Sync Logic on Data Series” Action block makes it possible to use no-code functions and features that either require the strategy to be configured and ready to accept market data or that require accurate market data and indicator data in the “When OnOrderTrace Occurs” section.
The “When OnOrderTrace Occurs” section is neither guaranteed to have accurate market data and indicator data by default nor is it even guaranteed to only be executed after the strategy is configured and ready to accept market data, and runtime errors would occur for various reasons if no-code functions and features that use market data or that require that the strategy is at least configured and ready to accept market data were allowed to be used in this section 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 or that require that the strategy is configured and ready to accept market data to be used in the “When OnOrderTrace Occurs” section 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”.
You may need to use a “Lock Critical Block of Code (lock(object){…})” Action block in the “When OnOrderTrace Occurs” section and other sections to ensure that certain blocks of trading logic are never executed at the same time on two different threads, but instead “take turns” executing
The NinjaTrader® Desktop platform is a multi-threaded application that is able to run the NinjaScript® strategies you create using Quagensia N Edition on multiple threads at once. For instance, while the trading logic in your Quagensia N Edition Strategy’s “When OnOrderTrace Occurs” section is running, NinjaTrader® can process information about your NinjaScript® strategy’s market data, orders, fills, positions, account, and much more on multiple separate threads at the same time. As another example, when you click a Button Control that your Quagensia N Edition Strategy adds to the NinjaTrader® chart on which it is applied, the trading logic that is in the Button Control’s “When Button Control is Clicked” section can be executed at the same time that everything described in the previous sentence is occurring.
If you have multiple blocks of no-code trading logic in a Quagensia N Edition Strategy that absolutely must not be executed at the exact same time as each other on two different threads, you can accomplish this by putting each of the multiple blocks of code inside of their own Lock Critical Block of Code (lock(object){…}) Action blocks, similar to how you can put trading logic into an “If Block”.