Skip to product information
1 of 1

HFTCODE.COM

Micro S&P 500 Short Momentum – Python Futures Strategy Source Code (MES)

Micro S&P 500 Short Momentum – Python Futures Strategy Source Code (MES)

Regular price $19.00 USD
Regular price Sale price $19.00 USD
Sale Sold out
Quantity

Python Strategy Source Code · Educational

Micro S&P 500 Short Momentum

A short-only Micro E-mini S&P 500 (MES) futures strategy built around NFP releases and hawkish Fed repricing. The code doesn't depend on any broker, uses only the Python standard library and has comments throughout.

Bot ID: bot_mes_short_momentum  |  Exchange: CME  |  Bias: SHORT only  |  Max contracts: 2

Overview

You get the complete, documented Python source code for a systematic short-momentum strategy on Micro E-mini S&P 500 futures. The strategy reads OHLCV bars and checks its entry and exit conditions at each bar close. It manages open positions with ATR-based stops and position sizing. Every decision is visible in the code, so you can trace why a trade was opened, how it was sized and why it was closed.

The code doesn't depend on any broker. Market-data and order-execution hooks are marked with placeholder comments. You can feed it bars from any source and send its orders to any broker API or paper-trading adapter, and the signal, indicator and risk modules stay the same. It uses only the Python standard library (asyncio, logging, typing).

This package is for:

  • Developers learning how systematic trading strategies are built
  • Traders who want a starting point to adapt and test on their own
  • Quants who want a clean, readable reference implementation

Please note: This is source code for study and further development. It is not a finished, proven trading system. The backtest below has very few trades and low statistical confidence. Test it thoroughly yourself before you consider live use.

What You Receive

  • bot_mes_short_momentum_portable.py: Python strategy file with all broker, data-feed and messaging code replaced by placeholder comments
  • The full strategy logic, including indicators, signals, position sizing and risk controls
  • Comments throughout the code, written for learning
  • Works with any platform that delivers OHLCV bar data to Python

How the Strategy Works

Indicators
  • RSI
  • MACD
  • EMA / SMA crossover
  • ATR volatility
  • Donchian channel breakout
  • Realized-volatility regime filter
Position Sizing
  • Risk-percent-of-capital sizing
  • Margin-utilization cap
  • Inverse-volatility (ATR) scaling
  • Volatility-regime (VIX) scaling*
  • Hard cap of 2 contracts
Exits & Trade Management
  • Profit-taking in stages at several R-multiple targets
  • Trailing stop that only moves in the trade's favor
  • Hard stop (STOP_HIT) and trailing stop (TRAILING_STOP)
  • Exit when the trend or momentum reverses (THESIS_INVALIDATED)
  • Maximum holding period (TIME_EXIT)
  • Profit target (PROFIT_TARGET)
Risk Controls
  • Stop after a set number of consecutive losses
  • Loss circuit breaker that halts trading
  • Dynamic daily loss limit
  • Weekly loss limit
  • No trading during the exchange maintenance window
  • Protection against stale data feeds

*VIX-based scaling needs you to supply a VIX data feed. Execution model: an event-driven async loop with structured JSON event logs (entries, exits, diagnostics and metrics). All fills are simulated by default.

Hypothetical Backtest Results

Backtest on 4-hour MES OHLCV bars (861 bars, about 4 months analyzed, May–Sep 2026) with $12,000 starting capital. Fills were approximated, not executed. Statistical confidence: LOW (7 trades).

Metric Value
Net P&L (hypothetical) $773.86
Total trades 7 (4 winners / 3 losers)
Win rate 57.1%
Sharpe ratio 1.68
Maximum drawdown $76.79 (0.64%)
Max consecutive wins / losses 2 / 2
Profitable months 2 of 4 (50%)

Monthly results (hypothetical, % of $12,000)

May 2026 Jun 2026 Jul 2026 Aug 2026 Sep 2026
+$794.87
+6.6%
No trades −$7.02
−0.06%
+$3.27
+0.03%
−$16.80
−0.14%

Almost all of the backtest profit came from a single month (May 2026). The strategy was roughly flat to slightly negative from July through September.

Paper-trading session (2026-09-23)

2 trades: 1 win, 1 loss. Net result: $0.00.

Limitations of these results
  • Only 7 trades. That is well below the 20+ usually needed for any statistical meaning.
  • Only 1 of the last 3 months was profitable, and September 2026 was a losing month.
  • Fills were approximated from a signal score, not executed trades.
  • Results depend heavily on one month and may not repeat.

Technical Requirements

  • Python 3.10+
  • Standard library only: asyncio, logging, os, sys, typing
  • Any OHLCV bar data source (4-hour bars were used in the backtest)
  • Any broker API or paper-trading adapter, which you supply

Frequently Asked Questions

Do I need a particular broker or data vendor?
No. All vendor-specific code has been removed. You supply the market data and order execution.

Can I paper-trade this?
Yes. Replace the placeholder order methods with a simulated fill engine. We strongly recommend paper trading for a long period before using real money.

Which contract does it trade?
The code is set up for the June 2026 MES contract (MESM6), which has expired. Change the SYMBOL setting to the current front-month contract (for example, MESZ6) and roll it each quarter.

Can I use it on other instruments?
Yes. Change SYMBOL and recalibrate the settings block (tick size, point value, ATR multipliers and risk limits) for the new market.

Is this a guaranteed or proven profitable system?
No. This is educational source code. The backtest is hypothetical and based on a very small number of trades.

Risk Disclaimer

This software is for educational purposes only and is not investment advice or a recommendation to buy or sell any security or futures contract. Futures trading involves substantial risk of loss and is not suitable for every investor. You can lose more than your initial investment. Past performance, whether actual or hypothetical, does not guarantee future results. Consult a qualified financial professional before trading real money.

Hypothetical or simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown.

View full details