All work
Client Case Study

5m Weapon: Live NATURALGAS Basket Strategy for a Client

A fully automated 5-minute weapon-candle strategy on MCX natural gas routing real orders to Dhan from a cloud VM.

FastAPI dashboard with typed arming, market-on-signal execution with a 3-second level loop, a persisted daily loss-cap latch, fill readback, a deploy script with auto-rollback and 66 tests; a state-based Pine indicator twin was added later.

5m Weapon: Live NATURALGAS Basket Strategy for a Client — illustration
What makes it serious
  • Live Dhan routing with typed arm and PAPER default
  • Persisted daily loss-cap latch checked in two loops
  • Deploy script with compile gate, health checks and auto-rollback
  • 66 pytest + 3 node checks; backtest of record 231 cycles documented

A client's discretionary "weapon candle" method on natural gas futures was turned into an unattended live system. The server-side engine watches 5-minute bars, builds the basket on signal and routes orders to the Dhan broker API, with a password-protected dashboard for arming, parameters and P&L. It ran live money from a cloud VM under systemd with a separate guardian service.

Several design choices came from incidents rather than theory. Dhan silently re-books resting stop orders as immediate limits, so everything is market-on-signal with a tight level loop and the engine, not the exchange, holds the stop. The trade book arrives as one row per exchange execution, so FIFO P&L keeps raw rows while display aggregates them. A daily loss cap is judged on realised plus fresh mark-to-market, and when breached a dated latch is persisted before the exit so arming and sending refuse until the date changes. Quantity units must be explicit after a 1,250x sizing scare, and only the service process may route orders after an ad-hoc import once traded the account.

The release path is a deploy script that refuses while armed or holding, backs up, compile-gates, restarts, health-checks and rolls back automatically. A later Pine v6 indicator encodes the state machine for charting and emits JSON alerts for the engine; its defaults measured negative on 5-minute data, and that was reported before anyone traded it.

Executes live broker orders for a client; shared as engineering work, not financial advice.

How it works

  1. Engine ingests 5-minute bars and detects the weapon-candle state
  2. Operator arms the day with a typed confirmation and a daily loss cap
  3. Signal fires: basket orders go to Dhan as market orders
  4. 3-second loop manages levels; fills are read back from the order book
  5. Loss cap or end-of-day flattens and latches; dashboard shows FIFO P&L
Stack
PythonFastAPIDhan APIsystemdGCPpytestPine Script v6
#mcx#natural-gas#dhan#live-trading#fastapi#risk-controls#client