PDA

View Full Version : Strategy: Halting a Strategy Once User Defined Conditions Are Met


NinjaTrader_Josh
01-04-2008, 01:09 AM
Reference sample for NinjaTrader 6.5.XXXX.X or greater.

For error-handling, money-management or any other reason you may want to halt your strategy from processing its' core program logic. Before you halt your strategy, it is best to close all positions and cancel all active orders to prevent the risk of having an unmanaged position in the market.

We have provided two reference samples.

The SampleHaltBasicStrategy reference sample demonstrates the following concepts and is intended for strategies driven exclusively by the OnBarUpdate() method:

Using PnL statistics to determine when to halt processing of the strategy
Cancelling active orders
Closing active positions

Another sample can be found here: http://www.ninjatrader-support.com/vb/showthread.php?t=4084

The SampleHaltAdvancedStrategy reference sample's intended audience is for advanced programmers who have programmed strategies that take advantage of event-driven methods such as, but not limited to, OnMarketData() or OnOrderUpdate() in addition to the OnBarUpdate() method. It demonstrates the following concepts:

Using a custom method to halt processing on all event-driven methods
Advanced order handling in error situations with the OnOrderUpdate() method

Important methods and properties include:

CancelOrder() (http://www.ninjatrader.com/support/helpGuides/nt7/cancelorder.htm)
IOrder (http://www.ninjatrader.com/support/helpGuides/nt7/iorder.htm)
Performance (http://www.ninjatrader.com/support/helpGuides/nt7/performance.htm)

Other methods and properties of interest include:

OnMarketData() (http://www.ninjatrader.com/support/helpGuides/nt7/onmarketdata.htm)
OnOrderUpdate() (http://www.ninjatrader.com/support/helpGuides/nt7/onorderupdate.htm)

Import instructions for NinjaTrader 6.5.XXXX.X or greater:

Download the file contained in this thread to your PC desktop
From the Control Center window, select the menu File > Utilities > Import NinjaScript
Select the downloaded file