Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90


Automated Trading Interface - Control From Within A Strategy

  • Filter
  • Time
  • Show
Clear All
new posts

    Automated Trading Interface - Control From Within A Strategy

    I'm trying to access the Automated Trading Interface ( NinjaTrader 8 ) from within a strategy. Preferably the DLL method. Some sample code would be much appreciated.

    My use case: Sometimes my connection to IB will disconnect and on occasion my strategy will disconnect and when it comes back up not be in sync. I realize there is auto sync options but none of those have worked for me (I've tried it all). So instead, I can have my strategy do a lookup on the ATI to see if I'm still in a hand and proceed from there.


    Hello bc24l,

    Thanks for your post.

    The DLL interface is used to have external apps interface with NinjaTrader. Order submissions can be made from here and ATM strategies can be started as well. The DLL interface does not allow starting NinjaScript strategies or interacting with them.

    The DLL interface is also provided as-is and support is limited to the resources available below. Please note that my colleague Chelsea's example is not officially supported by NinjaTrader.

    DLL interface -

    Example application (Unsupported example) -

    If your strategy disables from a disconnection, you would not be able to start it from the DLL interface, and we would not suggest trying to hook into the DLL interface through NinjaScript.

    If the issue is involving a strategy sync issue in the event of a disconnect, I suggest working through that instead.

    If you set Connection Loss Handling to Keep Running and set Disconnect Delay seconds to a high value, the strategy will stay running and would only fall out of sync if orders were filled during the disconnection. (This can be set in the Control Center under Tools > Options > Strategies)

    If the strategy gets disabled, you can re-enable it with ImmediatelySubmit and it will process historical data and attempt to match the orders calculated from historical data with live working orders. If the orders match, they will resume, otherwise, the live orders will be cancelled and replaced with those calculated from historical data.

    Another option to consider would be to program the strategy to use AdoptAccountPosition so when you enable the strategy, it inherits the active account position. I have attached some examples.

    For the thread's reference I have linked our Syncing Account Positions page of the Help guide.

    Please let me know if you are experiencing any issues involving syncing strategies, we will be happy to assist further.
    Attached Files
    JimNinjaTrader Customer Service


      Thanks for the info Jim. Can you provide an example of how I can access NTDirect.dll from within NinjaScript? Is that possible?


        Hello bc24fl,

        We do not have a such an example and we would not suggest trying to hook into the DLL interface through NinjaScript.

        The DLL interface is designed for external applications to interface with NinjaTrader. NinjaScript AddOn Framework would be better suited for the same sort of automated trading functionality but run directly from the platform.

        AddOn Framework Account class -

        Note: Neither the DLL interface or AddOn Framework allow starting NinjaScript strategies.
        JimNinjaTrader Customer Service


          Thanks Jim. Instead of access NTDirect.dll (I realize it was a hack.. but it was temporary), I was able to get the account position info from the Account class. Didn't realize the strategy is capable of knowing the account info even though it had been disconnected & reconnected. Thanks!


          Latest Posts


          Topics Statistics Last Post
          Started by DerkWehler, Today, 11:35 AM
          10 responses
          Last Post DerkWehler  
          Started by tkaboris, Today, 01:42 PM
          1 response
          Last Post NinjaTrader_Jesse  
          Started by dbennett3, Today, 01:59 PM
          0 responses
          1 view
          Last Post dbennett3  
          Started by webus, Today, 06:22 AM
          4 responses
          Last Post webus
          by webus
          Started by DayTradingDEMON, 07-11-2024, 08:54 AM
          16 responses
          Last Post DayTradingDEMON