Advanced Filters
Liquidity Filters in MT5: Reduce Slippage and False Signals | AlfaTactix
📖 13 min read
📝 2,401 words
🏷️ Advanced Filters
In this page: what Liquidity Filters is, how it works, when to use it, a practical example, and a bonus tip.
Use Liquidity Filters in a real strategy—no code required
Create a free account to save your progress and add this filter (and others) to strategies in minutes. Backtest, then export to MQL5.
Filter Explanation
Liquidity Filters Explanation
Liquidity Filters are essential tools for ensuring optimal execution conditions by filtering trades based on market liquidity indicators. They help you avoid trading during low-liquidity periods when execution quality degrades, spreads widen, and slippage increases significantly. Understanding liquidity dynamics is crucial for optimizing trade execution, as liquidity varies dramatically throughout the trading day and significantly impacts transaction costs and execution quality. Research by market microstructure scholars like Harris (2003) demonstrates that liquidity-based filtering can improve strategy performance by 20-35% by focusing on optimal execution conditions and reducing transaction costs.
How Liquidity Filtering Works:
Liquidity filtering operates by checking current market conditions against predefined liquidity thresholds before allowing trade execution. This systematic approach helps traders avoid periods when execution quality is suboptimal due to wide spreads, low volume, or shallow market depth, ensuring trades are entered only when liquidity conditions are favorable.
Key Liquidity Components:
Bid-Ask Spread: The spread is the difference between the bid (sell) and ask (buy) prices, representing the immediate transaction cost for entering or exiting a position. Spread costs compound over many trades, significantly impacting overall strategy profitability:
-
Tight Spreads (< 2 pips for major pairs): High liquidity, good execution quality, minimal slippage. During high-liquidity periods, spreads for major pairs like EUR/USD can be as low as 0.3-0.5 pips.
-
Wide Spreads (> 3 pips for major pairs): Low liquidity, poor execution conditions, increased slippage risk. During low-liquidity periods, spreads can widen to 5-10 pips or more, significantly impacting profitability.
-
Spread Volatility: Spreads fluctuate throughout the trading day, widening during low-activity periods (early morning, late evening, before/after major news events) and tightening during high-activity periods (session overlaps, peak trading hours).
-
Spread Cost Impact: For a strategy with 100 trades per month on EUR/USD, a 1-pip spread difference (e.g., 1 pip vs 2 pips) equals $10,000 difference in monthly transaction costs for a 10-lot position size.
Trading Volume: Volume indicates market participation and liquidity depth, providing insight into the ease of executing trades at desired prices:
-
High Volume: Many market participants, deep order books, tight spreads, minimal slippage. High volume periods typically show 50-100% higher liquidity compared to low-volume periods.
-
Low Volume: Few participants, thin markets, wide spreads, potential slippage. Low volume periods increase the risk of execution difficulties, especially for larger position sizes.
-
Volume Spikes: Sudden volume increases may indicate news events or major moves. Volume spikes often accompany increased liquidity, making them ideal for trade execution if the spike is sustained.
-
Volume Drops: Sudden volume decreases signal deteriorating market conditions and reduced liquidity. Volume drops often precede wider spreads and execution difficulties.
-
Volume Trend: Filtering based on volume trend (expanding vs contracting) helps identify periods when liquidity is improving or deteriorating. Expanding volume suggests increasing liquidity, while contracting volume suggests decreasing liquidity.
Market Depth: Market depth refers to the available liquidity at different price levels, indicating how large an order can be executed without significant price impact:
-
Deep Markets: Large orders can be executed without significant price impact. Deep markets show substantial order book depth at multiple price levels, allowing large positions to be executed efficiently.
-
Thin Markets: Even small orders can move prices, causing slippage. Thin markets show limited order book depth, making even moderate-sized positions difficult to execute without price impact.
-
Order Book Analysis: Real-time order book data (level II data) provides insight into market depth and available liquidity at different price levels, though this data is primarily available for exchange-traded instruments.
Liquidity Filter Conditions:
Spread-Based Filters:
-
Max Spread Filter: Ensure spread is below a threshold (e.g., spread < 0.0002 for EUR/USD, which is 2 pips). This ensures trades are executed only when spreads are tight, reducing transaction costs significantly.
-
Spread Widening Detection: Avoid trading when spreads are widening, indicating deteriorating liquidity. Spread widening often precedes execution difficulties and increased slippage.
-
Relative Spread: Compare current spread to average spread (e.g., current < 1.5 × average). This relative approach helps adapt to changing market conditions, allowing trades when spreads are relatively tight even if absolute spread levels vary.
-
Spread Percentile Filter: Filter based on spread percentiles (e.g., current spread < 70th percentile), ensuring trades are executed only during periods when spreads are below normal levels.
Volume-Based Filters:
-
Min Volume Filter: Only trade when volume is above average (e.g., volume > 20-period average). This ensures trades are executed only during periods with adequate market participation.
-
Volume Spike Detection: Trade during volume spikes when liquidity peaks. Sustained volume spikes often indicate increased market participation and improved execution conditions.
-
Volume Drop Detection: Avoid trading when volume suddenly drops below threshold. Volume drops often precede reduced liquidity and execution difficulties.
-
Volume Trend Filter: Filter based on volume trend (expanding vs contracting). Expanding volume suggests improving liquidity, while contracting volume suggests deteriorating liquidity.
-
Volume Percentile Filter: Filter based on volume percentiles (e.g., current volume > 50th percentile), ensuring trades are executed only during periods with above-average volume.
Combined Liquidity Filters:
-
Multi-Factor Liquidity Filter: Combine spread and volume filters for enhanced precision. For example, require both tight spreads (< 2 pips) AND high volume (> average) before allowing trades.
-
Dynamic Liquidity Thresholds: Adjust liquidity thresholds based on position size - larger positions require tighter spreads and higher volume to ensure optimal execution.
-
Time-Based Liquidity Filtering: Combine liquidity filters with time-based filters (e.g., only trade during known high-liquidity periods like session overlaps) for maximum effectiveness.
Why Liquidity Filters Matter:
-
Execution Quality: High-liquidity periods provide better fills with minimal slippage. Your entry and exit prices match your intended levels more closely, improving strategy performance. Research shows that trading during high-liquidity periods can improve fill quality by 40-60% compared to low-liquidity periods.
-
Cost Reduction: Tight spreads reduce transaction costs significantly. For a strategy with 100 trades per month, saving 1 pip per trade on EUR/USD equals $10 per lot per trade, or $1,000 per lot per month. For a 5-lot position, this equals $5,000 in monthly savings - often the difference between profitability and loss.
-
Slippage Prevention: Thin markets cause slippage - your actual execution price differs from intended price. This is especially critical for larger position sizes, where slippage can significantly impact profitability. Liquidity filters help avoid these periods, reducing slippage by 50-70%.
-
Risk Management: Low-liquidity periods increase the risk of:
- Wide spreads eating into profits, reducing net returns
- Slippage on entry and exit, causing worse-than-expected execution prices
- Inability to exit positions quickly during adverse moves, increasing risk exposure
- Price manipulation in thin markets, causing unexpected price movements
-
Strategy Performance: Execution quality directly impacts strategy performance. Poor fills can turn a profitable strategy into a losing one. Liquidity filters help ensure consistent execution quality, reducing variance in strategy performance and improving overall returns.
-
Scalability: Liquidity filters are essential for strategies that scale position sizes. As position sizes increase, execution quality becomes more critical, and liquidity filters become more important for maintaining profitability.
Typical Spread Levels by Market:
Spread levels vary significantly across different markets and instruments:
-
Major Forex Pairs (EUR/USD, GBP/USD, USD/JPY): 0.5-2 pips during high liquidity, 2-5 pips during normal conditions, 5-10+ pips during low liquidity
-
Minor Forex Pairs (EUR/GBP, AUD/USD): 2-5 pips during high liquidity, 5-8 pips during normal conditions, 8-15+ pips during low liquidity
-
Exotic Forex Pairs (USD/TRY, USD/ZAR): 5-15 pips during high liquidity, 15-30 pips during normal conditions, 30-50+ pips during low liquidity
-
Cryptocurrencies: Varies significantly by exchange and pair (0.01-0.5% during high liquidity on major exchanges)
-
Stocks/Equities: Spreads are typically expressed as a percentage of price (e.g., 0.01-0.1% for liquid stocks during normal hours)
Advantages:
-
Provides objective liquidity measurement that adapts to different market conditions and instruments, making it ideal for optimizing execution across various trading strategies and asset classes.
-
Works across all markets and timeframes, as liquidity dynamics apply universally. Whether trading forex, stocks, or commodities, liquidity filters help optimize execution timing.
-
Can be combined with other filters (session filters, volatility filters, time filters) for enhanced precision, creating sophisticated multi-factor entry conditions.
-
Helps manage risk by avoiding low-liquidity periods when execution quality degrades and slippage increases significantly.
-
Improves strategy profitability by reducing transaction costs and slippage, often making the difference between profitable and unprofitable strategies.
Limitations:
-
Spread and volume data availability varies across instruments and brokers. Some instruments may not provide real-time spread data, making spread-based filtering difficult.
-
Liquidity conditions can change rapidly, especially during news events or market crises, requiring real-time monitoring and potentially rapid filter adjustments.
-
Over-restrictive liquidity filters may cause missed opportunities when legitimate moves occur during periods of temporarily reduced liquidity due to news or other factors.
-
Different instruments may have different optimal liquidity thresholds, requiring instrument-specific filter configurations.
-
Should be combined with other analysis tools for optimal results. Liquidity filters work best when combined with volatility filters, session filters, and market condition analysis.
In summary, Liquidity Filters are essential tools for traders focused on optimizing execution quality and minimizing transaction costs, helping maximize strategy profitability while minimizing execution risk. For further reading, refer to Harris's comprehensive work "Trading and Exchanges: Market Microstructure for Practitioners" (2003), Investopedia's guide to understanding forex spreads, academic research on market microstructure and liquidity published in journals such as the Journal of Financial Markets, and institutional research on optimal execution by major banks and trading platforms.
Practical Example
Practical Example: Using Liquidity Filters
The Liquidity Filter is a market condition-based filter used to ensure trades are entered only when liquidity conditions are optimal for execution. In a trading strategy, the liquidity filter helps optimize execution quality and minimize transaction costs by focusing on periods when spreads are tightest, volume is highest, and market depth is greatest.
Scenario: You're trading EUR/USD with a position size of 5 lots. You need to ensure optimal execution conditions to minimize costs and slippage, as poor execution can significantly impact profitability for larger positions.
Strategy Logic:
-
Filter trades to execute only when:
- Spread is tight (< 2 pips or 0.0002 for EUR/USD)
- Volume is above average (current volume > 50-period average)
- Volume is not dropping (current volume >= previous volume)
- Spread is below 1.5× average spread (current < 1.5 × 20-period average)
-
Skip all trades when liquidity conditions are suboptimal to avoid wide spreads, low volume, and increased slippage
-
Combine multiple liquidity factors for enhanced precision and better execution quality
Backtrader Example:
import backtrader as bt
import pandas as pd
class LiquidityFilterStrategy(bt.Strategy):
params = dict(
max_spread=0.0002, # 2 pips for EUR/USD
volume_period=50, # Period for volume average
spread_period=20, # Period for spread average
min_volume_multiplier=1.0, # Min volume vs average (1.0 = average)
max_spread_multiplier=1.5 # Max spread vs average (1.5 = 50% above average)
)
def __init__(self):
# Volume analysis
self.volume_ma = bt.ind.SMA(self.data.volume, period=self.p.volume_period)
# For spread analysis (assuming spread data is available)
# In practice, you'd need to get spread from broker data or estimate it
# This is a simplified example
self.spread_estimate = self._estimate_spread()
self.spread_ma = bt.ind.SMA(self.spread_estimate, period=self.p.spread_period)
def _estimate_spread(self):
# In practice, you'd get actual spread from broker
# This is a simplified estimate based on high-low range
# Real implementation would use actual bid-ask spread data
return (self.data.high - self.data.low) / self.data.close * 10000 # Approximate pips
def check_liquidity_filter(self):
"""Check if liquidity conditions are optimal"""
# Check spread (simplified - use actual spread data in practice)
current_spread = self._estimate_spread()[0]
avg_spread = self.spread_ma[0]
spread_ok = (current_spread < self.p.max_spread and
current_spread < avg_spread * self.p.max_spread_multiplier)
# Check volume
current_volume = self.data.volume[0]
avg_volume = self.volume_ma[0]
volume_above_avg = current_volume > avg_volume * self.p.min_volume_multiplier
# Check volume trend (not dropping)
volume_stable = current_volume >= self.data.volume[-1]
# Combined liquidity filter: ALL conditions must be met
return spread_ok and volume_above_avg and volume_stable
def next(self):
# Liquidity filter: only trade when liquidity conditions are optimal
if not self.check_liquidity_filter():
return # Skip trade if liquidity filter fails
if not self.position:
# Your entry logic here (e.g., breakout detection)
if self._entry_signal():
self.buy()
else:
# Exit logic (e.g., stop-loss, take-profit, or opposite signal)
if self._exit_signal():
self.close()
def _entry_signal(self):
# Add your entry logic here
return False
def _exit_signal(self):
# Add your exit logic here
return False
# Usage
cerebro = bt.Cerebro()
cerebro.addstrategy(LiquidityFilterStrategy)
Cost Analysis:
Without Liquidity Filter:
- Average spread: 3 pips
- 100 trades/month × 3 pips × $10/pip × 5 lots = $15,000 in spread costs per month
- Additional slippage costs: ~$2,000-3,000/month
- Total transaction costs: $17,000-18,000/month
With Liquidity Filter:
- Average spread: 1 pip (trading only during high liquidity)
- 100 trades/month × 1 pip × $10/pip × 5 lots = $5,000 in spread costs per month
- Reduced slippage costs: ~$500-1,000/month
- Total transaction costs: $5,500-6,000/month
- Savings: $11,000-12,000 per month (65-70% reduction in transaction costs)
Expected Outcome:
This filter ensures:
- Optimal Execution: Entering trades only when spreads are tightest (typically 0.5-1 pip for EUR/USD during high liquidity) and volume is highest, improving execution quality by 40-60%
- Cost Reduction: Significantly lower transaction costs over time - for a 5-lot position, saving 2 pips per trade equals $1,000 per trade, or $100,000 per year for 100 trades per month
- Slippage Minimization: Reduced slippage during high-liquidity periods by 50-70%, as deep order books allow better fills
- Strategy Profitability: Lower costs improve net profitability significantly - strategies that were marginally profitable become consistently profitable, while losing strategies may become break-even or profitable
- Risk Management: Avoiding low-liquidity periods reduces execution risk and improves the ability to exit positions quickly during adverse moves
💡 Bonus Tip
For large position sizes (10+ lots), consider even stricter filters:
- Max spread: 1 pip (0.0001 for EUR/USD) - ensure absolute best execution
- Min volume: 1.5× average volume - require above-average liquidity
- Spread must be at multi-period low (e.g., lowest in last 20 periods) - trade only during absolute best liquidity conditions
- Combine with session filters - only trade during high-liquidity sessions (e.g., London-New York overlap)
This ensures you're trading in the absolute best liquidity conditions, critical for large positions where execution quality directly impacts profitability. The combination of strict liquidity filters with session filters can improve execution quality by 60-80% compared to unfiltered approaches.
Using Liquidity Filters ensures your strategy aligns with optimal execution conditions, improving execution quality and overall profitability over time by focusing on periods when transaction costs are minimized and execution quality is maximized.
Use Liquidity Filters in a real strategy—no code required
Create a free account to save your progress and add this filter (and others) to strategies in minutes. Backtest, then export to MQL5.
Continue learning