PSX Trader: Stock Signals, Backtests & Broker Terminal
Live at psx.jiddatlabs.comOutcome
A live site that keeps two years of PSX data complete and repairs its own gaps every night, scores every stock and backtests each on demand, and re-ranks Q9's monthly list for a paper book that trades it without real orders. Members who add a broker login get a terminal in the browser whose balance and fills flow back to the site. The signals are offered as decision support, not as a strategy that beats the market.
Overview
A self-hosted research and trading dashboard for the Pakistan Stock Exchange, for investors whose sign-up an admin approves. Each night it pulls PSX's data portal into PostgreSQL: daily market summaries back to 2020, the symbol directory and screener, circuit-breaker bands, every company announcement since 1998 and seven index series. Through the trading day it also stores 15-minute bars for about 180 liquid stocks. A signal engine of 46 weighted technical rules scores every stock, and a backtester replays its signals at the next session's open, with costs, an ATR stop and PSX's daily price limits.
Signals only mean something if the price history is right, and PSX's daily files carry raw prices: splits and bonus issues showed up as fake one-day crashes, 558 of them in charts, signals and backtests. Prices are now back-adjusted from PSX's restated previous close, and small bonuses, which a price-gap rule can't tell from a cash dividend, from the announced ratio. Signals fire when a condition first turns true, not on every day it stays true, which took one stock's entries over 2020–25 from 301 to 44, and correlated trend rules count once instead of stacking.
Nothing places orders by itself. Each user who saves a broker login gets a Docker container running the brokerage's own desktop trading terminal, opened in the browser through noVNC; Caddy checks every request with the app, so nobody reaches another user's screen. A Java agent inside the terminal signs it in, restarts it before the broker's two-hour sign-out and reads holdings and cash off the screen, while fills come from its trade log. Walk-forward research found the engine's signals don't beat holding the KSE-100; the best strategy it found, Q9, a monthly 20-stock quality ranking, beat the index in backtests over 2023–26 and is paper-traded before any real money.
Architecture & Pipeline
01
Market Data Ingest
Python · 6 PSX feeds · raw files cached
- Python
02
Adjusted Price History
PostgreSQL · splits & bonuses
- PostgreSQL
03
Signal Engine
Pandas · NumPy · 46 weighted rules
- NumPy
- Pandas
04
Backtester
Next open · ATR stop · price bands
05
Q9 Ranking & Paper Book
Monthly 20 · no real orders
06
Dashboard
Flask · Chart.js · Caddy HTTPS
- Flask
07
Broker Terminal & Sync
Docker · noVNC · Java agent
- Docker
- Java
End-to-end flow, in order. Scroll sideways on a narrow screen.
Key Features
- Six PSX feeds, each synced on its own so one failing endpoint degrades only that feed, and every dated feed kept complete over two years, with the KSE-100's own bars as the trading calendar so market holidays aren't refetched as gaps
- Splits and bonus issues back-adjusted from PSX's restated previous close, backfilled across 1.27 million rows for 2020–26, with small bonuses matched to their announced ratio because a price-gap rule can't tell a 10% bonus from a cash dividend
- Signal engine of 46 weighted rules (23 to buy, 23 to sell) over EMA, RSI, MACD, ATR, ADX, Bollinger and Stochastic indicators and candlestick patterns, run on the 492 stocks in a day's 1,048 symbols once futures and debt are left out; buys need a confirmed multi-timeframe uptrend
- Backtester that fills at the next session's open with costs on both sides, enforces the ATR stop against each day's low, won't fill outside PSX's recorded circuit-breaker band, and compares 11 strategies with buy-and-hold over any window from a week to all history
- Q9, a monthly 20-stock quality ranking re-ranked nightly, with a rebalance plan per user (whole shares, limits clamped to PSX's band) and a paper book trading it with no real orders
- A broker terminal per user: the brokerage's Java Web Start trading app, which runs only on Oracle's JRE 8u341, in its own Docker container on a TigerVNC screen opened through noVNC, with Caddy asking the app before every request so each user reaches only their own
- A Java agent inside the terminal signs it in with the user's Fernet-encrypted login, restarts it before the broker's two-hour sign-out and reads holdings and cash off the screen; fills come from its trade log, matched FIFO, net of costs
- Login wall with admin-approved sign-ups, TOTP two-step sign-in (required before a broker login can be saved), CSRF tokens and per-IP rate limits, plus an admin area with 12 alert rules, nightly database backups and over 200 automated tests