Chiến lược này là một hệ thống giao dịch dải dao động được xây dựng dựa trên đường trung bình di chuyển của chỉ số 300 chu kỳ (EMA). Bằng cách kết hợp EMA và chênh lệch tiêu chuẩn, tạo ra một dải dao động động giống như dải Brin để nắm bắt cơ hội mua quá mức và bán quá mức của thị trường. Chiến lược này chủ yếu tạo ra tín hiệu giao dịch bằng cách giao giá với dải dao động và đặt các điều kiện dừng dựa trên phần trăm.
Trung tâm của chiến lược là thiết lập trung tâm giá thông qua 300 chu kỳ EMA, sau đó sử dụng chênh lệch tiêu chuẩn để xây dựng các vùng dao động lên xuống. Khi giá phá vỡ đường mòn, nó được coi là tín hiệu bán tháo và khi phá vỡ đường mòn, nó được coi là tín hiệu mua tháo.
Chiến lược này nắm bắt cơ hội bán tháo thị trường thông qua dải dao động EMA, quy tắc giao dịch rõ ràng, hoạt động đơn giản. Tuy nhiên, trong ứng dụng thực tế, cần chú ý kiểm soát rủi ro, khuyến nghị nâng cao sự ổn định của chiến lược bằng cách thêm các chỉ số phụ trợ, thiết lập tham số tối ưu hóa. Chiến lược được thiết kế hợp lý, có giá trị thực tế tốt và không gian tối ưu hóa.
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Estrategia de Compra/Venta en Bandas de EMA 300", overlay=true)
// Definir el período de la EMA
periodo = input.int(300, title="Período de la EMA")
// Calcular la EMA de 300
ema_300 = ta.ema(close, periodo)
// Definir el número de desviaciones estándar
num_desviaciones = input.float(2, title="Número de Desviaciones Estándar")
// Calcular la desviación estándar de la EMA de 300
desviacion = ta.stdev(close, periodo)
// Calcular los límites superior e inferior de las bandas
banda_superior = ema_300 + desviacion * num_desviaciones
banda_inferior = ema_300 - desviacion * num_desviaciones
// Definir el porcentaje para las señales de compra y venta
porcentaje = input.float(0.98, title="Porcentaje de Salida de Banda")
// Definir señales de compra y venta
compra = ta.crossover(close, banda_inferior)
venta = ta.crossunder(close, banda_superior)
// Calcular el precio de salida para las señales de compra y venta
precio_salida_compra = close * (1 + porcentaje / 100)
precio_salida_venta = close * (1 - porcentaje / 100)
// Plotear las bandas
plot(banda_superior, color=color.blue, linewidth=2, title="Banda Superior")
plot(banda_inferior, color=color.red, linewidth=2, title="Banda Inferior")
// Plotear las señales de compra y venta
plotshape(compra, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Compra")
plotshape(venta, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Venta")
// Simular operaciones
if (compra)
strategy.entry("Compra", strategy.long)
if (venta)
strategy.entry("Venta", strategy.short)
// Definir reglas de salida
if (strategy.position_size > 0)
strategy.exit("Exit Long", from_entry="Compra", limit=precio_salida_compra)
if (strategy.position_size < 0)
strategy.exit("Exit Short", from_entry="Venta", limit=precio_salida_venta)
// Crear alertas
alertcondition(compra, title="Alerta de Compra", message="¡Señal de Compra Detectada!")
alertcondition(venta, title="Alerta de Venta", message="¡Señal de Venta Detectada!")
// Mostrar alertas en el gráfico
if (compra)
label.new(bar_index, low, text="Compra", style=label.style_label_up, color=color.green, textcolor=color.white)
if (venta)
label.new(bar_index, high, text="Venta", style=label.style_label_down, color=color.red, textcolor=color.white)