
Đây là một chiến lược theo dõi xu hướng thông minh dựa trên tín hiệu chéo của nhiều chỉ số kỹ thuật. Chiến lược này tích hợp ba chỉ số kỹ thuật lớn là đường trung bình di chuyển (EMA), đường trung bình tương đối mạnh (RSI) và đường trung bình di chuyển (MACD) để xác định xu hướng thị trường thông qua tín hiệu đa chiều và quản lý rủi ro bằng cách kết hợp với lệnh dừng lỗ động.
Lập luận cốt lõi của chiến lược này dựa trên 3 lớp lọc các chỉ số kỹ thuật:
Tạo ra một tín hiệu nhập cảnh phải đáp ứng các điều kiện sau:
Chiến lược này sử dụng mô hình nắm giữ tỷ lệ phần trăm vốn, sử dụng quyền lợi tài khoản 10% cho mỗi giao dịch và kiểm soát rủi ro với 2% dừng và 1% dừng.
Đề xuất kiểm soát rủi ro:
Chiến lược này xây dựng một hệ thống theo dõi xu hướng tương đối hoàn hảo thông qua sự phối hợp của nhiều chỉ số kỹ thuật. Ưu điểm của chiến lược là tín hiệu có độ tin cậy cao, quản lý rủi ro hoàn hảo, nhưng cũng có một sự chậm trễ và phụ thuộc vào môi trường thị trường. Bằng hướng tối ưu hóa được đề xuất, chiến lược có thể nâng cao hơn nữa khả năng thích ứng và ổn định của nó.
/*backtest
start: 2024-02-22 00:00:00
end: 2025-02-19 08:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © egidiopalmieri
//@version=5
strategy("BTCUSD Intraday - AI-like Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1)
// ==========================
// Risk and Strategy Parameters
// ==========================
takeProfitPerc = input.float(2.0, "Take Profit (%)", step=0.1) / 100.0 // Target profit: 2%
stopLossPerc = input.float(1.0, "Stop Loss (%)", step=0.1) / 100.0 // Stop loss: 1%
// ==========================
// Technical Indicators
// ==========================
emaShortPeriod = input.int(9, "Short EMA (period)", minval=1)
emaLongPeriod = input.int(21, "Long EMA (period)", minval=1)
emaShort = ta.ema(close, emaShortPeriod)
emaLong = ta.ema(close, emaLongPeriod)
// RSI Indicator
rsiPeriod = input.int(14, "RSI (period)", minval=1)
rsiValue = ta.rsi(close, rsiPeriod)
// MACD Indicator
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
// ==========================
// Entry Conditions
// ==========================
// LONG entry: short EMA crosses above long EMA, RSI not in overbought zone, MACD in bullish trend
longCondition = ta.crossover(emaShort, emaLong) and (rsiValue < 70) and (macdLine > signalLine)
// SHORT entry: short EMA crosses below long EMA, RSI not in oversold zone, MACD in bearish trend
shortCondition = ta.crossunder(emaShort, emaLong) and (rsiValue > 30) and (macdLine < signalLine)
// ==========================
// Signal Visualization
// ==========================
plotshape(longCondition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Long")
plotshape(shortCondition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")
// ==========================
// Entry Logic
// ==========================
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// ==========================
// Stop Loss and Take Profit Management
// The levels are calculated dynamically based on the average entry price
// ==========================
if strategy.position_size > 0
// For long positions
longSL = strategy.position_avg_price * (1 - stopLossPerc)
longTP = strategy.position_avg_price * (1 + takeProfitPerc)
strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)
if strategy.position_size < 0
// For short positions
shortSL = strategy.position_avg_price * (1 + stopLossPerc)
shortTP = strategy.position_avg_price * (1 - takeProfitPerc)
strategy.exit("Exit Short", from_entry="Short", stop=shortSL, limit=shortTP)
// ==========================
// Final Notes
// ==========================
// This script uses rules based on technical indicators to generate signals
// "AI-like". The integration of actual AI algorithms is not natively supported in PineScript.
// It is recommended to customize, test, and validate the strategy before using it in live trading.