
This strategy is a high-frequency trading system based on short-period Exponential Moving Average (EMA) crossover signals. It combines adaptive volatility tracking mechanisms with dynamic position management and strict risk control to quickly capture short-term market fluctuations. The strategy operates on short timeframes such as 1-minute or 5-minute charts, suitable for active traders seeking frequent trading opportunities.
The core logic is based on crossover signals between a fast EMA (3-period) and a slow EMA (8-period). Long signals are generated when the fast line crosses above the slow line, and short signals when the fast line crosses below. The strategy uses the ATR indicator to measure market volatility and dynamically set stop-loss and profit targets. The system supports both fixed contract quantity trading and dynamic position management based on account equity. In dynamic position mode, risk is controlled within 0.5% of account equity per trade. The strategy employs a 1.2 risk-reward ratio and uses 1.5 times ATR as the trailing stop distance.
The strategy builds a complete high-frequency trading system by combining short-period EMA crossover signals with dynamic risk management. Its strengths lie in quick response and strict risk control, but attention must be paid to false signals and trading costs. Through continuous optimization and parameter adjustment, the strategy can better adapt to different market environments, improving trading efficiency and stability.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("High-Frequency EMA Scalping Strategy - Adjustable Contracts", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1)
// Input parameters
fastEmaLength = input.int(3, title="Fast EMA Length", minval=1)
slowEmaLength = input.int(8, title="Slow EMA Length", minval=1)
atrLength = input.int(10, title="ATR Length", minval=1)
riskRewardRatio = input.float(1.2, title="Risk/Reward Ratio", minval=1)
useDynamicPositionSizing = input.bool(false, title="Use Dynamic Position Sizing?")
fixedContracts = input.int(1, title="Number of Contracts (if Fixed)", minval=1) // Fixed number of contracts
// Calculate EMA values
fastEma = ta.ema(close, fastEmaLength)
slowEma = ta.ema(close, slowEmaLength)
// Calculate ATR for dynamic stop-loss and take-profit
atr = ta.atr(atrLength)
// Dynamic position sizing (if enabled)
capital = strategy.equity
riskPerTrade = capital * 0.005 // Risk 0.5% per trade
dynamicTradeQty = riskPerTrade / (atr * 1.5)
// Use fixed or dynamic position sizing
tradeQty = useDynamicPositionSizing ? dynamicTradeQty : fixedContracts
// Entry conditions
longCondition = ta.crossover(fastEma, slowEma)
shortCondition = ta.crossunder(fastEma, slowEma)
// Long trade execution
if longCondition
risk = atr * 1.0
reward = risk * riskRewardRatio
strategy.entry("Long", strategy.long, qty=tradeQty)
strategy.exit("Trailing Stop Long", from_entry="Long", trail_points=atr * 1.5, trail_offset=atr * 1.0)
strategy.exit("Take Profit", from_entry="Long", limit=close + reward, stop=close - risk)
// Short trade execution
if shortCondition
risk = atr * 1.0
reward = risk * riskRewardRatio
strategy.entry("Short", strategy.short, qty=tradeQty)
strategy.exit("Trailing Stop Short", from_entry="Short", trail_points=atr * 1.5, trail_offset=atr * 1.0)
strategy.exit("Take Profit", from_entry="Short", limit=close - reward, stop=close + risk)
// Plot EMA lines for reference
plot(fastEma, color=color.blue, title="Fast EMA")
plot(slowEma, color=color.red, title="Slow EMA")