You can add no-code trading logic to the “When OnFundamentalData Occurs” section of a Quagensia N Edition Strategy that will be executed when the NinjaScript® strategy’s “OnFundamentalData()” event-driven method is executed.
NinjaScript® strategies have an event-driven method (a method is another name for a function) named OnFundamentalData() that is called by the NinjaTrader® platform while the NinjaScript® strategies are running.
To learn more about the OnFundamentalData() method you can read the OnFundamentalData() method’s help page on NinjaTrader’s official website.
You can access the single argument, or “input parameter”, passed to the “OnFundamentalData()” event-driven method by the NinjaTrader® platform from the “When OnFundamentalData Occurs” section without code.
The method signature for the OnFundamentalData() method is as follows:
protected override void OnFundamentalData(FundamentalDataEventArgs fundamentalDataUpdate)
You can add the “FundamentalDataEventArgs fundamentalDataUpdate” input parameter of the OnFundamentalData() method signature above to the no-code logic in your strategy’s “When OnFundamentalData Occurs” section by clicking in this section at a location where an expression of the “FundamentalDataEventArgs fundamentalDataUpdate” input parameter’s data type is allowed and selecting it from the “When OnFundamentalData Occurs” folder of the context menu that opens.
The single input parameter of the OnFundamentalData() method is an advanced NinjaScript® “FundamentalDataEventArgs” object. Quagensia® N Edition has a data type called “FundamentalDataEventArgs NinjaScript® Object” which allows you to create some very powerful trading logic both in the “When OnFundamentalData Occurs” section and in other sections. You can read the help page titled Using Advanced NinjaScript® Objects in Quagensia® N Edition to learn more about using advanced NinjaScript® objects such as the FundamentalDataEventArgs NinjaScript® Object.
The “When OnFundamentalData Occurs” section will execute whenever the underlying OnFundamentalData() NinjaScript® event-driven method is executed, and this can occur before all the data series of the strategy have at least the number of bars to which the strategy’s “Bars required to trade” field in the NinjaTrader® user interface is set.
Unlike the “When Bar Updates” section, which 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, the “When OnFundamentalData Occurs” section is completely unfiltered and will execute whenever the underlying OnFundamentalData() NinjaScript® event-driven method is executed.
The OnFundamentalData() NinjaScript® event-driven method is not called for historical bars on a chart, only real-time bars, so if you are applying your strategy to a chart with enough historical price bars to handle the number of bars back that your trading logic requires you should not experience issues due to the trading logic in the “When OnFundamentalData Occurs” section being executed for every execution of the OnFundamentalData() NinjaScript® event-driven method. For instance, if your trading logic requires data from only one bar ago and you apply your strategy to a chart with five historical bars, you should not experience any issues due to this behavior of the “When OnFundamentalData Occurs” section.
That said, to reduce the likelihood that your strategy will ever experience a runtime error or a logic error due to this issue, it is recommended that if your logic needs to access any market data other than that which is in the “FundamentalDataEventArgs fundamentalDataUpdate” input parameter of the OnFundamentalData() method, that you should put that logic in an “If Block” that has a condition that checks to ensure that there are enough price bars. You can create such a condition in multiple ways, including by setting the condition’s comparison operator to “Is Equal To”, then clicking on the location on the left side of the “Is Equal To” and selecting either the no-code function named “Not Enough Price Bars (Checks Primary And Secondary Data Series)” or the no-code function named “Not Enough Price Bars (Checks Primary Data Series Only)” from the “Price Data >> Price Bar Metadata” folder of the context menu that opens, then entering the required number of bars into that no-code function’s single input parameter, then clicking on the right side of the “Is Equal To” and selecting “False” from the “Hard-Coded Value (True, 42, “Hello”, List of Choices)” folder of the context menu that appears.
You may need to use a “Lock Critical Block of Code (lock(object){…})” Action block in the “When OnFundamentalData 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 OnFundamentalData 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”.