
This strategy is a trend following trading system based on the crossover of fast and slow Exponential Moving Averages (EMA). It generates more reliable buy and sell signals by confirming price position relative to both EMAs. The strategy includes customizable backtesting timeframe settings for performance evaluation within specific periods.
The strategy utilizes 10-period and 20-period EMAs as core indicators. A long signal is triggered when the fast EMA crosses above the slow EMA and the closing price is above both EMAs; a short signal is triggered when the fast EMA crosses below the slow EMA and the closing price is below both EMAs. This dual confirmation mechanism enhances signal reliability.
This is a well-structured and logically rigorous trend following strategy. By combining dual EMA crossover with price confirmation mechanism, it effectively balances signal timeliness and reliability. The strategy offers good scalability and can be further enhanced through optimization. It serves as an excellent foundation for medium to long-term trend following trading frameworks.
/*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)