Paper Trading Hardening Guide

This guide covers stale-price protection and the new paper-trade viability engine: graded viability scoring, manual override modes, minimum meaningful edge, adaptive context-aware edge, configurable volatility floor, and how to use these settings safely in production versus testing.

1 — What Changed At System Level
Stale Price Protection
  • Cached prices are checked for age before return.
  • Stale prices log warnings but do not block trades.
  • MCX alias path uses the same protection.
Viability Engine
  • Binary cost filter evolved into graded scoring.
  • Uses per-share efficiency instead of total-size distortion.
  • Blocks low-edge and tiny-absolute-edge trades.
Manual Override Control
  • Manual detection is source/metadata-first.
  • STRICT / WARN / OFF modes supported.
  • Manual override affects viability only, not all risk checks.
2 — Stale Price Protection
How It Works
  • _get_current_price() reads cached price and timestamp.
  • If age is over 2 seconds, it logs [STALE PRICE].
  • Price is still returned. This is soft validation, not rejection.
if age > 2.0:
    logger.warning(f"[STALE PRICE] {symbol} → {age:.2f}s old")
return price
Why This Is Correct
  • Real brokers also operate through delayed or bursty ticks.
  • Blocking on every stale event causes missed trades and unstable behavior.
  • Logs give observability without disrupting execution flow.
Recommended: keep this warn-only
3 — New Viability Engine

The paper gate is now a graded decision engine. It combines cost realism, per-share efficiency, minimum meaningful edge, volatility-aware adaptive filtering, and safe manual override behavior.

Core Formula
per_share_profit = expected_move
per_share_cost = est_cost / qty
viability_score = per_share_profit / per_share_cost

dynamic_min_edge = volatility_unit * multiplier * qty
final_min_edge = max(min_expected_profit, dynamic_min_edge)

if expected_gross < final_min_edge:
    tier = "REJECT_ABSOLUTE"
Why Per-Share Is Better
  • Total-profit scoring is quantity-dependent and can mislead decisions.
  • Per-share scoring measures setup quality itself.
  • This makes comparison across cheap and expensive symbols more reliable.
Tier Rule Meaning Default Behavior
STRONG score ≥ 2.0 Clear edge after cost Allow
ACCEPTABLE score ≥ 1.2 Tradable but not elite Allow
WEAK score ≥ 0.8 Marginal edge STRICT uses configurable REJECT/WARN
REJECT score < 0.8 Poor cost efficiency Reject unless override or mode allows
REJECT_ABSOLUTE expected_gross < final_min_edge Too small to matter Hard reject
4 — Context-Aware Minimum Edge
Adaptive Edge Logic
  • Static floor alone is too rigid across quiet and volatile markets.
  • The engine computes a volatility-aware dynamic minimum edge.
  • Final filter uses the larger of static and dynamic minimum edge.
dynamic_min_edge = volatility_unit * 0.5 * qty
final_min_edge = max(min_expected_profit, dynamic_min_edge)
Volatility Proxy
  • If stop loss exists: volatility_unit = abs(entry - stop_loss)
  • Otherwise: fallback proxy from expected move and RR.
  • This gives ATR-like behavior without requiring new candle dependencies.
Minimum Volatility Floor
  • Ultra-tight stops can make volatility too small and weaken adaptive filtering.
  • The engine now applies min_volatility_unit = entry * min_volatility_floor_pct.
  • Default is 0.001 = 0.1%, configurable in the UI.
  • The setting is clamped to 0.0001 through 0.02 for safety.
min_volatility_floor_pct = max(0.0001, min(user_value, 0.02))
min_volatility_unit = entry * min_volatility_floor_pct
volatility_unit = max(volatility_unit, min_volatility_unit)
5 — Manual Override Modes
STRICT
  • Default production mode.
  • Rejects REJECT tier trades.
  • WEAK tier follows REJECT or WARN setting.
  • Manual override can allow manual-only non-viable trades.
WARN
  • Allows trades but logs viability tier and score.
  • Best for testing execution pipeline and monitoring behavior.
  • Do not use as default production mode.
OFF
  • Turns off viability scoring gates.
  • Useful only for troubleshooting or isolated experiments.
  • Risk logic outside viability still remains.

Important: manual override is not a trading edge. It is a testing convenience. Do not rely on override to justify poor signals.

6 — How To Configure It
Production / Auto Bot
  • Trade Quality Gate = ON
  • Non-Viable Mode = STRICT
  • Weak Tier Action = REJECT
  • Manual Override = OFF
  • Min Expected Profit = ₹100 or higher
  • Adaptive Min Edge = ON
  • Adaptive Multiplier = 0.5
  • Min Volatility Floor = 0.1%
