均线交叉动量翻转量化交易策略是一个基于规则的趋势跟踪系统,该系统核心逻辑围绕21周期指数移动平均线(21 EMA)展开。策略监测价格与21 EMA的关系,当价格收盘穿越均线上方时做多,穿越均线下方时做空,并在价格再次穿越均线时平仓并反向开仓。该策略还包含自定义的交易时段过滤、止盈止损设置、每日最大交易次数限制以及首次盈利后自动锁定交易等风控机制,旨在提供一个纪律严明、逻辑清晰的交易系统。
该策略的核心原理是捕捉价格围绕21 EMA的动量变化,实现趋势跟随与反转交易。具体来说:
策略还整合了成交量加权平均价(VWAP)作为辅助参考指标,提供额外的市场背景信息。
这些优化方向旨在提升策略的稳健性和适应性,减少假信号并提高盈利能力。
均线交叉动量翻转量化交易策略是一个基于21 EMA交叉的趋势跟踪系统,具有逻辑清晰、规则严明的特点。通过监测价格与均线的关系,结合严格的风险管理机制,该策略能够有效捕捉市场趋势转变点,同时控制风险。
策略的主要优势在于其简明直观的交易逻辑和完善的纪律执行机制,尤其是首次盈利后锁定交易的设计有效防止了过度交易和利润回吐。然而,策略也存在均线滞后性、过度依赖单一指标等潜在风险。
未来优化方向应着重于参数动态化、多因子信号确认、风险管理增强以及市场状态分类等方面,以提升策略在不同市场环境下的适应能力。通过这些优化,该策略有望成为一个更加稳健、可靠的量化交易系统。
作为DSPLN方法的一部分,这一策略体现了”耐心倾听”(Do So Patiently Listening Now)的交易哲学,强调纪律性和系统性,为交易者提供了一个克服情绪干扰、专注于规则执行的交易框架。
/*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)