From Pine Script to a Python Trading Platform

Custom TradingView indicators

From Pine Script to a Python Trading Platform

TickersWikipediaPricesbatched yfinanceScannerconfig-drivenvectorbtSL/TP backtestsBroker APIpaper bracket orders

This one started on TradingView. I’d been writing Pine Script indicators for years, custom divergence detection and trend filters, and they worked well enough that I kept bumping into the limits of what a charting platform lets you do. You can draw signals on a chart all day, but you can’t scan 500 tickers with them, and you can’t honestly test whether your idea would have made money. So I rebuilt the whole thing in Python.

First problem was data. The library I’d been using for ticker lists was dead, so the S&P 500 list now comes straight from Wikipedia and the price history downloads in batches through yfinance. Second problem was cost. The polished backtesting suites want real money for features like pattern similarity scanning, so I wrote my own rolling implementation. It’s not as fancy, but it’s free and I understand every line of it.

The scanner runs my divergence strategy across the whole index and flags setups. Entry conditions like trend filters are config driven, so I can turn ideas on and off without touching code. Backtesting runs through vectorbt with stop-loss and take-profit modeling, and every result gets benchmarked against just buying and holding. That last part matters more than people think. A strategy can look great in isolation and still lose to doing nothing. If you don’t test against buy-and-hold, you’re grading your own homework.

The newest piece is a bridge to a brokerage API for paper trading. It places bracket orders with position sizes based on risk, not gut feel, and it has a dry-run mode so I can watch what it would do before letting it do anything. I also ported the core strategy to NinjaScript along the way, which was a good exercise in finding out which parts of the logic were actually portable and which parts were quietly depending on platform behavior.

To be clear, this is an engineering project, not financial advice. For me it’s the same instinct as putting a scanner on a car instead of guessing from the sound. Data beats hunches, and if the tool to get that data doesn’t exist or costs too much, I’d rather build it.