
Chiến lược này kết hợp một đám mây biểu đồ cân bằng đầu tiên và các đường trung bình di chuyển đơn giản ngắn hạn (55) và dài hạn (200) để xác định tín hiệu mua bán tiềm năng. Các tín hiệu mua cần phải có giá cao hơn đám mây và SMA dài hạn và đi qua SMA ngắn hạn sau khi đi qua SMA ngắn hạn. Các tín hiệu bán cần phải có giá thấp hơn đám mây và SMA dài hạn và đi qua SMA ngắn hạn sau khi đi qua SMA ngắn hạn.
Chiến lược này dựa trên các nguyên tắc sau:
Chương trình đầu tiên tính toán các thành phần đám mây đầu tiên cần thiết ((đường chuyển đổi, đường chuẩn, span A và B), và SMA ngắn hạn và dài hạn. Sau đó, xác định nhiều điều kiện để xác định vị trí của giá so với đám mây và đường thẳng.
Chiến lược giao dịch nhiều đường trung bình trên một đám mây này tìm kiếm cơ hội đầu vào có rủi ro thấp để quay trở lại đường trung bình trong xu hướng đã được thiết lập bằng cách kết hợp đám mây biểu đồ cân bằng đầu tiên và đường trung bình di chuyển đơn giản. Bằng cách lọc các giao dịch trong các thị trường ngang và các sự kiện tin tức quan trọng, chiến lược này có thể làm giảm nguy cơ tín hiệu giả, do đó cải thiện hiệu suất tổng thể. Chiến lược này chủ yếu phù hợp với những người giao dịch trung bình dài hạn, hoạt động tốt trên các khung thời gian như 1 giờ và 2 giờ.
/*backtest
start: 2023-05-11 00:00:00
end: 2024-05-16 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Ichimoku Cloud and Moving Average Strategy", shorttitle="ICMA", overlay=true)
// Input parameters
shortMA = input.int(55, title="Short-term Moving Average Length")
longMA = input.int(200, title="Long-term Moving Average Length")
// Calculate moving averages
shortSMA = ta.sma(close, shortMA)
longSMA = ta.sma(close, longMA)
// Ichimoku Cloud settings
conversionPeriod = input.int(9, title="Conversion Line Period")
basePeriod = input.int(26, title="Base Line Period")
spanBPeriod = input.int(52, title="Span B Period")
displacement = input.int(26, title="Displacement")
// Calculate Ichimoku Cloud components
conversionLine = ta.sma(high + low, conversionPeriod) / 2
baseLine = ta.sma(high + low, basePeriod) / 2
leadSpanA = (conversionLine + baseLine) / 2
leadSpanB = ta.sma(high + low, spanBPeriod) / 2
// Plot Ichimoku Cloud components
plot(leadSpanA, color=color.blue, title="Leading Span A")
plot(leadSpanB, color=color.red, title="Leading Span B")
// Entry conditions
aboveCloud = close > leadSpanA and close > leadSpanB
belowCloud = close < leadSpanA and close < leadSpanB
aboveShortMA = close > shortSMA
aboveLongMA = close > longSMA
belowShortMA = close < shortSMA
belowLongMA = close < longSMA
// Buy condition (Price retests 55 moving average after being above it)
buyCondition = aboveCloud and aboveLongMA and close[1] < shortSMA and close > shortSMA
// Sell condition (Price retests 55 moving average after being below it)
sellCondition = belowCloud and belowLongMA and close[1] > shortSMA and close < shortSMA
// Strategy entry and exit
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.entry("Sell", strategy.short, when = sellCondition)
// Plot moving averages
plot(shortSMA, color=color.green, title="Short-term SMA")
plot(longSMA, color=color.red, title="Long-term SMA")
// Plot buy and sell signals
plotshape(series=buyCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(series=sellCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")