Broker/Data: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Favorite Futures: ES, CL, EUR/USD, TF
Posts: 171 since Aug 2009
Thanks: 99 given,
Debug Ninjascript in Visual Studio on Live or Replay data
I have noticed that using replay data is actually very valuable in terms of strategy development and making sure I programmed the IOrders correctly.
I noticed that sometimes when I do a "Managed Approach" using multiple exit targets, I then need to create multiple IOrders for each leg if I am correct.
So if I need 2 targets, I need to create 2 entry IOrders, 2 stop IOrders, and 2 target IOrders.
I noticed, however, that for some reason when I use replay data, on the first trade it will work properly, however, as soon as the 2nd short trade happens, it will only put on 1 of my stop IOrders and the other one does not even get into an Accepted state and remains null.
I wanted to know if using Visual Studio to debug each bar would be helpful. However, I noticed that while attaching to a process, putting in my breakpoint, and then refreshing NinjaTrader chart: I can then see my breakpoint go from red to yellow and I see the stack fill up with the first bar.
However, I don't want historical data. So, it is fine, I just delete tick data from the tick data folder --- because I use tick granularity for order entry, so when I load the strategy, if there is no historical tick data, it starts only on new data.
So, the problem is when I start a breakpoint from this point, I cannot have access to "new incoming data" from the replay data. As soon as I start the replay data, it shows NinjaTrader as "not responding" until I hit "Stop debugging" and detach process from Visual Studio.
So here is my delima: How do I debug on "Replay Data" so I can see what is going on with my program on Live Data or Replay Data that "Streams" and is not historical?
Historical data acts different than real live or replay data in Ninja.
Here is the code I am trying to debug. For some reason, the 2nd IOrder: stop2Order which is linked to "StopShort2" and "Sort2" from entry2Order does not get filled when you play it on 10/01 or 10/02 on the 2nd order.
Here is the strategy
Here is the indicator
So when install indicator then strategy, and compile, and download 10/01 and 10/02 replay data from CQG, and open 1 chart and turn on chart trader (so I can see the stops and targets) and then open another chart and open the sdIBTest.cs strategy, when I start replay data on 500 speed, it does first short trade fine, but the next one instead of having 20 contracts for the Stop, it only has 10 contracts.
When I look at the log, the StopShort2 is not even listed as "Accepted"
When I try to trace when is going in with stop2Order at any point.
I put it in OnExecution, or OnOrderUpdate, and nothing happens when that 2nd order comes in.
I am totally not understanding.
The only thing I can think of is moving to a "Unmanaged Approach" and using 2 target IOrders, but using 1 entry IOrder and 2 stop IOrder, and then just use the "ChangeOrder(.......) " method to change the amount of contracts when something gets hit. I can override OCO functionality this way.
However, the other problem that gets created is: What are the things I now need to handle when I use an "Unmanaged Approach"?
Order Rejection? and ConnectionStatus type things?
Basically I want to be able to not have the strategy totally turn off when an order gets rejected. Just go flat but keep the strategy running. I think I can handle this with OnOrderUpdate and using the
There is something I need to say also in Initialize() to declare that I intend to take control over this.
I think I understand Order Rejected, but how does the "Unmanaged approach" handle connection loss issues?
I, of course, just want this:
1. if I lose a connection, when I re-establish a connection, then I want the strategy to go back to work
2. If Ninja crashes or the computer crashes, when I restart, I want the strategy to pick up where it left off.
I do not want it to go flat and then start fresh again.
so a lot of input here
1. Live and Replay Visual Studio debugging
2. Did I program something wrong in my strategy concerning IOrders?
3. If using an Unmanaged Approach, how do I handle connection loss issues so it always picks up where it left off and becomes a pretty bulletproof or close to bulletproof strategy?
Last edited by spinnybobo; October 27th, 2013 at 07:36 PM.