NexusFi: Find Your Edge


Home Menu

 





NinjaTrader Crash Recovery


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one TraderDJB with 6 posts (0 thanks)
    2. looks_two MXASJ with 3 posts (0 thanks)
    3. looks_3 zeller4 with 1 posts (0 thanks)
    4. looks_4 kandlekid with 1 posts (0 thanks)
    1. trending_up 5,897 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 12 posts
    2. attach_file 1 attachments




 
Search this Thread

NinjaTrader Crash Recovery

  #1 (permalink)
 
TraderDJB's Avatar
 TraderDJB 
Michigan
 
Experience: Intermediate
Platform: NinjaTrader, TradeStation, Thinkorswim
Broker: MB Trading
Trading: Forex
Posts: 46 since Jan 2010
Thanks Given: 7
Thanks Received: 28

In testing and using NinjaTrader, there have been many times that it has crashed on me. If I'm running a strategy live and NT or the computer crash, I'm concerned that I'll have to manually close open positions and then restart the strategy. Have any of you had experiences like this? Is there a way to allow the strategy to keep going where it left off?

I've been thinking, if I could reload the IOrders during "protected override void OnStart()" (only called right before the strategy goes live, after it does the quick backtest on the Days2Load), the strategy could continue where it left off. It wouldn't be hard to have all "!= null" IOrders printed into an XML file every 5 minutes using the code attached, or to read the file if "bool recoverPastTrades == true" but... IOrders are a read only interface, and not a class. That's where my programming ability ends - does this sound like a good idea? How could I create a new IOrder without actually sending it from "EnterOrder()"?

Oh, and it would want to check that the sum of all IOrders.Filled in the file == Account current quantity - in case an order was generated that didn't make it into the file and handle it if one didn't.

- DJB

Do or do not, there is no try. - Yoda
Attached Files
Elite Membership required to download: H2Configurator.zip
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #3 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404


DJB -

No idea if this would be something that could help or if you already used it. Your programming with dlls is way beyond my capability...

 
Code

RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;

Good luck with your solution, whatever it may be.

Kirk

Reply With Quote
  #4 (permalink)
 
TraderDJB's Avatar
 TraderDJB 
Michigan
 
Experience: Intermediate
Platform: NinjaTrader, TradeStation, Thinkorswim
Broker: MB Trading
Trading: Forex
Posts: 46 since Jan 2010
Thanks Given: 7
Thanks Received: 28

Thank you for your input. That helps in terms of keeping it going, but what I'm talking about is restoring it if the worst happens - NT completely crashes. We'll see.

Do or do not, there is no try. - Yoda
Started this thread Reply With Quote
  #5 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Are you on NT7? FWIW I'm finding the following is good to help prevent a crash:

- If I'm doing a lot of coding/compiling through the day memory usage increases and is not released. A fresh restart of Ninja is a Best Practice before going live. The same would apply for Backtesting (ie if you have been backtesting all day its worth a restart before going live).
- If I'm live and for some reason I have to do a lot of disable/enable with Strats, memory usage increases and is not released. I may restart Ninja at an appropriate time during the trading session.
- A daily or weekly reboot of the host PC is a Best Practice.

I'm considering adding some code to a Strat that will monitor memory usage every n time period and alert me if a threshold is crossed. That would allow me to flatten/restart to prevent a crash while I'm live.

I haven't had to do this yet (luckily!), but if I had a crash and I had any positions on that were not long term, I'd call the broker and direct them to flatten everything.

Memory usage in NT7 is my pet project this week . I'm trying both forced Garbage Collection and looking at which methods have a Dispose() thing going and how to take advantge of that. Also starting to wonder if its time to move to a 64 bit platform...

Reply With Quote
  #6 (permalink)
kandlekid
College Point, NY (Queens)
 
Posts: 63 since Nov 2009
Thanks Given: 5
Thanks Received: 20

Typically, for a crash such as you describe, you would have the exchange send over the orders, with their current state. You'd then have the correct state of each, etc. This is similar to a reconciliation. Re-loading anything on the client side w/o access to the destination (i.e. w/o consulting the exchange of record) does not reflect the current state of the orders.

