Engineering an Institutional ICT Intraday Trading Engine for NSE Equities

Discretionary intraday trading is notoriously susceptible to emotional pitfalls—hesitation on entries, premature profit-taking, and revenge trading during volatile market sessions. To eliminate behavioral friction, I engineered a mechanical, institutional-grade algorithmic intraday trading engine specifically tuned for National Stock Exchange (NSE) high-beta equities: BAJAJFINSV, DIVISLAB, and JUBLFOOD.

The engine automates the entire lifecycle: from liquidity discovery and displacement filtering to order routing via the Kotak Neo API and autonomous lifecycle monitoring as a background Linux daemon on Oracle Cloud Infrastructure (OCI).


1. The Quantitative ICT Strategy Framework

The engine converts Inner Circle Trader (ICT) market microstructure concepts into deterministic, quantifiable mathematical rules.

+-------------------------------------------------------------+
| 1. Liquidity Sweep Detection (Key Highs / Lows)            |
+-------------------------------------------------------------+
                              |
                              v
+-------------------------------------------------------------+
| 2. Displacement Validation (Candle Range >= 1.30x Baseline)  |
+-------------------------------------------------------------+
                              |
                              v
+-------------------------------------------------------------+
| 3. Fair Value Gap (FVG) Identification                      |
+-------------------------------------------------------------+
                              |
                              v
+-------------------------------------------------------------+
| 4. Limit Order on FVG Retest & Concurrency Verification     |
+-------------------------------------------------------------+

Market Microstructure Liquidity Sweeps

In high-beta Indian equities, institutional participants often require deep liquidity pools to fill significant order flow. These pools naturally accumulate just beyond recent swing highs and swing lows (where retail stop-loss orders congregate).

The engine tracks rolling 5-minute swing extrema. When price pierces an established swing level and rejects back into the prevailing range, the system tags a liquidity sweep event.

Institutional Displacement Filter

Not every sweep leads to a reversal; many are continuation breakouts. To differentiate between false breaks and authentic institutional sponsorship, the engine enforces a 1.30x displacement filter:

  • The candle expanding out of the sweep must demonstrate a true body range at least 1.30 times greater than the 20-period Average True Range (ATR).
  • Strong close: Bullish displacement requires a close in the upper 25% of the candle; bearish displacement requires a close in the lower 25%.

This filter ensures the system only enters when true institutional volume and aggressive market orders enter the order book.

Fair Value Gap (FVG) Retest Triggers

When displacement occurs, it frequently leaves behind an inefficient 3-candle price imbalance (a Fair Value Gap) where price moved too quickly for two-sided trading:

  • Bullish FVG: High of Candle 1 does not overlap with Low of Candle 3.
  • Bearish FVG: Low of Candle 1 does not overlap with High of Candle 3.

Rather than chasing price during expansion, the engine maps the FVG imbalance zone and awaits a controlled retest. Once price retraces into the gap, an entry trigger is generated.


2. Execution Mechanics & Risk Architecture

A quantitative edge is only as robust as the risk engine governing it. The system enforces strict capital protection parameters:

Asymmetric Profit-to-Risk Structuring

Every position is configured with an asymmetric 2.25:1 Profit-to-Risk target (2.25R):

  • Invalidation Level (Stop Loss): Placed strictly behind the displacement origin swing extreme. If price violates this level, the institutional premise is invalidated.
  • Take-Profit Target: Mapped directly to 2.25 times the initial risk distance.

Intrabar LTP Exit Monitoring

Standard candle-close exits suffer from severe slippage during sharp intraday volatility. The engine decouples its exit logic from candle close timers:

  • Sub-minute background threads poll live Last Traded Price (LTP) feeds.
  • If market price breaches the stop loss or reaches the 2.25R take-profit threshold, exit orders are triggered instantaneously intrabar.

Dynamic Position Sizing

Position sizing is dynamically calculated on every trade signal based on:

  1. Current account equity.
  2. Predetermined risk-per-trade percentage.
  3. Volatility distance between entry and the structural stop loss.
  4. Intraday MIS margin requirements.

This ensures that regardless of the nominal stock price (whether ₹1,500 for BAJAJFINSV or ₹4,000 for DIVISLAB), the portfolio's absolute downside per trade remains mathematically fixed.

Portfolio-Level Concurrency Locking

Correlated risk is a major failure point in intraday equity trading. If multiple stocks in the universe trigger simultaneous buy signals during an index impulse, taking all trades can over-leverage the account.

The engine implements a thread-safe portfolio concurrency lock:

  • When one asset enters a live position, the global lock engages.
  • Additional signals in other assets are systematically queued or ignored until the active trade reaches completion.

Zero Overnight Gap Risk (100% Cash Settlement)

All positions are purely intraday MIS. An autonomous square-off scheduler triggers 15 minutes prior to the NSE market close, ensuring zero exposure to overnight gap-downs, global macro events, or earnings announcements.


3. Autonomous Cloud Infrastructure

To eliminate reliance on local machines or spotty home networks, the engine is deployed as an autonomous Linux service on Oracle Cloud Infrastructure (OCI).

       +---------------------------------------------+
       |             OCI Linux VM (24/7)             |
       |                                             |
       |  +--------------------+   Token Auth        |
       |  |  Systemd Daemon    | <------------+      |
       |  +--------------------+              |      |
       |            |                         |      |
       |            v                         v      |
       |  +--------------------+     +-------------+ |
       |  | Core Algo Engine   | <-> |  Kotak Neo  | |
       |  | - Market Scanner   |     |  REST / WS  | |
       |  | - Risk Controller  |     +-------------+ |
       |  | - LTP Monitor      |              ^      |
       |  +--------------------+              |      |
       |            |                         |      |
       |            v                         v      |
       |  +--------------------+     +-------------+ |
       |  | Telegram Reporter  |     | NSE Equities| |
       |  +--------------------+     +-------------+ |
       +---------------------------------------------+

Kotak Neo API Integration

  • Automated Morning Auth: A headless script handles session initialization, TOTP generation, and token refresh prior to the 09:15 AM IST market open.
  • Order Routing: High-speed REST calls for limit and market order execution directly to Kotak's servers.

Self-Healing & Process Supervision

  • Systemd Service: Managed as a persistent daemon with automatic restart policies on abnormal exits.
  • Audit Logging: Every tick analysis, signal evaluation, and order event is recorded with millisecond timestamps for post-session trade analysis.
  • Live Telemetry: Real-time trade notifications, stop adjustments, and execution receipts are dispatched via a private Telegram webhook.

4. Key Takeaways

Engineering this engine reinforced fundamental principles in quantitative finance:

  1. Rule Determinism: Qualitative chart analysis must be broken down into unequivocal, rule-based algorithms to remove emotion.
  2. Execution Matters More Than Prediction: Microsecond LTP exits and strict concurrency locking protect equity far better than any directional bias.
  3. Infrastructure Is Strategy: High uptime, autonomous token refreshes, and cloud-native hosting turn a strategy from a hobby script into a production system.