View Full Version : Unexpected outcome from sync
richp6
09-24-2010, 12:15 AM
Hi,
I'm trying to solve a common problem that I know NT has accounted for, but I can't seem to get it to act the way I'm expecting.
Here is my simple problem: the strategy opens a position with stop / profit target. NT disconnects, so my strategy becomes disabled. When I re-enable the strategy, NT closes my position.
Here are my relevant settings:
sync with account position = true
immediately submit orders
if (historical) return
Even though I have open profit / stop on an open position, NT closes my position when enabled. I want it to just continue to manage the stop and profit target as it was doing before.
Thanks,
Rich
NinjaTrader_Bertrand
09-24-2010, 05:12 AM
Rich, thanks for reporting in - are you sure the strategy still carries the open position at the point of reenabling then? Have you confirmend this via the strategies tab as you restarted it up?
http://www.ninjatrader.com/support/helpGuides/nt7/syncing_account_positions.htm
Thanks
richp6
09-24-2010, 08:03 AM
Bertrand,
Here is the output I'm getting from the strategy when I test it via disconnecting from my broker data (I'm testing this using Sim102).
9/24/2010 6:55:00 AM Entered internal PlaceOrder() method at 9/24/2010 6:55:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Target' FromEntrySignal=''
9/24/2010 6:55:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Target' Mode=Price Value=1161 Currency=0 Simulated=False
9/24/2010 6:56:57 AM CancelAllOrders: BarsInProgress=0
**NT** Disabling NinjaScript strategy 'FollowThroughDown/a23ee46d05784f3b9fab607ee65a5805'
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target' Mode=Price Value=1001 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target' Mode=Price Value=1040 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target 1' Mode=Price Value=1 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target 2' Mode=Price Value=1 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target 3' Mode=Price Value=1 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target1' Mode=Ticks Value=400 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='STarget1' Mode=Ticks Value=40 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='STarget2' Mode=Ticks Value=50 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='STarget3' Mode=Ticks Value=60 Currency=0 Simulated=False
9/24/2010 6:57:49 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target' Mode=Price Value=1040 Currency=0 Simulated=False
9/24/2010 6:58:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Target' Mode=Price Value=1001 Currency=0 Simulated=False
**NT** Enabling NinjaScript strategy 'FollowThroughDown/a23ee46d05784f3b9fab607ee65a5805' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=True EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=False MaxRestarts=4 in 5 minutes
**NT** Syncing account position on starting strategy 'FollowThroughDown/a23ee46d05784f3b9fab607ee65a5805'. Account position='1S ES 12-10' Strategy position=''
As soon as I enabled the script, it closed my position. Before I enabled the strategy, I was able to verify that the stop and profit targets were still there. Any ideas on what I'm doing wrong? Does it work differently when the broker side loses the connection but is still connected via NT? My problem is that my broker software (IB) automatically shuts down once every 24 hrs, so I invariably get a situation where it disconnects itself from NT.
Thanks,
Rich
NinjaTrader_Bertrand
09-24-2010, 09:41 AM
Rich, it flattens your account position because of a flat strategy position, hence the mismatch it corrects as auto sync is enabled -
**NT** Syncing account position on starting strategy 'FollowThroughDown/a23ee46d05784f3b9fab607ee65a5805'. Account position='1S ES 12-10' Strategy position=''
As you enable the strategy what would it show in the strategy's tab as it's position?
Thanks
richp6
09-24-2010, 09:56 AM
Before I enable the strategy, the strategy shows no open position. I thought it was supposed add 1 to the strategy position because the account position was 1. How am I supposed to configure NT so that it will start up where it left off when the strategy was disabled due to the disconnect? BTW, I'm running v7Beta.
NinjaTrader_Bertrand
09-24-2010, 10:05 AM
No, it will ensure the account position mirrors the strategy position - so if you're strategy is flat, the account will be 'flatted' > the needed sync is then there. If were not synching up, the strategy would have from the start on, as it would for example take your live account flat instead of replicating the long position the strategy may have entered.
1. Strategy: Flat - Account: 1 Short
2. Signal to go long from Strategy, so Strategy: 1 Long - Account : now flat, as you previously held a short
>> so sync lost.
richp6
09-24-2010, 10:21 AM
Ok, that now makes sense to me. So the million dollar question is why does the strategy lose its position when the disconnect happens? In theory, I would expect the strategy to show 1 ES and the account to show 1 ES, so when I start it back up, the strategy just picks up where it left off.
NinjaTrader_Bertrand
09-24-2010, 10:36 AM
Rich - what connection loss option are you working with in this scenario?
http://www.ninjatrader.com/support/helpGuides/nt7/connectionlosshandling.htm
richp6
09-24-2010, 10:43 AM
I have it set to keep running
NinjaTrader_Bertrand
09-24-2010, 11:40 AM
Rich, are you really experiencing a connection loss event or are you disconnecting manually from your IB account?
richp6
09-24-2010, 11:47 AM
I am disconnecting manually. I'm trying to recreate the scenario that would happen when a position is being held over several days. Let's say my strategy gets me into a position on Friday. IB's tradestation attempts to shut itself down once every 24 hrs (at the time I designate). So, do I need to make sure that the tradestation software never shuts down during this time (Sat, Sun) while nothing is going on to make sure my strategy is still running?
NinjaTrader_Bertrand
09-24-2010, 11:54 AM
Rich, you can't compare a manual disconnect & reconnect from a connection loss event producing the strategy 'Keep running' state. So you're seeing the exact same issue at TWS shutdown time when the strategy is working for you?
richp6
09-24-2010, 11:59 AM
I'm actually not sure, because when I experenced the problem for the first time, I didn't have all my settings set the way they are now. I'll test and get back to you next week.
NinjaTrader_Bertrand
09-24-2010, 12:01 PM
Ok great, sounds good - thanks for your support and testing and have a nice weekend.
richp6
09-28-2010, 08:46 PM
I tested it out, and when IB disconnects NT treats it the same as when I did a manual disconnect. Here is the log:
**NT** Strategy 'FollowThroughDown/631b9ca4bff6439cb2a60e1250718dcb' lost order connection but will keep running.
**NT** Strategy 'FollowThroughDown/631b9ca4bff6439cb2a60e1250718dcb' lost price connection but will keep running.
9/28/2010 7:00:02 PM CancelAllOrders: BarsInProgress=0
**NT** Disabling NinjaScript strategy 'FollowThroughDown/631b9ca4bff6439cb2a60e1250718dcb'
I'm trying some other methods to pick up the strategy with a little success. Let me know if NT comes out with some way to handle this.
NinjaTrader_Bertrand
09-29-2010, 11:49 AM
Hi Rich, thanks for the testing - the only idea I would have is changing the TWS shutdown time continuously to avoid running into this, I believe there's also a program available from a 3rd party that would help you achieve that.
daviddwilson
10-10-2010, 06:56 PM
Rich, you can't compare a manual disconnect & reconnect from a connection loss event producing the strategy 'Keep running' state. So you're seeing the exact same issue at TWS shutdown time when the strategy is working for you?
I'm actually not sure, because when I experenced the problem for the first time, I didn't have all my settings set the way they are now. I'll test and get back to you next week.
GiantHogweed
10-16-2010, 12:34 PM
David - I have similar problems using IB with a simulated strategy on NT7B22. My strategies carry positions for weeks at a time. I have been using a third party application called TWSStart that works most of the time. Generally I can leave IB one for weeks at a time without losing my connection to NT. Most of the problems I have are when my internet connections goes down during bad weather. At that point I have to restart NT, restart IB and hope that my accounts don't go out of sync with the strategies.
Question for NT - I have about 30 strategies that I am running in simulation. They work well except for the scenario described above; when I restart I get out of sync. I do have that strategies grouped into accounts so each account does not have more than one strategy in it that uses the same security. Therefore within each account I don't have to worry about strategies trying to go long and short at the same time.
In the help file I found the following function that would allow me to synch my strategies and accounts within the strategy, possibly in the OnStartup method:
int NTMarketPosition(string account)
Gets the market position for the selected instrument/account combination. Returns 0 for flat, negative for short and positive for long.
However this appears to only be valid for DLL integration?? Can I use this in Ninjascript code? If not this would appear to solve my problem and others as well. Can this be implemented in NT7 before release?
Also, I have another enhancement to suggest. I would like to see a totalized summary of positions PnL in the positions tab of the control center. These 30 strategies generate many positions and I would like to see the overall PnL instead of just seeing each security's PnL. At a minimum I would like to see a subtotal for each account. Currently I have to dump it to excel and totalize.
NinjaTrader_RyanM
10-16-2010, 02:59 PM
Hello Gainthogweed,
Thank you for your suggestions.
Unfortunately there aren't supported NinjaScript methods for capturing an account position. This isn't something that will make it prior to beta release but something we may consider in the future.
For PNL reporting have you looked at the account performance feature? This will allow you to generate reports based on specific instruments, or accounts.
http://www.ninjatrader.com/support/helpGuides/nt7/account_performance_tab.htm