
Strategi ini adalah sistem perdagangan trend-tracking berdasarkan crossover rata-rata bergerak indeks cepat dan lambat (EMA). Ia menghasilkan isyarat jual beli yang lebih dipercayai dengan mengesahkan hubungan kedudukan harga dengan garis rata-rata ganda. Strategi ini mempunyai fungsi penyetempatan tempoh pengembalian untuk menilai prestasi strategi dalam jangka masa tertentu.
Strategi menggunakan EMA 10 dan 20 kitaran sebagai penunjuk teras. Apabila EMA cepat melintasi EMA perlahan ke atas dan harga penutupan berada di atas dua garis rata, ia mencetuskan isyarat ganda; Apabila EMA cepat melintasi EMA perlahan ke bawah dan harga penutupan berada di bawah dua garis rata, ia mencetuskan isyarat kosong.
Ini adalah strategi trend-tracking yang jelas dan logik yang ketat. Melalui mekanisme pengesahan harga yang digabungkan dengan penyeberangan dua hala yang sama, ia menyeimbangkan kesesuaian dan kebolehpercayaan isyarat.
/*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)