Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setup + Tear-Down

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Setup + Tear-Down

    I'm putting the final touches to a pretty complex hedge fund strategy I've been working on for about 2 months. Its pretty big - about 30 classes, four Inversion of Control Containers, three data processing pipelines, each with scanners, parsers, aggregators, repositories, multiple sub-strategies for scoring, risk-managment, position-sizing and scaling, it even has web service proxies for grabbing external data and a load of other stuff. This could turn into SkyNet and destroy the world.

    I am struggling a bit with one aspect though - set up and tear down. There's obviously a lot to set up when the strategy is first loaded, then when it starts to run over historical data there's a whole load of data structures built up and a significant internal state to be maintained.

    Unfortunately when I "reload ninjascript" or switch timeframes or instruments without closing the chart or deleting the strategy it reloads with remnants of the previous state and sometimes the instance hangs around for quite some time throwing up errors when I access the strategy dialog for example. I don't ever want anything to be re-used, I want everything to be destroyed and re-made every time.

    I wrote the attached strategy to print out the object hashcode, managed thread id and a bunch of other info for every state transition. Objects which are supposed to be "terminated" seem to come back to life and oddly it seems like the previous instance of a strategy is fired-up to start the new one. Is it spawning instances of itself?

    Just when I think I've terminated one strategy it comes back to life and tries to access its resources again and starts throwing up loads of errors. It seems like "terminated" for a Ninja Strategy actually does not mean terminated, more like asleep?. If I am super aggressive with my disposal of resources (in the terminated state) I can't get it started again - loads of NullReference exceptions.

    If I'm relaxed about it - I end up with hangover state from the previous run. Sometimes Even with no strategies listed in the strategy window I start getting null reference exceptions thrown from the strategy - just opening the strategy window throws up a ton of errors because there's a half-dead zombie instance hanging around.

    Is there any way I can do a clean set up and tear down a strategy every time? When the strategy stops I want the object garbage collected and to disappear forever. I don't want it trying to access its past corrupted state, or printing out errors when it tries to do so I don't want it to try to launch new instances of itself - I want it gone, forever - whats the best way to ensure this?
    Attached Files

    #2
    Hello,

    Thank you for the post.

    I just wanted to post a quick reply to let you know I will be reviewing the comments and provided script and reply back once I have.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      With regard to this query.... I've discovered that the "Reload Ninjascript" option on indicators and strategies does not have the same effect as explicitly loading and unloading the strategy and indicator. It leaves things in a corrupted internal state for me.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      4 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Brevo, Today, 01:45 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rjbtrade1, 11-30-2023, 04:38 PM
      2 responses
      73 views
      0 likes
      Last Post DavidHP
      by DavidHP
       
      Started by suroot, 04-10-2017, 02:18 AM
      5 responses
      3,021 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Stanfillirenfro, Today, 07:23 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X