Advertisement
Haiichi

xanh mua đỏ bán

Jan 21st, 2024
353
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © haidinh83
  3.  
  4. //@version=5
  5. strategy("Ichimoku, MACD, DMI Multiple time frame 21/01/2024", overlay=true)
  6.     // Khung thời gian
  7. timeframe1 = "5"   // M5
  8. timeframe2 = "15"  // M15
  9. timeframe3 = "60"  // H1
  10. timeframe4 = "240" // H4
  11.  
  12.     // Nhập tham số ADX và DI
  13. lengthDMI = input(14, title="DMI Length")
  14. thresholdADX = input(20, title="ADX Threshold")
  15.  
  16. // Tính giá trị Ichimoku
  17. ichimoku(tenkanPeriod, kijunPeriod, senkouPeriod) =>
  18.     tenkanSen = (ta.highest(high, tenkanPeriod) + ta.lowest(low, tenkanPeriod)) / 2
  19.     kijunSen = (ta.highest(high, kijunPeriod) + ta.lowest(low, kijunPeriod)) / 2
  20.     senkouSpanA = (tenkanSen + kijunSen) / 2
  21.     senkouSpanB = (ta.highest(high, senkouPeriod) + ta.lowest(low, senkouPeriod)) / 2
  22.     [tenkanSen, kijunSen, senkouSpanA, senkouSpanB]
  23.  
  24.     // Lấy Ichimoku từng khung thời gian
  25. [tenkanM5, kijunM5, spanAM5, spanBM5] = request.security(syminfo.tickerid, timeframe1, ichimoku(9, 26, 52))
  26. [tenkanM15, kijunM15, spanAM15, spanBM15] = request.security(syminfo.tickerid, timeframe2, ichimoku(9, 26, 52))
  27. [tenkanH1, kijunH1, spanAH1, spanBH1] = request.security(syminfo.tickerid, timeframe3, ichimoku(9, 26, 52))
  28. [tenkanH4, kijunH4, spanAH4, spanBH4] = request.security(syminfo.tickerid, timeframe4, ichimoku(9, 26, 52))
  29.  
  30.     // Tính giá trị MACD và Signal Line cho từng khung thời gian
  31. [macdM5, signalM5, _] = request.security(syminfo.tickerid, timeframe1, ta.macd(close, 12, 26, 9))
  32. [macdM15, signalM15, _] = request.security(syminfo.tickerid, timeframe2, ta.macd(close, 12, 26, 9))
  33. [macdH1, signalH1, _] = request.security(syminfo.tickerid, timeframe3, ta.macd(close, 12, 26, 9))
  34. [macdH4, signalH4, _] = request.security(syminfo.tickerid, timeframe4, ta.macd(close, 12, 26, 9))
  35.  
  36.   // Tính giá trị DMI cho từng khung thời gian
  37. calcDMI(len) =>
  38.     up = ta.change(high)
  39.     down = -ta.change(low)
  40.     plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  41.     minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  42.     trur = ta.rma(ta.tr, len)
  43.     plus = fixnan(100 * ta.rma(plusDM, len) / trur)
  44.     minus = fixnan(100 * ta.rma(minusDM, len) / trur)
  45.     adx = 100 * ta.rma(math.abs(plus - minus) / (plus + minus == 0 ? 1 : plus + minus), len)
  46.     [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
  47.  
  48.  
  49. [plusM5, minusM5, adxM5] = request.security(syminfo.tickerid, timeframe1, calcDMI(lengthDMI))
  50. [plusM15, minusM15, adxM15] = request.security(syminfo.tickerid, timeframe2, calcDMI(lengthDMI))
  51. [plusH1, minusH1, adxH1] = request.security(syminfo.tickerid, timeframe3, calcDMI(lengthDMI))
  52. [plusH4, minusH4, adxH4] = request.security(syminfo.tickerid, timeframe4, calcDMI(lengthDMI))
  53. //and (close > spanAH4)
  54. // and (close > spanAH4)
  55.  
  56.  
  57. // Điều kiện mua cho H1
  58. buyConditionH1 = (close > spanAM15) and (close > spanAH1)  and (macdH1 > signalH1) and (macdH1 > 0) and (close > spanAH4) and (signalH1 > 0) and (plusH1 > minusH1) and ((adxH1 >= 25) or plusH1
  59.  >= 25)
  60.  
  61. // Điều kiện mua cho M15
  62. buyConditionM15 = (close > spanAM15) and (close > spanAH1) and (macdM15 > 0) and (plusM15 > minusM15) and (close > spanAH4) and (adxM15 >= 25) and minusM15 >= 25
  63.  
  64. // Điều kiện mua tổng hợp
  65. buyCondition = buyConditionH1 and buyConditionM15
  66.  
  67. // Điều kiện bán cho H1
  68. sellConditionH1 = (close < spanAM15) and (close < spanAH1) and (close < spanAH4) and
  69.                   (macdH1 < signalH1) and (macdH1 < 0) and (signalH1 < 0) and
  70.                   (minusH1 > plusH1) and ((adxH1 >= 25) or minusH1 >= 25)
  71.  
  72. // Điều kiện bán cho M15
  73. sellConditionM15 = (close < spanAM15) and (close < spanAH1) and (close < spanAH4) and
  74.                    (macdM15 < 0) and (minusM15 > plusM15) and ((adxM15 >= 25) or minusM15 >= 25)
  75.  
  76. // Điều kiện bán tổng hợp
  77. sellCondition = sellConditionH1 and sellConditionM15
  78.  
  79. // Thực hiện giao dịch nếu điều kiện bán hoặc mua được đáp ứng
  80. if buyCondition
  81.     strategy.entry("Buy", strategy.long)
  82.  
  83. if sellCondition
  84.     strategy.entry("Sell", strategy.short)
  85.  
  86.  
  87.     // Vẽ và tô màu giữa Senkou Span A và B cho mỗi khung thời gian
  88. p1 = plot(spanAM15, color=color.blue, title="Span A M15")
  89. p2 = plot(spanBM15, color=color.blue, title="Span B M15")
  90. fill(p1, p2, color=color.new(color.blue, 90), title="M15 Cloud")
  91.  
  92. p3 = plot(spanAH1, color=color.purple, title="Span A H1")
  93. p4 = plot(spanBH1, color=color.purple, title="Span B H1")
  94. fill(p3, p4, color=color.new(color.purple, 90), title="H1 Cloud")
  95.  
  96. p5 = plot(spanAH4, color=color.orange, title="Span A H4")
  97. p6 = plot(spanBH4, color=color.orange, title="Span B H4")
  98. fill(p5, p6, color=color.new(color.orange, 90), title="H4 Cloud")
  99.  
  100.     // Tô màu nền và hiển thị cảnh báo
  101.  
  102. bgcolor(buyCondition ? color.new(color.green, 45) : sellCondition ? color.new(color.red, 45) : na)
  103. alertcondition(buyCondition, title="Mua Signal", message="Điều kiện mua đã được đáp ứng")
  104. alertcondition(sellCondition, title="Bán Signal", message="Điều kiện bán đã được đáp ứng")
  105.  
  106.  
Advertisement
Comments
  • tradingviewcodes
    117 days
    # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement