这是一个基于三重指数移动平均线(EMA)交叉信号的趋势跟踪交易系统。该系统结合了EMA8、EMA21和EMA89三条均线,通过均线交叉产生交易信号,并集成了基于风险收益比的智能移动止损功能,实现了自动化的风险管理。
系统主要包含以下核心功能模块: 1. 信号生成模块:利用快速EMA8与中速EMA21的交叉确定交易方向,同时要求价格在慢速EMA89的上方或下方以确认大趋势 2. 交易执行模块:在满足做多或做空条件时自动开仓,并设置初始止损和目标位 3. 风险管理模块:当价格移动达到1:1的风险收益比时,自动将止损移至成本位,锁定无风险收益 4. 可视化模块:在图表上绘制三条均线、入场点和移动止损标记
该策略通过结合经典的均线交叉系统和现代的风险管理方法,实现了一个完整的趋势跟踪交易系统。系统的优势在于其可靠的信号生成机制和智能的风险控制方法,但在实际应用中仍需要根据具体市场特征进行参数优化和功能扩展。通过持续改进和优化,该策略有望在各种市场环境下保持稳定的表现。
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover with SL to BE", shorttitle="OmegaGalsky", overlay=true)
// Входни параметри
ema8_period = input.int(8, title="EMA 8 Period")
ema21_period = input.int(21, title="EMA 21 Period")
ema89_period = input.int(89, title="EMA 89 Period")
fixed_risk_reward = input.float(1.0, title="Risk/Reward Ratio (R2R)")
sl_percentage = input.float(0.001, title="Stop Loss Percentage", step=0.0001)
tp_percentage = input.float(0.0025, title="Take Profit Percentage", step=0.0001)
// Изчисляване на EMA
ema8 = ta.ema(close, ema8_period)
ema21 = ta.ema(close, ema21_period)
ema89 = ta.ema(close, ema89_period)
// Условия за BUY
buy_condition = ta.crossover(ema8, ema21) and close > ema89 and close > open
// Условия за SELL
sell_condition = ta.crossunder(ema8, ema21) and close < ema89 and close < open
// Вход в BUY позиция
if (buy_condition)
stop_loss = close * (1 - sl_percentage)
take_profit = close * (1 + tp_percentage)
strategy.entry("BUY", strategy.long)
strategy.exit("TP/SL", from_entry="BUY", stop=stop_loss, limit=take_profit)
// Вход в SELL позиция
if (sell_condition)
stop_loss = close * (1 + sl_percentage)
take_profit = close * (1 - tp_percentage)
strategy.entry("SELL", strategy.short)
strategy.exit("TP/SL", from_entry="SELL", stop=stop_loss, limit=take_profit)
// Логика за преместване на стоп към BE
if (strategy.position_size > 0)
entry_price = strategy.position_avg_price
// За LONG позиция
if (strategy.position_size > 0 and high >= entry_price + (entry_price * sl_percentage * fixed_risk_reward))
strategy.exit("SL to BE", from_entry="BUY", stop=entry_price)
label.new(bar_index, high, "SL moved to BE", color=color.green)
// За SHORT позиция
if (strategy.position_size < 0 and low <= entry_price - (entry_price * sl_percentage * fixed_risk_reward))
strategy.exit("SL to BE", from_entry="SELL", stop=entry_price)
label.new(bar_index, low, "SL moved to BE", color=color.red)
// Чертеж на EMA
plot(ema8, color=color.orange, title="EMA 8")
plot(ema21, color=color.blue, title="EMA 21")
plot(ema89, color=color.purple, title="EMA 89")