
Chiến lược này là một hệ thống theo dõi xu hướng dựa trên MACD và RSI bộ lọc chỉ số kép, tích hợp các cơ chế dừng động. Chiến lược này chủ yếu tạo ra cơ hội giao dịch thông qua tín hiệu chéo của MACD và sử dụng RSI làm xác nhận thứ hai, đồng thời đưa ra phần trăm dừng để kiểm soát rủi ro.
Chiến lược sử dụng MACD ((12,26,9) và RSI ((14)) làm chỉ số chính. Các tín hiệu mua phải đáp ứng hai điều kiện đồng thời: MACD Gold Fork và RSI ở vùng oversold (dưới 40 mặc định) và MACD Dead Fork và RSI ở vùng oversold (trên 59 mặc định). Hệ thống cũng thiết lập dừng động 3%, tự động kiểm soát rủi ro khi giá di chuyển theo hướng không thuận lợi vượt quá phần trăm thiết lập. Ngoài ra, chiến lược cũng bao gồm bộ lọc thời gian, cho phép người dùng thiết lập phạm vi thời gian giao dịch cụ thể.
Đây là một chiến lược theo dõi xu hướng có cấu trúc, logic rõ ràng. Bằng cách sử dụng kết hợp MACD và RSI, chất lượng tín hiệu giao dịch được nâng cao hiệu quả. Thiết kế dừng động giúp kiểm soát rủi ro, giúp chiến lược có tính năng quản lý rủi ro tốt.
/*backtest
start: 2025-02-13 10:00:00
end: 2025-02-19 00:00:00
period: 1m
basePeriod: 1m
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/
// © eagle916
//@version=5
strategy("EAG MACD + RSI Strategy",overlay=true, initial_capital = 300, default_qty_value = 10, default_qty_type = "percent_of_equity", commission_type=strategy.commission.percent, commission_value=0.1)
// Input para el RSI
rsi_length = input.int(14, title="RSI Length", minval=1)
rsi_overbought = input.int(59, title="RSI Overbought Level", minval=1, maxval=100)
rsi_oversold = input.int(40, title="RSI Oversold Level", minval=1, maxval=100)
// Input para el MACD
macd_length = input.int(12, title="MACD Length", minval=1)
macd_overbought = input.int(26, title="MACD Overbought Level", minval=1, maxval=100)
macd_signal = input.int(9, title="MACD Signal Level", minval=1, maxval=100)
// Input para el porcentaje de pérdida (stop loss)
stop_loss_percent = input.float(3.0, title="Porcentaje de Stop Loss (%)", minval=0.1, step=0.1)
// Calcular RSI
rsi_value = ta.rsi(close, rsi_length)
// Calcular MACD
[macdLine, signalLine, _] = ta.macd(close, macd_length, macd_overbought, macd_signal)
macd_crossup = ta.crossover(macdLine, signalLine) // Cruce al alza del MACD
macd_crossdown = ta.crossunder(macdLine, signalLine) // Cruce a la baja del MACD
// Condiciones de compra y venta
buy_condition = macd_crossup and rsi_value <= rsi_oversold
sell_condition = macd_crossdown and rsi_value >= rsi_overbought
// Registrar precio de entrada
var float entry_price = na
if strategy.position_size == 0
entry_price := na
// Mostrar señales de compra y venta en la gráfica principal
plotshape(series=buy_condition, title="Señal de Compra", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") // Compra debajo de la vela
plotshape(series=sell_condition, title="Señal de Venta", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL") // Venta encima de la vela
// Órdenes de estrategia
if buy_condition
strategy.entry("Compra", strategy.long)
entry_price := close
if sell_condition
strategy.entry("Venta", strategy.short)
entry_price := close
// Calcular el precio de stop loss
long_stop_loss = entry_price * (1 - stop_loss_percent / 100)
short_stop_loss = entry_price * (1 + stop_loss_percent / 100)
// Cerrar posición si el precio va en contra el porcentaje definido por el usuario
if strategy.position_size > 0 and close < long_stop_loss
strategy.close("Compra", comment="Stop Loss Compra")
if strategy.position_size < 0 and close > short_stop_loss
strategy.close("Venta", comment="Stop Loss Venta")