Introduction: The Myth of 10% Daily Gains vs. Real-World Quant Engineering
When newcomers explore algorithmic trading, the most frequent aspiration is aggressive compounding — often asking for "10% daily returns." From a pure mathematical standpoint, compounding $1,000 at 10% per day turns into $17,449 in 30 days and an impossible $22.2 Trillion in one year (exceeding global GDP).
In quantitative finance, attempting 10% daily gains requires 50x–100x leverage, guaranteeing a 100% total liquidation within standard market pullbacks. Even the most successful quantitative hedge fund in history — Renaissance Technologies' Medallion Fund — achieved ~60% annualized returns. True quantitative edge comes from statistical rigor, strict position sizing, anti-chop regime detection, and systematic risk management.
In this post, we explore how to build a production-grade, 24/7 autonomous algorithmic trading engine running natively on an ARM64 Linux host, spanning 24/7 Crypto, US Tech Equities, and Indian Equities (NSE/BSE) with Zerodha Kite Connect execution.
1. System Architecture on Linux Edge Hardware
Running a 24/7 quant engine demands high reliability, low power consumption, and deterministic execution. We deployed the system on a Debian-based Linux environment (ARM64) running entirely in headless mode via systemd:
# Disable GUI/Display server to free 500MB+ RAM and save battery
sudo systemctl set-default multi-user.target
sudo systemctl stop phosh.service
# Dedicated 24/7 systemd unit with automated recovery
[Unit]
Description=Global & Crypto AI Quant Trading Engine (Port 5000)
After=network.target network-online.target
[Service]
Type=simple
User=droidian
WorkingDirectory=/home/droidian/Projects/global-trade-bot
Environment=PYTHONUNBUFFERED=1
ExecStart=/usr/bin/python3 /home/droidian/Projects/global-trade-bot/main.py
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
2. Market Microstructure & Structural Separation
A common pitfall in multi-asset trading bots is treating global crypto and regional stock markets identically. They have fundamentally different market microstructure:
- Crypto (24/7 Continuous Trading): Never closes. Highly volatile, prone to weekend low-liquidity chop and sudden liquidation wicks. Denominated in USD/USDT.
- Indian Equities (NSE/BSE): Strict trading window (09:15 AM to 03:30 PM IST, Mon–Fri). Denominated in Indian Rupee (INR ₹). Cash equity delivery requires integer share quantities without fractional splits.
To honor these structural differences, we partitioned the architecture into two dedicated services:
- Global & Crypto Engine (Port 5000): Scans BTC, ETH, SOL, AVAX, SUI, XRP, plus US large-caps (NVDA, AAPL, TSLA).
- Indian NSE/BSE Engine (Port 5001): Synchronized with an Indian Standard Time (IST) scheduler, active strictly during NSE market hours.
3. Quantitative Alpha Strategy: Wilder's RSI, ADX & ATR
Rather than using noisy simple moving averages, our strategy computes institutional-grade technical indicators:
# Standard Wilder's Smoothing for RSI (14)
delta = df['close'].diff()
gain = delta.clip(lower=0)
loss = -delta.clip(upper=0)
avg_gain = gain.ewm(alpha=1/14, adjust=False).mean()
avg_loss = loss.ewm(alpha=1/14, adjust=False).mean()
rs = avg_gain / (avg_loss + 1e-9)
df['rsi'] = 100 - (100 / (1 + rs))
# ADX (Average Directional Index) - The Anti-Chop Filter
# If ADX < 20, the market is in low-volume consolidation; block all entries!
if latest['adx'] < 20.0:
return {"signal": "HOLD", "score": 0, "reason": "Market in Sideways Chop"}
ADX >= 20 (and ideally >= 25) prevents the bot from over-trading during dead weekend ranges.
4. Dual-AI Consensus: Hard Math Meets Claude LLM Audits
A unique innovation in this architecture is the Dual-AI Consensus Engine. Instead of purely trusting quantitative indicators or blindly following an LLM, the system uses a hybrid approach:
- Antigravity (AGY) Quantitative Model: Calculates EMA 9/21/50 stack alignment, RSI momentum recovery, volume surges (>1.5x 20-MA), and outputs a numerical score from 0 to 100.
- Claude Code Real-Time Audit: If the quantitative score $\ge 70$, the bot calls Claude via local CLI to audit the candidate setup for potential bull/bear traps, liquidity fakeouts, and market regime conditions.
- Consensus Trigger: Orders only execute when both the mathematical model and Claude Code approve the setup with high conviction.
5. Capital Preservation & Micro-Account Risk Management
Testing algorithmic strategies on micro-capital ($10.00 USD / ₹1,000 INR) presents unique mathematical challenges. When trades have tight targets, exchange round-trip taker fees (0.15%) can turn breakeven trades into small losses.
We engineered three defensive mechanisms to protect capital:
- Wider Noise-Resistant Stops (2.2x ATR): Prevents normal market noise from triggering premature stop-outs.
- Auto-Breakeven Stop Lock: Once a trade reaches +1.0% profit, the stop-loss is automatically adjusted above the entry price + fees, guaranteeing a risk-free trade.
- Daily Drawdown & Consecutive Loss Circuit Breaker: If portfolio drawdown reaches 4% in a day, or 3 consecutive losses occur, trading halts automatically for the day.
6. Real-Market Execution via Zerodha Kite Connect API
For the Indian stock market, simulated paper trading can be transitioned to live execution on the National Stock Exchange (NSE) via Zerodha's official Kite Connect API:
# Live NSE Order Routing via Kite Connect
from kiteconnect import KiteConnect
kite = KiteConnect(api_key=CONFIG["zerodha_api_key"])
kite.set_access_token(session["access_token"])
# Place real Delivery (CNC) or Intraday (MIS) order on NSE
order_id = kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange=kite.EXCHANGE_NSE,
tradingsymbol="INFY",
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=1,
product=kite.PRODUCT_CNC,
order_type=kite.ORDER_TYPE_MARKET
)
The dashboard provides a 1-click OAuth login to authenticate with Zerodha daily, displaying real margin balances and allowing instant switching between Paper Simulation and Live Real-Money Trading.
7. Real-Time Telemetry & TradingView Candlestick Visualizer
Both trading bots embed TradingView Lightweight Charts directly into their browser interfaces. The dashboards stream live 15m/1h OHLCV candlesticks, volume bars, EMA ribbons, and dynamic horizontal price lines for Entry Price, Take-Profit Target (TP), and Stop Loss (SL).
A built-in Live AI Console Stream renders color-coded logs ([SYSTEM], [SCAN], [AI], [CLAUDE], [TRADE], [ZERODHA]) in real time, accompanied by instant notifications sent to Telegram.
Conclusion & Key Takeaways
Building an autonomous algorithmic trading system is a software engineering and risk management discipline. Key lessons from this project include:
- Regime Detection is Paramount: Filtering out low-volatility chop with ADX saves far more capital than trying to predict exact reversal points.
- Defensive Execution Beats Aggressive Leverage: Trailing stops and auto-breakeven locking protect gains as trends mature.
- Hybrid AI Architecture Works: Pairing quantitative formulas with LLM sanity checks reduces false breakout rates.