
이 전략은 클라우드 확장, 이동 평균 집적 지표 (MACD) 및 트렌드 지표 (DMI) 의 신호를 여러 시간 프레임에 걸쳐 통합하여 잠재적인 구매 및 판매 기회를 식별합니다. 이 전략은 단기 및 중기 두 차원에서 시장을 살펴보고자하는 거래자에게 참고 자료를 제공하기위한 것입니다.
이 전략은 구매 및 판매 조건을 수행하기 위해 15 분 (M15) 및 1 시간 (H1) 차트에 대한 일치 신호를 기반으로하며, 추가 확인이 되도록 4 시간 (H4) 시간 프레임을 참조합니다.
이 전략은 다중 시간 프레임 분석과 여러 지표의 장점을 최대한 활용하여 트렌드의 방향과 강도를 효과적으로 식별할 수 있습니다. 매개 변수를 조정하여 다양한 품종에 적용할 수 있으며 특정 상황에 맞게 최적화 할 수 있습니다. 그러나 거래자는 지표 자체의 한계를 염두에 두고 적절한 위험 통제 조치를 취해야합니다.
/*backtest
start: 2024-01-25 00:00:00
end: 2024-02-01 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © haidinh83
//@version=5
strategy("Ichimoku, MACD, DMI Multiple time frame 21/01/2024", overlay=true)
// Khung thời gian
timeframe1 = "5" // M5
timeframe2 = "15" // M15
timeframe3 = "60" // H1
timeframe4 = "240" // H4
// Nhập tham số ADX và DI
lengthDMI = input(14, title="DMI Length")
thresholdADX = input(20, title="ADX Threshold")
// Tính giá trị Ichimoku
ichimoku(tenkanPeriod, kijunPeriod, senkouPeriod) =>
tenkanSen = (ta.highest(high, tenkanPeriod) + ta.lowest(low, tenkanPeriod)) / 2
kijunSen = (ta.highest(high, kijunPeriod) + ta.lowest(low, kijunPeriod)) / 2
senkouSpanA = (tenkanSen + kijunSen) / 2
senkouSpanB = (ta.highest(high, senkouPeriod) + ta.lowest(low, senkouPeriod)) / 2
[tenkanSen, kijunSen, senkouSpanA, senkouSpanB]
// Lấy Ichimoku từng khung thời gian
[tenkanM5, kijunM5, spanAM5, spanBM5] = request.security(syminfo.tickerid, timeframe1, ichimoku(9, 26, 52))
[tenkanM15, kijunM15, spanAM15, spanBM15] = request.security(syminfo.tickerid, timeframe2, ichimoku(9, 26, 52))
[tenkanH1, kijunH1, spanAH1, spanBH1] = request.security(syminfo.tickerid, timeframe3, ichimoku(9, 26, 52))
[tenkanH4, kijunH4, spanAH4, spanBH4] = request.security(syminfo.tickerid, timeframe4, ichimoku(9, 26, 52))
// Tính giá trị MACD và Signal Line cho từng khung thời gian
[macdM5, signalM5, _] = request.security(syminfo.tickerid, timeframe1, ta.macd(close, 12, 26, 9))
[macdM15, signalM15, _] = request.security(syminfo.tickerid, timeframe2, ta.macd(close, 12, 26, 9))
[macdH1, signalH1, _] = request.security(syminfo.tickerid, timeframe3, ta.macd(close, 12, 26, 9))
[macdH4, signalH4, _] = request.security(syminfo.tickerid, timeframe4, ta.macd(close, 12, 26, 9))
// Tính giá trị DMI cho từng khung thời gian
calcDMI(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / trur)
minus = fixnan(100 * ta.rma(minusDM, len) / trur)
adx = 100 * ta.rma(math.abs(plus - minus) / (plus + minus == 0 ? 1 : plus + minus), len)
[plus, minus, adx] // Đảm bảo mỗi phần của hàm nằm trên một dòng riêng biệt
[plusM5, minusM5, adxM5] = request.security(syminfo.tickerid, timeframe1, calcDMI(lengthDMI))
[plusM15, minusM15, adxM15] = request.security(syminfo.tickerid, timeframe2, calcDMI(lengthDMI))
[plusH1, minusH1, adxH1] = request.security(syminfo.tickerid, timeframe3, calcDMI(lengthDMI))
[plusH4, minusH4, adxH4] = request.security(syminfo.tickerid, timeframe4, calcDMI(lengthDMI))
// Điều kiện mua cho H1
buyConditionH1 = (close > spanAM15) and (close > spanAH1) and (close > spanAH4) and
(macdH1 > signalH1) and (macdH1 > 0) and (signalH1 > 0) and
(plusH1 > minusH1) and (adxH1 >= 25)
// Điều kiện mua cho M15
buyConditionM15 = (close > spanAM15) and (close > spanAH1) and (close > spanAH4) and
(macdM15 > 0) and (plusM15 > minusM15) and (adxM15 >= 25)
// Điều kiện mua tổng hợp
buyCondition = buyConditionH1 and buyConditionM15
// Điều kiện bán cho H1
sellConditionH1 = (close < spanAM15) and (close < spanAH1) and (close < spanAH4) and
(macdH1 < signalH1) and (macdH1 < 0) and (signalH1 < 0) and
(minusH1 > plusH1) and (adxH1 >= 25)
// Điều kiện bán cho M15
sellConditionM15 = (close < spanAM15) and (close < spanAH1) and (close < spanAH4) and
(macdM15 < 0) and (minusM15 > plusM15) and (adxM15 >= 25)
// Điều kiện bán tổng hợp
sellCondition = sellConditionH1 and sellConditionM15
// Thực hiện giao dịch nếu điều kiện bán hoặc mua được đáp ứng
if buyCondition
strategy.entry("Buy", strategy.long)
if sellCondition
strategy.entry("Sell", strategy.short)
// Vẽ và tô màu giữa Senkou Span A và B cho mỗi khung thời gian
p1 = plot(spanAM15, color=color.blue, title="Span A M15")
p2 = plot(spanBM15, color=color.blue, title="Span B M15")
fill(p1, p2, color=color.new(color.blue, 90), title="M15 Cloud")
p3 = plot(spanAH1, color=color.purple, title="Span A H1")
p4 = plot(spanBH1, color=color.purple, title="Span B H1")
fill(p3, p4, color=color.new(color.purple, 90), title="H1 Cloud")
p5 = plot(spanAH4, color=color.orange, title="Span A H4")
p6 = plot(spanBH4, color=color.orange, title="Span B H4")
fill(p5, p6, color=color.new(color.orange, 90), title="H4 Cloud")
// Tô màu nền và hiển thị cảnh báo
bgcolor(buyCondition ? color.new(color.green, 45) : sellCondition ? color.new(color.red, 45) : na)
alertcondition(buyCondition, title="Mua Signal", message="Điều kiện mua đã được đáp ứng")
alertcondition(sellCondition, title="Bán Signal", message="Điều kiện bán đã được đáp ứng")