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 kempotrader, Today, 08:56 AM
    0 responses
    6 views
    0 likes
    Last Post kempotrader  
    Started by kempotrader, Today, 08:54 AM
    0 responses
    4 views
    0 likes
    Last Post kempotrader  
    Started by mmenigma, Today, 08:54 AM
    0 responses
    2 views
    0 likes
    Last Post mmenigma  
    Started by halgo_boulder, Today, 08:44 AM
    0 responses
    1 view
    0 likes
    Last Post halgo_boulder  
    Started by drewski1980, Today, 08:24 AM
    0 responses
    3 views
    0 likes
    Last Post drewski1980  
    Working...
    X