The “When OnPositionUpdate Occurs” Section (N Edition)

You can add no-code trading logic to the “When OnPositionUpdate Occurs” section of a Quagensia N Edition Strategy that will be executed when the NinjaScript® strategy’s “OnPositionUpdate()” event-driven method is executed.

NinjaScript® strategies have an event-driven method (a method is another name for a function) named OnPositionUpdate() that is called by the NinjaTrader® platform while the NinjaScript® strategies are running.

To learn more about the OnPositionUpdate() method you can read the OnPositionUpdate() method’s help page on NinjaTrader’s official website.

You can access the arguments, or “input parameters”, passed to the “OnPositionUpdate()” event-driven method by the NinjaTrader® platform from the “When OnPositionUpdate Occurs” section without code.

The method signature for the OnPositionUpdate() method is as follows:

protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)

You can add one of the input parameters of the OnPositionUpdate() method signature above to the no-code logic in your strategy’s “When OnPositionUpdate 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 OnPositionUpdate Occurs” folder of the context menu that opens.

The first input parameter of the OnPositionUpdate() method is an advanced NinjaScript® “Position” object. You can access it in the same way as you can access the non-advanced input parameters as described above. Quagensia® N Edition has a data type called “Position NinjaScript® Object” which allows you to create some very powerful trading logic both in the “When OnPositionUpdate 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 Position NinjaScript® Object.

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 the “When OnPositionUpdate Occurs” section.

The “When OnPositionUpdate Occurs” section is 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 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 to be used in the “When OnPositionUpdate 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 OnPositionUpdate 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 OnPositionUpdate 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”.

Submit your high-quality Quagensia tutorials for consideration for free inclusion on our website.

If you publish high-quality Quagensia tutorials on a social media platform like YouTube, please consider submitting them to us. We may promote them for free by linking to them from relevant pages on our website.

To submit your Quagensia tutorials for consideration for free inclusion on our website, use the How to Submit Your Quagensia-Enhanced Content page. We are available by phone or email to help you create, publish, and promote Quagensia-enhanced content. You can also get questions answered in our Content Creator Support Center and in the official Quagensia® Discord community’s content-creators channel.

Thanks for Sharing!

Ready to get started?

Download the Quagensia no-code strategy builder free trial and build your trading strategies now.

Under a dollar a day.

Priced to be an easy decision for most traders.

Join Us on Discord

Build point-&-click strategies for NinjaTrader® and TradeStation® using Quagensia®. Collaborate with other traders to get and give help, build and backtest strategies together, and grow your skills.

Subscribe to our Newsletter

We'll send you product updates and company news from Quagensia as well as curated lists of Quagensia-enhanced content.

Welcome
Content Creators

Quagensia enables content creators to make interactive content. We invite you to create Quagensia-enhanced content and share it on YouTube and other social media channels. You may submit your high-quality Quagensia-enhanced content for consideration for free inclusion on our website.

Screenshots

For larger and additional screenshots, see large Quagensia N Edition screenshots (for NinjaTrader®) and large Quagensia T Edition screenshots (for TradeStation®).

For additional screenshots, see the list of Strategies Built into Quagensia N Edition (for NinjaTrader®) and Strategies Built into Quagensia T Edition (for TradeStation®). Select a built-in strategy that interests you and scroll down for the screenshot. Then scroll up to the top of the page and click the “Overview” link to watch the video on how to use that built-in strategy.

This is a screenshot of the point-and-click trading strategy you will build in Quagensia N Edition (for NinjaTrader®) if you follow along with the video titled Create NinjaTrader® Strategies Using Point-&-Click with Quagensia N Edition – Full Tutorial.

This is a screenshot of the point-and-click trading strategy you will build in Quagensia N Edition (for NinjaTrader®) if you follow along with the video titled "Introduction to Quagensia N Edition".

Click the gear icon that appears when you place your mouse pointer over the location to which you would like to add trading logic. A context menu will appear with filtered options to choose from.

Click the gear icon that appears when you place your mouse pointer over the location to which you would like to add trading logic. A context menu will appear with filtered options to choose from.

Thanks for Sharing!

Ready to get started?

Download the Quagensia no-code strategy builder free trial and build your trading strategies now.

Under a dollar a day.

Priced to be an easy decision for most traders.

Join Us on Discord

Build point-&-click strategies for NinjaTrader® and TradeStation® using Quagensia®. Collaborate with other traders to get and give help, build and backtest strategies together, and grow your skills.

Subscribe to our Newsletter

We'll send you product updates and company news from Quagensia as well as curated lists of Quagensia-enhanced content.

Welcome
Content Creators

Quagensia enables content creators to make interactive content. We invite you to create Quagensia-enhanced content and share it on YouTube and other social media channels. You may submit your high-quality Quagensia-enhanced content for consideration for free inclusion on our website.