A Trader Journal

Change yourself, change your trading.

Ninjatrader: Discretionary trading using Strategy analyzer

If your platform is not Ninjatrader then probably you can skip this post. All the quant stuff on this blog are done using Ninjatrader & R. For last few days I was trying to get Ninjatrader software handle following scenario. I feel the scenario is fairly common and the solution will be useful others. So posting it on the blog.

Scenario:
I have couple strategies that works off daily and weekly charts. Now I would like to use the strategies for live trading. But I am NOT comfortable with software placing orders automatically. Also I would like to use some level of discretion. So my desired workflow is:
  • Each day wait for US markets to close for the day. Then start Ninjatrader and connect to an EOD data feed (Example: Yahoo/Kinetic etc).
  • Select my strategy and run on a pre-defined watch list in Strategy Analyzer.
  • The strategy executes on the watchlist and generates list of orders (buy/sell/short/cover) with details. I either take a printout (or save in spreadsheet) to trade manually the following day/week.
  • Repeat the above step for other production strategies & watch lists.
Solution:
I don't like Market Analyzer and Strategies tab options in Ninjatrader to implement above workflow for reasons like - (a) One needs to write additional indicators for each of the strategies thereby increasing work and code maintenance complexity (b) The strategies and market analyzer tabs are not as simple/flexible as strategy analyzer to run on watch lists and (c) I am more comfortable and accustomed with strategy analyzer because of all that back testing.

The solution actually seems to be quite simple. Hopefully I am not overlooking something and get hit in coming days. Following are the steps:
  1. In strategy Initialize() method, set CalculateOnBarClose variable to false and recompile. See the code for sample strategy at the end.
  2. In strategy OnBarUpdate() method, write your logic to print order data. In my case, I created custom order class (and filled it with details I need) in OnBarUpdate() method. The locations were just before the lines where strategy triggers call Entry and Exit orders. See the code for sample strategy at the end.
  3. In strategy OnTermination() method, add logic to write all collected orders to a file.
  4. Verify the strategy generates orders correctly by varying the end-date (i.e. To) in backtest options. Also verify once by actually waiting for market to close and run your strategies.
That pretty much completes what I did. Looks like for daily charts, ninjatrader is forced to use the session template from the data providers. The provider may send data out on daily bars as ETH or RTH. (Extended Trading Hours) or (Regular Trading Hours) with Extended including the overnight trading. I tested the above with Yahoo and Kinetic EOD (free) data feeds. They seem to work. So I guess these data feeds session template for daily bars is RTH.

Sample Strategy Code - SampleOrderTest.cs

Note: I will post the custom order and utilities library in following days after some cleanup.  They are not as such needed to verify the above scenario. The utilities library is mainly for aiding strategy to generate orders in csv format with content similar to NT orders (plus some additional fields like notes etc) and few additional APIs to handle multi-instrument rotational strategies.

Now I am not an expert on NinjaTrader and don't know if there are any problems with the above solution. So please do due diligence and use at your own discretion. Also any content on this blog is NOT a recommendation.

Credits - The post would not be complete without mentioning the help received from Koganam (member) and  Ninjatrader_JC (NT support)  in support forum.

1 comments:

Anonymous said...

Just found your site and am reading around. I also use Ninjatrader, and what I do to achieve the same result is convert any strategies to indicators and then run them on charts.

I have different workspaces for different groups of strategies. I keep Ninjatrader running all the time, and just check the appropriate workspace at the appropriate time. I can see all my signals, and act on them manually.

Sometimes the conversion of a strategy to an indicator is a pain, usually depending on the stop out logic. Time based stops are pretty easy to convert.

Post a Comment

Share