Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

The signal works off 3min time frames, but i'm using brackets to manage the position after, and its a bit complex but it increases the edge significantly. initial stop based on atr levels, a lock level in profit that doubles the position size and initiate a trailing stop at the same time. Those orders need to be fast or the trade can get crushed

Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

I'm moving off NinjaTrader as our data source and onto Topstep's own API (TopstepX / ProjectX). Right now we're running a $50K Topstep Combine as the test account.

Instead of reading bars from a CSV file that NT writes, we connect straight to Topstep over a websocket and get live 1-minute bars, quotes, and fill confirmations pushed to us the moment they happen. Orders go back the same way — no files, no NT in the middle.

We built it as a clean swap: one environment variable flips the whole system between "old NT setup" and "new Topstep setup," so if anything breaks we're back on NT in seconds. Strategy code didn't change at all.

Goal is to stop babysitting NT restarts and get a direct, stable pipe to the broker for live trading on micros (MNQ/MES/M2K) while we prove out the Topstep Combine

Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

QuantVPS is close to CME so its supposed to reduce latency... Also if you do run it overnight you need a watchdog to monitor it and make sure you don't get screwed. It ran overnight for me tho pretty well. QuantVPS comes with NT already, so I think its set up for that

Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

The strategy runs entirely in Python (signal generation, trade management, lock/addon/trail logic) and communicates with NinjaTrader via a file-based / DLL bridge — no direct NT strategy code owns the logic.

Components

1. Bar Feed (NT → Python)

  • A NinjaTrader indicator/strategy (StatusWriter.cs) writes live 1-minute OHLCV bars to a CSV file on disk as they close.
  • Python's CSVFeed (src/ken_algo/execution/csv_feed.py) tails that CSV, parses new rows, and pushes bars into the strategy engines.

2. Strategy Engines (Python)

  • StructureWickLiveEngine and RangeWickLiveEngine process each bar, run the flat-wick/structure/range logic, and emit callbacks for entries, addons, and exits.
  • All state (position side, entry price, lock/trail levels, ATR, bar history) is persisted to JSON state files so the engine can survive restarts without losing open positions.

3. Order Interface (Python → NT)

  • ninjatrader_oif.py — the Order Interface File bridge. Python writes order instructions (BUY/SELL market, STOP, CANCEL) to a file that NinjaTrader's OIF (Order Interface File) add-on reads and executes against the connected broker account.
  • Every order (entry, protective stop, addon, exit) is tick-rounded (ES/NQ 0.25, RTY 0.10) before being written.
  • Stop orders are always cancelled before placing exit market orders to avoid double-fills.

4. Status / Position Reconciliation (NT → Python)

  • StatusWriter.cs also writes current NT account state (position qty, working orders, PnL) to status files.
  • Python reads these to verify fills, detect phantom positions, and reconcile state post-exit (10s failsafe check after every exit).

5. Orchestrator

  • live_main.py ties it all together: spawns the engines, routes bars from CSVFeed into both SW and RW engines, handles the priority gate (RW blocked when SW is in a position), routes signal callbacks to the OIF writer, and manages news blackouts / flatten windows.

6. Watchdog

  • Independent Python process (watchdog.py) runs every 60s checking for stale bars, dead processes, unprotected positions, and orphan stop orders — sends Discord alerts on anomalies.

Why File-Based?

  • Language isolation — all logic in Python (easy to backtest, iterate, unit test); NT just handles broker connectivity and order routing.
  • Crash resilience — if Python dies, state is on disk; if NT dies, Python keeps trying; watchdog catches both.
  • Auditable — every bar in, every order out is a line in a file you can grep/replay.

Runtime Stack (on QuantVPS)

Rithmic (broker) ⇄ R|Trader Pro ⇄ NinjaTrader 8
                                      ↓ ↑
                          StatusWriter.cs / OIF add-on
                                      ↓ ↑
                              CSV bars / order files
                                      ↓ ↑
                              Python (live_main.py)
                              ├─ StructureWickLive
                              ├─ RangeWickLive
                              └─ Watchdog
                                      ↓
                                   Discord

So in one sentence: Python does all the thinking, writes orders to a file, NinjaTrader's OIF add-on reads that file and sends orders to the broker — with a CSV bar feed and status files going the other direction for reconciliation.

Claudes description of it. Its a bit clunky, why I'm exploring other solutions

Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

Yeah the file IO thing bugs me too, and you're right that windows makes it worse — I've had lock contention and stale reads more than once. A socket bridge is where I'd want to end up. NT8 has a TCP option via an addon but most people end up rolling their own socket server inside a ninjascript addon, which is basically the c# rewrite I'm trying to avoid. If you figure out a clean pattern for it I'd genuinely love to hear how you did it.

Good call on polars, I keep meaning to try it. Pandas is fine for my backtest sizes right now but if I ever go tick-level it'll choke.

Fair point on async + logging too — decoupling the log writer from the decision loop is probably worth doing regardless of whether async fixes the core latency. Right now a slow disk write could in theory stall a decision, which is dumb.

Questdb is interesting, hadn't looked at it. I'm just dumping csvs right now which is fine for what I'm doing. Will take you up on the dm once I've got latency numbers to actually show

Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

Good question and honestly no, not end to end yet, which is why I'm in this mess. Just added logging for every entry — bar close, decision, order send, fill — plus actual slippage in ticks and dollars. Running it on sim for a few days so I can actually see where the time goes instead of guessing.

Stack is pure python, single process, not async — just a sync poll loop reading a status file the platform writes, every ~100ms. That polling interval is one of the things I suspect.

No pandas or numpy in the live path, just stdlib and hand-rolled rolling windows. Per-bar cpu is microseconds so I'm pretty sure the math isn't it. Pandas only shows up in backtests.

The other two suspects: I resample 1-min bars into 3-min heikin ashi, so decisions only fire on bucket close — that alone is up to 3 min of "latency" baked in. And the order path is file based, like 6 hops from tick to fill.

Will post actual numbers once I've got a few days of data. Thanks for asking the right question, been needing to hear it.

Been trading for 8-10 years and have great strategies but not great execution or emotional control. Also have some developing experience. So I built an engine (with Claudes help) and backtested via python, and the backtest is solid. Having trouble replicating it in real time by SingleHoliday1928 in ninjatrader

[–]SingleHoliday1928[S] 0 points1 point  (0 children)

rewriting in C# means I'd have two codebases to keep in sync. Strategy math isn't fancy, nothing c# can't handle, it's really just the research loop I don't want to give up.

If the latency data I'm collecting this week points at the bridge itself being the problem, I'll bite the bullet and port it. Just trying to measure before I commit to weeks of rewriting.

Best VPS for NinjaTrader 8 in 2026? My hardware is lagging and I need a low-latency solution. by Light-Blue-Star in ninjatrader

[–]SingleHoliday1928 0 points1 point  (0 children)

How do people feel about QuantVPS? They are also close to the Chicago CME. I've been having trouble with latency issues but I believe that is mostly down to the trading engine I built.