← Back to Documentation Hub
PSX Risk ManagementCircuit Breakers Ready

Hybrid Stop-Loss & Circuit Breaker Mechanics

How the bot combines hardware exchange orders with software gap-down guards to protect your capital on the Pakistan Stock Exchange.

Why PSX Stop-Loss is Different (In Plain English)

Unlike crypto or forex where markets run 24/7 without limits, the Pakistan Stock Exchange (PSX) enforces strict daily price limits called Circuit Breakers (+7.5% upper limit and -7.5% lower limit). Furthermore, once you place a Stop-Loss order at a PSX broker, your shares become "locked" by that order.

Our bot uses a Hybrid Risk Model: it places a physical Stop-Loss order on the broker's exchange servers for offline protection, while our intelligent software monitors for gap-downs and automatically releases locked shares before taking your profits.

Layer 1: Hardware Broker Order (type: 4)

The instant your BUY order is filled at PSX, the bot automatically sends an official ORDER_TYPE_STOP_LOSS (type: 4) command to the StockIntel broker servers.

Offline Safety: Because the order lives directly on the exchange servers, your capital is protected even if your internet disconnects, your Node.js server restarts, or TradingView goes offline.

Layer 2: Software Gap-Down Guard

If bad market news causes a stock to open the next morning with a "Gap-Down" below your Stop-Loss trigger price, standard broker orders will get rejected or frozen.

Smart Circuit Defense: Before placing an order, the bot checks if currentPrice <= stop_loss. If a gap-down occurred, it halts automation for that share, marks status as MANUAL_INTERVENTION_REQUIRED, and emails an urgent alert to your inbox.

Stop-Loss & Take-Profit Lifecycle Diagram

Step 1: BUY Order Fills at 15.00 PKR (500 Shares)
Bot checks: Is Price already below Stop-Loss (14.50 PKR)?
YES (Gap-Down Crash)
Halt automation & email urgent alert
NO (Normal Path)
Place Broker Stop-Loss (type: 4) at 14.50

Real-World Example: Trading 500 Shares of TPLP

Here is a concrete timeline of how the bot handles a trade on Taseer Properties (TPLP) from initial entry to exit:

Time / EventWhat Happens in PSX MarketWhat the Bot Does Automatically
10:00 AM — BUY SignalTradingView sends BUY signal for TPLP at 15.00 PKR.Calculates affordability, places BUY order for 500 shares.
10:00:02 AM — Broker FillsBroker confirms 500 shares bought at 15.00 PKR.✅ Immediately sends Broker Stop-Loss (type: 4) at 14.50 PKR and stores active_stop_order_id.
Scenario A — Take-Profit HitTPLP rises to 15.80 PKR. TradingView sends SELL signal.2-Step Auto Sequence:
1. Cancels active Stop-Loss order at broker so shares unlock.
2. Instantly executes SELL order at 15.80 PKR to lock in profit.
Scenario B — Stop-Loss HitTPLP drops to 14.50 PKR without TradingView signal.Broker automatically sells 500 shares at 14.50. Bot receives webhook, updates trade to CLOSED (BROKER_STOP_LOSS), and calculates fees.
Why the 2-Step Auto-Cancel & Execute Sequence is Critical

Many beginner algorithmic traders ask: "Why doesn't the bot just send a SELL order immediately when a Take-Profit signal arrives?"

In PSX, when you place a Stop-Loss order for 500 shares, the broker "pledges" or locks those 500 shares against that stop order. If you try to place another SELL order without cancelling the stop first, the broker will reject it with a "Shares already pledged by an open order" error.

Our v4.2 bot handles this automatically in milliseconds: it detects `active_stop_order_id`, sends a cancellation command, and as soon as the broker confirms cancellation, it fires your Take-Profit SELL order!

← Previous: The 5 Safety PillarsNext: Pyramiding & FIFO Lot Matching →