Announcement

Collapse

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

Collapse

Attempt to enter order during ConnectionLost

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

    Attempt to enter order during ConnectionLost

    Hi,

    I'm running a strategy that enters/updates order on the close of every bar.

    Last week, I ran into an issue when it attempted to update orders during a connection lost, which resulted in the strategy disabling itself. The worst bit was that any the existing orders were not cancelled, which leaves me completely exposed.

    My On Connection Lost settings under Options - Strategies - Ninjascript tab is attached.

    How do I stop my strategy from submitting any order updates during a connection lost? My goal here is to let the strategy keep running, but without order updates/submission, until the connection is re-established, and then the strategy can resume.

    I've read through the Help Guide, and suspect the solution might be in OnConnectionStatus(), but the documentation is really sparse here and I have no idea on how to achieve the above.

    Any help is much appreciated.

    Thank you.


    Attached Files

    #2
    Hi nicbizz, thanks you for your quesiton.

    The OnConnectionStatus() method works like any other even method in NinjaTrader. Add this code at the class level of your script to override the method as a starting point:

    e.g.

    protected override void OnBarUpdate()
    {
    ///...
    }

    protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
    {
    if(orderStatus == ConnectionStatus.Connected)
    Print("Connected" + " " + DateTime.Now);

    if(orderStatus == ConnectionStatus.Connecting)
    Print("Connecting" + " " + DateTime.Now);

    if(orderStatus == ConnectionStatus.ConnectionLost)
    Print("ConnectionLost" + " " + DateTime.Now);

    if(orderStatus == ConnectionStatus.Disconnected)
    Print("Disconnected" + " " + DateTime.Now);

    }

    In the example in the OnConnectionStatus() documentation a ConnectionStatus variable is also held at the class level and updated each time OnConnectionStatus is called. That kind of variable can be used in OnBarUpdate to say "if not connected, don't submit the order".

    Please let me know if I can assist any further.



    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by helpwanted, Today, 03:06 AM
    1 response
    14 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    6 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    243 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    387 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X