
The EMA Momentum Flip Quantitative Trading Strategy is a rules-based trend-following system that revolves around the 21-period Exponential Moving Average (21 EMA). The strategy monitors the relationship between price and the 21 EMA, entering long positions when price closes above the EMA and short positions when price closes below it, exiting when price crosses back over the EMA and immediately re-entering in the opposite direction. The strategy also incorporates customized session filters, take-profit/stop-loss settings, daily trade limits, and an automatic trading lockout after the first profitable trade, designed to provide a disciplined, logically clear trading system.
The core principle of this strategy is to capture momentum shifts around the 21 EMA, implementing both trend-following and reversal trading. Specifically:
The strategy also incorporates Volume Weighted Average Price (VWAP) as a supplementary reference indicator, providing additional market context.
These optimization directions aim to enhance the strategy’s robustness and adaptability, reducing false signals and improving profitability.
The EMA Momentum Flip Quantitative Trading Strategy is a trend-following system based on 21 EMA crossovers, characterized by clear logic and strict rules. By monitoring the relationship between price and the moving average, combined with rigorous risk management mechanisms, this strategy effectively captures market trend transition points while controlling risk.
The strategy’s main advantages lie in its intuitive trading logic and comprehensive disciplinary execution mechanisms, especially the design of locking trades after the first profit, which effectively prevents overtrading and profit giveback. However, the strategy also has potential risks such as EMA lag and over-reliance on a single indicator.
Future optimization directions should focus on parameter dynamization, multi-factor signal confirmation, enhanced risk management, and market state classification to improve the strategy’s adaptability in different market environments. Through these optimizations, this strategy has the potential to become a more robust and reliable quantitative trading system.
As part of the DSPLN method, this strategy embodies the trading philosophy of “Do So Patiently Listening Now,” emphasizing discipline and systematization, providing traders with a framework to overcome emotional interference and focus on rule execution.
/*backtest
start: 2025-06-15 00:00:00
end: 2025-06-21 08:00:00
period: 3m
basePeriod: 3m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EnvisionTrades
//@version=5
strategy("DSPLN EMA Flip Strategy v6", overlay=true)
// 🔹 Inputs
startHour = input.int(8, "Start Hour")
startMinute = input.int(30, "Start Minute")
endHour = input.int(10, "End Hour")
endMinute = input.int(30, "End Minute")
useTPSL = input.bool(true, "Use TP/SL?")
tpPoints = input.int(40, "Take Profit (points)")
slPoints = input.int(20, "Stop Loss (points)")
// 🔹 Time Filter
isWithinTradingHours = (hour > startHour or (hour == startHour and minute >= startMinute)) and
(hour < endHour or (hour == endHour and minute < endMinute))
// 🔹 Indicators
ema21 = ta.ema(close, 21)
vwap = ta.vwap
plot(ema21, title="21 EMA", color=color.orange)
plot(vwap, title="VWAP", color=color.blue)
// 🔹 State Variables
var int tradesToday = 0
var bool lastTradeWon = false
var float entryPrice = na
var label winLabel = na
var int prevTradeCount = 0
// 🔹 Entry Conditions
longEntry = isWithinTradingHours and close > ema21 and close[1] <= ema21[1]
shortEntry = isWithinTradingHours and close < ema21 and close[1] >= ema21[1]
// 🔹 Exit Conditions
longExit = strategy.position_size > 0 and close < ema21
shortExit = strategy.position_size < 0 and close > ema21
// 🔹 Trade Control
canTrade = tradesToday < 5 and not lastTradeWon
// 🔹 Entry Logic
if canTrade and strategy.position_size == 0 and longEntry
strategy.entry("Long", strategy.long)
entryPrice := close
if useTPSL
strategy.exit("TP Long", from_entry="Long", stop=close - slPoints * syminfo.mintick, limit=close + tpPoints * syminfo.mintick)
if canTrade and strategy.position_size == 0 and shortEntry
strategy.entry("Short", strategy.short)
entryPrice := close
if useTPSL
strategy.exit("TP Short", from_entry="Short", stop=close + slPoints * syminfo.mintick, limit=close - tpPoints * syminfo.mintick)
// 🔹 EMA Manual Exit Logic
if longExit
strategy.close("Long")
tradesToday += 1
lastTradeWon := close > entryPrice
if lastTradeWon
winLabel := label.new(bar_index, high, "✅ WIN - No More Trades", style=label.style_label_down, color=color.green)
if shortExit
strategy.close("Short")
tradesToday += 1
lastTradeWon := close < entryPrice
if lastTradeWon
winLabel := label.new(bar_index, low, "✅ WIN - No More Trades", style=label.style_label_up, color=color.green)
// 🔹 Detect Closed Trades (TP/SL exits)
tradeCount = strategy.closedtrades
if tradeCount > prevTradeCount
closedProfit = strategy.netprofit - strategy.netprofit[1]
tradesToday += 1
lastTradeWon := closedProfit > 0
if lastTradeWon
winLabel := label.new(bar_index, high, "✅ TP WIN - No More Trades", style=label.style_label_down, color=color.green)
prevTradeCount := tradeCount
// 🔹 Reset Daily
if (hour == endHour and minute == endMinute)
tradesToday := 0
lastTradeWon := false
entryPrice := na
prevTradeCount := 0
if not na(winLabel)
label.delete(winLabel)