TradingView → NinjaTrader 8 Breakout Execution
Pine strategy, Python webhook bridge and NinjaScript strategy that turn fractal-breakout alerts into bracket orders on NinjaTrader 8, with both breakout sides resting at once.
The problem
The trader had a multi-timeframe fractal breakout strategy on TradingView and wanted it to place real orders in NinjaTrader 8. TradingView only sends webhooks to public HTTPS endpoints, and NinjaTrader has no webhook listener.
What I built
- Pine strategy: a lighter version of the breakout script that fires a flat JSON
alert()when each breakout order is placed, with entry, stop, target, quantity and order type. - Webhook bridge: a Flask server that checks a passphrase, accepts TradingView’s plain-text bodies, removes the passphrase, and relays the order to NinjaTrader over TCP.
- NT8 strategy: a TCP listener that parses the JSON and submits orders through the unmanaged API. Long and short breakout entries can rest at the same time. On a fill it places a stop and target as an OCO pair and cancels the other side.
- One-click launcher: a packaged Windows bridge app that starts the server and an ngrok tunnel and shows the public URL.
- Tests: a C# test for the JSON parser and an end-to-end Python test with a fake NinjaTrader listener, covering bad passphrases, missing fields, malformed JSON and an unreachable NinjaTrader.
Details
Testing found a real bug. The original parser matched a key by its first appearance in the text, so the "stop" key matched the value of "orderType":"stop". That would have placed broken brackets. Key matches are now anchored to a following colon, and a regression test covers the case.