Reply With Quote
  #7 (permalink)
 
TraderDJB's Avatar
 TraderDJB 
Michigan
 
Experience: Intermediate
Platform: NinjaTrader, TradeStation, Thinkorswim
Broker: MB Trading
Trading: Forex
Posts: 46 since Jan 2010
Thanks Given: 7
Thanks Received: 28

Thank you, both of you.

MXASJ, please do share with what you come up with for the memory freeing functions - I use all 64 bit and NT still does the same in terms of accumulating memory being used.

kandlekid, I'm looking into getting the orders from the broker that are active through NT - it's not official supported, supposedly.

Do or do not, there is no try. - Yoda
Started this thread Reply With Quote
  #8 (permalink)
 
TraderDJB's Avatar
 TraderDJB 
Michigan
 
Experience: Intermediate
Platform: NinjaTrader, TradeStation, Thinkorswim
Broker: MB Trading
Trading: Forex
Posts: 46 since Jan 2010
Thanks Given: 7
Thanks Received: 28

Update: I have successfully accessed from within the strategy the global values that are listed in the Executions, Positions, and Accounts tabs using this code:

 
Code
// To access Executions or Accounts, replace "Positions" with the appropriate change.
                Print("Positions: " + Account.Positions.Count);
                System.Collections.IEnumerator Test = Account.Positions.GetEnumerator();
                for (int i = 0; i < Account.Positions.Count; i++)
                {
                    Test.MoveNext();
                    Print("Current" + Test.Current);
                }
It seems that the current status of the broker isn't kept into separate orders that the strategy placed but rather is the running sum. So, I'll have to have the strategy infer based on the current quantity and direction (long/short) where it is at then it will know for sure. Since it uses multiple orders of fixed sizes, it won't be hard to infer how many it has active to match the broker position.

It still doesn't solve how to recreate the IOrder... but I suppose the strategy doesn't need to, it could keep track at that point by something else instead of IOrder == null...... more updates to come.

Do or do not, there is no try. - Yoda
Started this thread Reply With Quote
  #9 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


TraderDJB View Post
Update: I have successfully accessed from within the strategy the global values that are listed in the Executions, Positions, and Accounts tabs using this code:

 
Code
// To access Executions or Accounts, replace "Positions" with the appropriate change.
                Print("Positions: " + Account.Positions.Count);
                System.Collections.IEnumerator Test = Account.Positions.GetEnumerator();
                for (int i = 0; i < Account.Positions.Count; i++)
                {
                    Test.MoveNext();
                    Print("Current" + Test.Current);
                }
It seems that the current status of the broker isn't kept into separate orders that the strategy placed but rather is the running sum. So, I'll have to have the strategy infer based on the current quantity and direction (long/short) where it is at then it will know for sure. Since it uses multiple orders of fixed sizes, it won't be hard to infer how many it has active to match the broker position.

It still doesn't solve how to recreate the IOrder... but I suppose the strategy doesn't need to, it could keep track at that point by something else instead of IOrder == null...... more updates to come.

Very interesting...

If you are wondering about memory consumtion, try this in OnStartUp() and enable/diable a few times:

 
Code
                            
Print("Strategies in cache: " Account.Strategies.Count);
System.Collections.IEnumerator Test2 Account.Strategies.GetEnumerator();
for (
int i 0Account.Strategies.Counti++)
{
Test2.MoveNext();
Print(
"Current Strategies: " Test2.Current);


Reply With Quote
  #10 (permalink)
 
TraderDJB's Avatar
 TraderDJB 
Michigan
 
Experience: Intermediate
Platform: NinjaTrader, TradeStation, Thinkorswim
Broker: MB Trading
Trading: Forex
Posts: 46 since Jan 2010
Thanks Given: 7
Thanks Received: 28


Right, that's the info displayed in the control panel tabs.

Do or do not, there is no try. - Yoda
Started this thread Reply With Quote




Last Updated on August 18, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts