Strategy vault / Mean reversion
Dynamic Supply Demand Zone Midline Reversal Strategy
This strategy is a trading system based on supply-demand zones and midline reversal, operating on a 5-minute timeframe. It generates trading signals when price retraces to the midline during trends, with take-profit…

Overview
This strategy is a trading system based on supply-demand zones and midline reversal, operating on a 5-minute timeframe. It generates trading signals when price retraces to the midline during trends, with take-profit and stop-loss levels set at pre-identified supply and demand zones. The strategy combines Simple Moving Average (SMA) for trend direction, identifies supply-demand zones through highs and lows, and uses the zone midpoint as a crucial price reference level.
Strategy Principles
The core logic includes several key elements:
- Supply-Demand Zone Identification: Uses user-defined period (default 50) highs and lows to determine supply (resistance) and demand (support) zones
- Midline Calculation: Takes the midpoint of supply-demand zones as a key price reversal reference
- Trend Determination: Employs Simple Moving Average (default 20 periods) to determine current trend direction
- Entry Conditions:
- Long: Price above SMA (uptrend) with bullish candlestick pattern below midpoint
- Short: Price below SMA (downtrend) with bearish candlestick pattern above midpoint
- Take-Profit and Stop-Loss Setup:
- Long: Take-profit at supply zone, stop-loss at demand zone
- Short: Take-profit at demand zone, stop-loss at supply zone
Strategy Advantages
- Clear Logic: Combines trend, price structure, and candlestick patterns into a complete trading system
- Robust Risk Management: Sets profit targets and stops based on market structure
- High Adaptability: Can be adjusted through parameters for different market conditions
- Visual Support: Provides clear visualization of trading signals and key price levels
- High Automation: Clear entry and exit conditions enable fully automated trading
Strategy Risks
- False Breakout Risk: Price may oscillate within supply-demand zones, generating false signals
- Parameter Sensitivity: Different parameter settings may lead to significantly different trading results
- Market Environment Dependency: May underperform in highly volatile or ranging markets
- Slippage Impact: Actual execution prices may deviate significantly from signal prices in less liquid markets
- Overtrading: Frequent zone breakouts may lead to excessive trading
Strategy Optimization Directions
- Signal Filtering:
- Add volume confirmation
- Incorporate volatility indicators for market condition filtering
- Dynamic Parameters:
- Implement adaptive parameter adjustment based on market volatility
- Introduce adaptive moving averages
- Risk Management Enhancement:
- Implement dynamic position sizing
- Add risk-reward ratio filters
- Market Environment Recognition:
- Develop market state classification system
- Use different parameter settings for different market states
Summary
The Dynamic Supply-Demand Zone Midline Reversal Strategy is a trading system that combines multiple dimensions of technical analysis, capturing market opportunities through the interplay of supply-demand zones, trends, and price patterns. Its core strengths lie in its clear logical framework and comprehensive risk management system, but traders need to closely monitor market environment changes and adjust parameters accordingly. Through the suggested optimization directions, the strategy's stability and adaptability can be further enhanced.
Source Pine Script
/*backtest
start: 2025-02-16 00:00:00
end: 2025-02-23 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bommytarton
//@version=6
strategy("Midline Rejection Entry with TP/SL at Supply/Demand", overlay=true)
// User inputs for Swing Length and Length for Supply/Demand Zones
length = input.int(50, title="Swing Length", minval=1)
midlineLength = input.int(20, title="Midline Length for Trend", minval=1) // Moving average length for trend
// Identify swing highs (Supply Zone) and swing lows (Demand Zone)
supplyZone = ta.highest(high, length) // Supply Zone (resistance)
demandZone = ta.lowest(low, length) // Demand Zone (support)
// Calculate the midpoint between supply and demand zones
midpoint = (supplyZone + demandZone) / 2
// Trend Detection: Use a simple moving average (SMA) for trend direction
smaTrend = ta.sma(close, midlineLength)
// Variables to store Supply/Demand Zones at the time of entry
var float entrySupplyZone = na
var float entryDemandZone = na
var float entryMidpoint = na
// Entry Conditions
// 1. Price in an uptrend (close above SMA)
longCondition = close > smaTrend and close < midpoint and close > open and open < close[1] and close[1] < open[1]
// 1. Price in a downtrend (close below SMA)
shortCondition = close < smaTrend and close > midpoint and close < open and open > close[1] and close[1] > open[1]
// Close any open trades before opening a new one
if (longCondition or shortCondition)
strategy.close_all()
// Execute the entry logic
if (longCondition)
entrySupplyZone := supplyZone // Store Supply Zone for Take Profit
entryDemandZone := demandZone // Store Demand Zone for Stop Loss
entryMidpoint := midpoint // Store Midpoint
strategy.entry("Long", strategy.long)
label.new(bar_index, low, "Open Long", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)
if (shortCondition)
entrySupplyZone := supplyZone // Store Supply Zone for Stop Loss
entryDemandZone := demandZone // Store Demand Zone for Take Profit
entryMidpoint := midpoint // Store Midpoint
strategy.entry("Short", strategy.short)
label.new(bar_index, high, "Open Short", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)
// Define Take Profit and Stop Loss Levels for Long/Short Trades
if (strategy.opentrades > 0)
// For Long trades, use Supply Zone for Take Profit and Demand Zone for Stop Loss
if (strategy.position_size > 0)
strategy.exit("Take Profit", "Long", limit=entrySupplyZone) // Take Profit at Supply Zone
strategy.exit("Stop Loss", "Long", stop=entryDemandZone) // Stop Loss at Demand Zone
// For Short trades, use Demand Zone for Take Profit and Supply Zone for Stop Loss
if (strategy.position_size < 0)
strategy.exit("Take Profit", "Short", limit=entryDemandZone) // Take Profit at Demand Zone
strategy.exit("Stop Loss", "Short", stop=entrySupplyZone) // Stop Loss at Supply Zone
// Re-Plot Supply, Midpoint, and Demand Zones after Trade Closure
plot(supplyZone, title="Supply Zone", color=color.red, linewidth=2, style=plot.style_line)
plot(demandZone, title="Demand Zone", color=color.green, linewidth=2, style=plot.style_line)
plot(midpoint, title="Midpoint", color=color.blue, linewidth=1, style=plot.style_line)
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-24. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dynamic-Supply-Demand-Zone-Midline-Reversal-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Strategy with Volume and Price Pullback Multiple Take ProfitPine Script · Mean reversion · 1h
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- Fast RSI Reversal Trading StrategyPine Script · Mean reversion · 1h
- Multi Indicator Reversal Point Capture Trading StrategyPine Script · Mean reversion · 1d