NinjaScript diagnostics

2 min read

How to log price-feed and order connection changes in NinjaTrader

When prices stop updating, a connection can still report Connected on the order side. A short indicator callback records what each side reported at the time.

Illustration of a two-pen recorder drawing a steady teal line while an orange line drops and returns.

Quick answer

In OnConnectionStatusUpdate(), read Status for the adapter’s main function and PriceStatus for the price feed. For an adapter that supports live orders, Status describes its order system. Log both values with their previous values and the connection profile so you can see which side changed.

Print one line for each connection change

Add this override inside a custom NinjaScript indicator class. If the class already overrides OnConnectionStatusUpdate(), add the logging lines to that method. The time includes your computer’s UTC offset and records when the callback ran. The profile name identifies the connection when several are open.

protected override void OnConnectionStatusUpdate(
    NinjaTrader.Cbi.ConnectionStatusEventArgs e)
{
    var profile = e.Connection.Options.Name;
    Print($"{System.DateTimeOffset.Now:O} | {profile}" +
          $" | adapter {e.PreviousStatus} -> {e.Status}" +
          $" | prices {e.PreviousPriceStatus} -> {e.PriceStatus}");
}

Read the two transitions on the same line

Compile the indicator and add it to a chart. From the Control Center, choose New → NinjaScript Output. Read the tab selected by the indicator’s PrintTo setting. To keep a record, right-click that tab and choose Save As.

  • If a line reads “adapter Connected -> Connected | prices Connected -> ConnectionLost,” the price feed reported a loss while the adapter’s main connection stayed connected.
  • If a live-order adapter reports “adapter Connected -> ConnectionLost | prices Connected -> Connected,” the order connection reported a loss while the price connection stayed up. On a data-only adapter, interpret Status according to that adapter’s function.

When the feed says Connected but a chart is still

PriceStatus applies to the connection. To check whether a particular contract is receiving updates, look for an OnMarketData() event for that instrument. Match the event type to the question. A bid or ask update shows quote activity. A Last event records a trade update.

The callback above records connection changes. For a chart that stays still without a connection event, continue with the chart troubleshooting guide below. If a strategy disabled itself during the interruption, use the separate strategy recovery guide.

Official sources

Connection alerts

Get an email when a connection drops

Ninja Watchdog can monitor NinjaTrader connections on your Windows desktop or VPS and email you when a connection drops.

Try Ninja Watchdog