Announcement

Collapse
No announcement yet.

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.



    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    60 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    145 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    161 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    97 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    283 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X