该策略是一个基于快速和慢速指数移动平均线(EMA)交叉的趋势跟踪交易系统。它通过对价格与双均线的位置关系进行确认,生成更可靠的买卖信号。策略内置了回测时间段设置功能,便于在特定时间范围内评估策略表现。
策略使用10周期和20周期的EMA作为核心指标。当快速EMA向上穿越慢速EMA,且收盘价位于两条均线之上时,触发做多信号;当快速EMA向下穿越慢速EMA,且收盘价位于两条均线之下时,触发做空信号。这种双重确认机制提高了信号的可靠性。
这是一个结构清晰、逻辑严谨的趋势跟踪策略。通过双均线交叉结合价格确认机制,有效平衡了信号及时性和可靠性。策略具有良好的可扩展性,通过优化可以进一步提升性能。适合作为中长期趋势跟踪的基础策略框架。
/*backtest
start: 2024-02-21 00:00:00
end: 2024-10-01 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BNB_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BFXGold
//@version=5
strategy("BFX Buy and Sell", overlay=true)
// Inputs
ema_fast_length = input.int(10, title="Fast EMA Length")
ema_slow_length = input.int(20, title="Slow EMA Length")
// Calculate EMAs
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
// Confirmation candles
confirmation_above = close > ema_fast and close > ema_slow
confirmation_below = close < ema_fast and close < ema_slow
// Crossovers with confirmation
long_condition = ta.crossover(ema_fast, ema_slow) and confirmation_above
short_condition = ta.crossunder(ema_fast, ema_slow) and confirmation_below
// Plot signals
if (long_condition )
label.new(bar_index, low, text="BUY", style=label.style_label_up, color=color.new(color.green, 0), textcolor=color.white)
if (short_condition)
label.new(bar_index, high, text="SELL", style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white)
// Strategy execution for backtesting
if (long_condition)
strategy.entry("Long", strategy.long)
if (short_condition)
strategy.entry("Short", strategy.short)
// Plot EMAs
plot(ema_fast, title="Fast EMA (10)", color=color.blue, linewidth=1)
plot(ema_slow, title="Slow EMA (20)", color=color.orange, linewidth=1)