
Chiến lược này sử dụng đường giao nhau để xác định hướng động lực giá, hỗ trợ cho xu hướng tổng thể bằng cách xác định xu hướng vàng, để thực hiện theo dõi xu hướng.
Chiến lược này sử dụng giao điểm của hai đường trung bình EMA và SMA để đánh giá hướng động lực giá, EMA phản ứng nhanh hơn, phản ứng SMA ổn định hơn. Khi EMA vượt qua SMA, đánh giá giá tăng mạnh, làm nhiều hơn; Khi EMA vượt qua SMA, đánh giá giá giảm mạnh, làm rỗng.
Ngoài ra, chiến lược này cũng sử dụng giao thoa của SMA chu kỳ nhanh và SMA chu kỳ chậm để xác định hướng xu hướng tổng thể. Khi SMA nhanh vượt qua SMA chậm, nó là gai vàng và được đánh giá là xu hướng tăng dài hạn; khi SMA nhanh vượt qua SMA chậm, nó là gai chết và được đánh giá là xu hướng giảm dài hạn.
Chiến lược được đánh giá là cơ hội để làm nhiều hơn khi vượt qua SMA trên EMA. Nếu thời điểm này là gai vàng, thì việc làm nhiều hơn không chỉ có hỗ trợ động lực ngắn hạn, mà còn phù hợp với xu hướng dài hạn, đây là thời điểm tốt hơn để làm nhiều hơn; Nếu thời điểm này là gai chết, thì chỉ có hỗ trợ động lực ngắn hạn, không phù hợp với xu hướng dài hạn, đây là thời điểm làm nhiều hơn mạo hiểm.
Có thể giảm rủi ro bằng cách kết hợp các chỉ số khác để xác nhận tín hiệu, tối ưu hóa tham số chu kỳ trung bình, hoặc thiết lập dừng lỗ.
Chiến lược này nói chung là một chiến lược theo dõi xu hướng ổn định và đáng tin cậy hơn. Nó cùng lúc xem xét động lực giá ngắn hạn và hướng xu hướng dài hạn, tạo ra tín hiệu giao dịch bằng cách giao nhau. Nó kết hợp với xác nhận chỉ số kép, có độ tin cậy cao hơn so với chiến lược theo dõi xu hướng đơn lẻ.
/*backtest
start: 2023-09-19 00:00:00
end: 2023-10-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Cryptoluc1d
//@version=4
strategy("Equal-Length EMA/SMA Crossover Strategy", initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=25, commission_type=strategy.commission.percent, commission_value=0.2, overlay=true)
// Create inputs
mom_length = input(title="Momentum Length (EMA=SMA)", defval=50)
bias_length_fast = input(title="Golden Cross Length (Fast)", defval=50)
bias_length_slow = input(title="Golden Cross Length (Slow)", defval=100)
// Define MAs
ema = ema(close, mom_length) // EMA/SMA crossover of the same period for detecting trend acceleration/deceleration
sma = sma(close, mom_length)
bias_fast = sma(close, bias_length_fast) // golden/death cross for overall trend bias
bias_slow = sma(close, bias_length_slow)
// Define signal conditions
buy_trend = crossover(ema, sma) and bias_fast >= bias_slow // buy when EMA cross above SMA. if this happens during a bullish golden cross, buying is in confluence with the overall trend (bias).
buy_risky = crossover(ema, sma) and bias_fast < bias_slow // buy when EMA cross above SMA. if this happens during a bearish death cross, buying is early, more risky, and not in confluence with the overall trend (bias).
buy_late = crossover(sma, bias_slow) and ema > sma // the SMA crossing the Slow_SMA gives further confirmation of bullish trend, but signal comes later.
sell = crossunder(ema, sma) // sell when EMA cross under SMA.
// Enable option to hide signals, then plot signals
show_signal = input(title="Show Signals", defval=true)
plotshape(show_signal ? buy_trend : na, title='Trend Buy', style=shape.triangleup, location=location.belowbar, color=color.green, text='TREND BUY')
plotshape(show_signal ? buy_risky : na, title='Risky Buy', style=shape.triangleup, location=location.belowbar, color=color.olive, text='RISKY BUY')
plotshape(show_signal ? buy_late : na, title='Late Buy', style=shape.triangleup, location=location.belowbar, color=color.lime, text='LATE BUY')
plotshape(show_signal ? sell : na, title='Sell', style=shape.triangledown, location=location.abovebar, color=color.red, text='SELL')
// Define entry and exit conditions
longCondition = ema > sma and bias_fast >= bias_slow // LONG when EMA above SMA, and overall trend bias is bullish
if (longCondition)
strategy.entry("BUY TREND", strategy.long)
exitLong = crossunder(ema, sma) // close LONG when EMA cross under SMA
strategy.close("BUY TREND", when=exitLong)
// // short conditions. turned off because up only.
// shortCondition = ema < sma and bias_fast <= bias_slow // SHORT when EMA under SMA, and overall trend bias is bearish
// if (shortCondition)
// strategy.entry("SELL TREND", strategy.short)
// exitShort = crossover(ema, sma) // close SHORT when EMA cross over SMA
// strategy.close("SELL TREND", when=exitShort)
// Enable option to show MAs, then plot MAs
show_ma = input(title="Show MAs", defval=false)
plot(show_ma ? ema : na, title="Momentum EMA", color=color.green, linewidth=1)
plot(show_ma ? sma : na, title="Momentum SMA", color=color.yellow, linewidth=1)
plot(show_ma ? bias_fast : na, title="Golden Cross SMA (Fast)", color=color.orange, linewidth=2)
plot(show_ma ? bias_slow : na, title="Golden Cross SMA (Slow)", color=color.red, linewidth=2)