Strategy Position and Sync Issues

Hi All,

I have a strategy that I am testing on a sim account. But I’m having some issues that I don’t understand. My first issue is why the strategy is getting out of sync, and scond is how it can take a short position when my strategy only takes long positions?

My strategy is currently running on two different instruments (MES & MNQ) on the same sim account using NT brokerage data/connection. I am using OnBarClose and I have tried both WaitUntilFlat, and ImmediatelySubmit as the start behavior. I load 15-20 days worth of data on each chart. But occasionally the strategy is getting out of sync. This is the first issue I don’t understand.

I let the stratgey run all day, with no other programs running. But I do have a screen saver. Can this cause an issue with the chart data updating that effects the strategy? I have noticed that sometimes when I move the mouse and the system comes out of screen saver, the charts will look out of date and then update to the current data. Not sure if this is really the case or just a visual thing. Could this be the issue? If not this, could it be just a hardware issue running the software? My computer is only 2 years old and has 32Gb of RAM.

I have also noticed in the Log that it does lose the data feed connection occasionally. Most are less than 10 seconds and don’t seem to pose any problem. But some are a little longer than 10 seconds and the strategy will be disabled and restarted again once the connection is reestablished. Is this dropped connection typically an issue if its less than one minute of total time?

Another thing I don’t understand is how the strategy can take a short position when my strategy only takes long positions. I understand that if you use the Synchronize account option for Start Behavior, it could do this in an attempt to synchronize the account to the strategy. But can it do this if you do not use this option? I noticed today that my strategy had a short position, no short trade on the strategy showing, and no disconnect from the data feed longer than 2-3 seconds. Needless to say I’m confused by thia behavior.

Any help or suggestions is greatly appreciated. Its is frustrating to have a strategy you believe is good and want to test out, but cannot get it over these issues that don’t appear to have anything to do with the strategy logic itself.

Thank you,
Ray

Managed or unmanaged mode. Did you write your own strategy or did someone else?

What size bars are you running against. Minute or tick data?

What data series do you have loaded in your chart and strategy?

Personally I would only trade one instrument per strategy. And I prefer Immediately submit, synchronize account as the start behavior.

NT can get confused sometimes. Always a good idea to right-click the chart and Reload all historical data before starting a strategy.

Yes, Synchronize account will buy or sell if needed when the strategy starts to sync the account. If you do not choose to synchronize the account and the account isn’t flat when you start then anything is possible.

If the strategy code is not quite right even a long-only strategy could end up with an extra sell which could leave you in a short position rather than flat. For example, if you are Long 1 and your code incorrectly sells twice to close the position, then you’ll be Short 1.

If you’re getting frequent loss of connection, you can end up with problems. NT can crash or stop trading if the disconnects happen too frequently. The crashes are probably not supposed to happen, but the stopping is by design. NT usually recovers nicely from a single loss of connection though.

You might also want to clear out your cache folder just to make sure data is not corrupted. https://forum.ninjatrader.com/forum/ninjatrader-8/platform-technical-support-aa/1197750-how-to-clear-ninjatrader-8-db-cache-folder-folder

Sometimes, depending on how NT has been used, the database can get corrupted and a reinstall is the easiest thing. Just be sure to backup your NinjaTrader 8\bin\Custom folder. I usually make a copy of my entire NinjaTrader 8 folder before I do any reinstall or upgrade.

Honestly, after nearly 10 years of experience with NinjaTrader, doing a lot of custom Ninjascript with AddOns, etc. I’ve found that most of the time I’m the source of the problem. I’ve done something NT didn’t like. Granted this is easy to do and sometimes very hard to figure out how to fix. But systematic testing is the key. Make a copy of your strategy and strip it down to the essentials. Then add one additional thing back at a time and make sure that the behavior is what you expect with each step. NT is very powerful and for the most part very stable. But it’s easy to get something wrong that isn’t obvious.

1 Like

Hi Steve,

First, thank you for the response. Some really great information/questions, and I certainly have some things to look at.

To answer some of your questions, I am using Managed mode with a strategy I modified. I believe I picked up the basic logic from a download on the Ninjatrader user app share some time ago, but have modified the code over time. So I would say a combination of both.

I’m using two different bar types, 60 minute candles, and renko bars. I have two separate sim accounts that I run MES and MNQ with the candles, and then another sim account that I run MES and MNQ with renko as I have heard that using the same instrument on multiple strategies is definitely a no-no. I have seen this cause issues, so I separated the accounts to avoid this.

From what I have seen, both of them have had issues with syncing. I cannot say I have seen one have anymore of an issue than the other at this point.

I’m going to start looking at my code as you suggested to see if I can determine if it is something in there. I have some questions I’m hoping you can help or provide suggestions.

I think you can have as many sim accounts as you like, but I believe you are limited to only 4 in real trading with NT brokerage. Technically, since I only have 4 instrument/strategy combinations, I can have each one on its own account. Do you recommend this? The only reason I was hesitant with this is if I later want to expand by adding another instrument to either of my candle or renko strategies, I would have to go the route of having multiple instruments on a single account or I would be limited to only 4. I would think multiple instruments with a single strategy on a single account should work fine. This is why I have been trying to get it to work. Although it may have nothing to do with the issues I’m seeing, I’m curios as to whether you think this is a preferred route?

How do you manage order quantity. Right now I’m using a default quantity of 1 in the strategy code, but then in the strategy settings in the chart, I have selected 2 for testing as this is my current quantity preference. My goal was to be able to scale up using the Micros. Have you found that this has caused any issues? Or is it more likely that it’s only an issue because there is something else that is causing a problem?

I have seen some disconnects, but most are only a second or two and it looks like NT recovers nicely. I am going to clear out my cache and maybe even reinstall NT if I keep having issues. Do you clear out your cache on a regular basis? I use the NT brokerage CMEGROUP_TOP data feed. I don’t know if you use NT Brokerage, but I was curious if this is sufficient for trading MES & MNQ using an automated strategy?

Do you restart/reload your strategies every day or at a certain time? Is there a way to get NT to do this automatically? Have you seen this be a source of many syncing/performance issues?

Also, do you have a recommended amount of data to load (in days or something else)? I know it can affect your strategies results, but just curious if there was guidance or some rule others typically use.

I really appreciate any info or suggestions you can provide.

Thank you,
Ray