Testing / Debug
  • Trade Quality Gate = ON
  • Non-Viable Mode = WARN
  • Weak Tier Action = WARN
  • Manual Override = ON only if needed
  • Keep minimum edge slightly lower to observe more cases
Asset Portability
  • Equities: start around 0.1% floor
  • Forex: can be lower, around 0.05%
  • Crypto: often needs 0.2% to 0.5%
  • Tune only after reviewing logs, not by intuition
7 — How This Helps Profitability
What Improves
  • Fewer trades where costs silently dominate edge.
  • Less churn in low-priced names with tiny targets.
  • More realistic paper results before live deployment.
  • Better net expectancy by removing weak or meaningless trades.
What It Does Not Do
  • It does not guarantee profitability.
  • It does not create edge if the strategy has none.
  • It does not replace good signal quality or market structure.

Real objective: fewer but better trades. A drop in trade count is usually healthy if net expectancy, realized Sharpe, and cost efficiency improve.

8 — What To Watch In Logs
New Debug Visibility
expected_gross=84.00
est_cost=62.30
per_share_profit=0.4200
per_share_cost=0.3115
min_expected_profit=100.00
dynamic_min_edge=73.50
final_min_edge=100.00
min_volatility_floor_pct=0.0010
effective_volatility_unit=0.3500
tier=REJECT_ABSOLUTE
score=1.348
  • score tells you per-unit edge quality.
  • tier tells you decision class.
  • final_min_edge shows whether static or adaptive rule dominated.
  • effective_volatility_unit shows whether the floor likely kicked in.
9 — Quick Reference
Question Answer
Does stale price protection block trades? No. It logs stale price age and still returns the price.
What is viability score based on? Per-share profit divided by per-share cost.
What blocks tiny but efficient trades? REJECT_ABSOLUTE via final_min_edge.
What is adaptive min edge? max(min_expected_profit, volatility_unit × multiplier × qty)
How is volatility estimated? Stop distance when available, otherwise expected move divided by RR.
What stops ultra-tight SL abuse? A configurable minimum volatility floor percentage.
Is the floor safe against bad configs? Yes. It is clamped between 0.01% and 2% in the engine.
Should manual override be used in production? No. Keep it for testing, debugging, and isolated operator workflows.
10 — Recommended Presets For Indian Markets

Scope: these presets are for Indian-market workflows only: NSE cash, NFO index or stock derivatives, and MCX commodities. No crypto assumptions are used here.

NSE Cash Intraday
  • Trade Quality Gate = ON
  • Non-Viable Mode = STRICT
  • Weak Tier Action = REJECT
  • Min Expected Profit = ₹100 to ₹250
  • Adaptive Min Edge = ON
  • Adaptive Edge Multiplier = 0.5
  • Min Volatility Floor = 0.10%
  • Manual Override = OFF
Best for equities like SBIN, RELIANCE, INFY, ICICIBANK
NFO Options / Futures
  • Trade Quality Gate = ON
  • Non-Viable Mode = STRICT
  • Weak Tier Action = REJECT
  • Min Expected Profit = ₹250 to ₹750
  • Adaptive Min Edge = ON
  • Adaptive Edge Multiplier = 0.7
  • Min Volatility Floor = 0.15% to 0.25%
  • Manual Override = OFF
Use stricter edge because derivatives can look attractive but decay fast after costs
MCX Intraday Commodities
  • Trade Quality Gate = ON
  • Non-Viable Mode = STRICT
  • Weak Tier Action = REJECT
  • Min Expected Profit = ₹300 to ₹1000
  • Adaptive Min Edge = ON
  • Adaptive Edge Multiplier = 0.75
  • Min Volatility Floor = 0.15% to 0.30%
  • Manual Override = OFF
Useful for GOLD, SILVER, CRUDEOIL, NATURALGAS where volatility regimes shift sharply
Testing Preset For Indian Markets
  • Non-Viable Mode = WARN
  • Weak Tier Action = WARN
  • Manual Override = ON only for manual signal testing
  • Keep Min Expected Profit lower than production
  • Watch logs first, then tighten filters after 1 week of observation
What Not To Do
  • Do not copy low-volatility equity settings into MCX blindly.
  • Do not lower slippage or spread just to increase paper profitability.
  • Do not leave Manual Override enabled in production.
  • Do not set Min Volatility Floor too high or almost every trade will fail edge tests.