设为首页 收藏本站 切换语言

Pine Script代码,改成MQL5代码。 Tradingview改成MT5 指标

| 发表于 2024-10-16 13:40:31 | 显示全部楼层 |复制链接
任务编号:126902 悬赏任务20H币 悬赏任务 : 按雇主需求进行任务后提交稿件,被采纳后即获得佣金。

距截止: 00天00时00分00秒 雇主已托管赏金:20 H币
雇主发布需求24.10.16 雇主托管佣金24.10.16 投稿者投稿 雇主开始选稿 任务完成

任务大厅共需1个合格投稿 | 每稿将获得20 H币 | 每人交稿次数不限 可多次任务

投诉举报 联系Ta 我来承接 已有0 个投稿 | 已采纳0 稿 | 拒绝0 稿 | 还需要1 稿

任务需求:
Pine Script代码,改成MQL5代码:

  1. //@version=5

  2. const int maxDistanceToLastBar = 5000
  3. const int labelCooldown = 8
  4. const int KDELimit = 300

  5. indicator("RSI短线", shorttitle = "RSI短线",overlay = true, max_labels_count = 500)

  6. rsiLengthInput = input.int(14, minval = 1, title="RSI Length", group="RSI Settings")
  7. rsiSourceInput = input.source(close, "Source", group="RSI Settings")

  8. highPivotLen = input.int(21,  "High Pivot Length", minval = 1, group = "Pivots", display = display.none)
  9. lowPivotLen = input.int(21, "Low Pivot Length", minval = 1, group = "Pivots", display = display.none)

  10. float KDEBandwidth = input.float(2.71828, "Bandwidth", group = "KDE", tooltip = "This setting sets the smoothness of the KDE function output.")
  11. int KDEStep = input.int(100, "Nº Bins", minval = 1, group = "KDE", tooltip = "The number of elements the KDE Probability array will have. Higher settings will result in greater precision.")

  12. bearishColor = input.color(#f23646, "High Pivots", group = "Style", inline = "col", display = display.none)
  13. bullishColor = input.color(#089981, "Low Pivots", group = "Style", inline = "col", display = display.none)

  14. rsi = ta.rsi(rsiSourceInput, rsiLengthInput)

  15. //#region KDE
  16. gaussian (float distance, float bandwidth = 1.0) => 1.0 / math.sqrt(2.0 * math.pi) * math.pow(math.e, -0.5 * math.pow(distance / bandwidth, 2.0))

  17. kde (array<float> arr, float bandwidth, int steps) =>
  18.     arrSize = arr.size()
  19.     arrRange = arr.range()
  20.     arrMin = arr.min()
  21.     stepCount = arrRange / steps
  22.    
  23.     densityRange = array.new<float>(steps * 2)
  24.     for i = 0 to (steps * 2) - 1
  25.         densityRange.set(i, arrMin + i * stepCount)
  26.    
  27.     xArr = array.new<float>()
  28.     yArr = array.new<float>()
  29.     for i = 0 to densityRange.size() - 1
  30.         float temp = 0
  31.         for j = 0 to arr.size() - 1
  32.             temp += gaussian(densityRange.get(i) - arr.get(j), 1.0 / bandwidth)

  33.         
  34.         xArr.push(densityRange.get(i))
  35.         yArr.push(1.0 / arrSize * temp)
  36.     [xArr, yArr]
  37. //#endregion

  38. //#region Pivots

  39. prefixSum (array<float> arr, int l, int r) =>
  40.     arr.get(r) - (l == 0 ? 0 : arr.get(l - 1))

  41. float MidKDEHigh = na
  42. float MidKDELow = na

  43. var array<float> KDEHighX = na
  44. var array<float> KDEHighY = na
  45. var array<float> KDEHighYSum = array.new<float>()

  46. var array<float> KDELowX = na
  47. var array<float> KDELowY = na
  48. var array<float> KDELowYSum = array.new<float>()

  49. highPivot = ta.pivothigh(highPivotLen, highPivotLen)
  50. lowPivot = ta.pivotlow(lowPivotLen, lowPivotLen)

  51. var highPivotRSIs = array.new<float>()
  52. var lowPivotRSIs = array.new<float>()

  53. if not na(highPivot)
  54.     if highPivotRSIs.size() > KDELimit
  55.         highPivotRSIs.remove(0)
  56.     highPivotRSIs.push(rsi[highPivotLen])

  57.     [KDEHighX1, KDEHighY1] = kde(highPivotRSIs, KDEBandwidth, KDEStep)
  58.     KDEHighX := KDEHighX1
  59.     KDEHighY := KDEHighY1
  60.    
  61.     KDEHighYSum.clear()
  62.     temp = 0.0
  63.     for i = 0 to KDEHighY.size() - 1
  64.         temp += KDEHighY.get(i)
  65.         KDEHighYSum.push(temp)

  66.     MidKDEHigh := array.get(KDEHighX, array.indexof(KDEHighY, array.max(KDEHighY)))

  67. if not na(lowPivot)
  68.     if lowPivotRSIs.size() > KDELimit
  69.         lowPivotRSIs.remove(0)
  70.     lowPivotRSIs.push(rsi[lowPivotLen])

  71.     [KDELowX1, KDELowY1] = kde(lowPivotRSIs, KDEBandwidth, KDEStep)
  72.     KDELowX := KDELowX1
  73.     KDELowY := KDELowY1

  74.     KDELowYSum.clear()
  75.     temp = 0.0
  76.     for i = 0 to KDELowY.size() - 1
  77.         temp += KDELowY.get(i)
  78.         KDELowYSum.push(temp)

  79.     MidKDELow := array.get(KDELowX, array.indexof(KDELowY, array.max(KDELowY)))
  80. //#endregion

  81. //#region KDE Optimization
  82. f_lin_interpolate(float x0, float x1, float y0, float y1, float x) =>
  83.     y0 + (x - x0) * (y1 - y0) / (x1 - x0)

  84. float lowProb = na
  85. float maxLowProb = na
  86. float highProb = na
  87. float maxHighProb = na

  88. if last_bar_index - maxDistanceToLastBar < bar_index
  89.     if highPivotRSIs.size() > 0
  90.         highXIndexL = array.binary_search_leftmost(KDEHighX, rsi)
  91.         highXIndexR = math.min(array.binary_search_rightmost(KDEHighX, rsi), KDEHighX.size() - 1)
  92.         nearestIndex = (math.abs(rsi - KDEHighX.get(highXIndexL)) < math.abs(rsi - KDEHighX.get(highXIndexR))) ? highXIndexL : highXIndexR
  93.         highProb := prefixSum(KDEHighYSum, 0, nearestIndex)
  94.    
  95.     if lowPivotRSIs.size() > 0
  96.         lowXIndexL = array.binary_search_leftmost(KDELowX, rsi)
  97.         lowXIndexR = math.min(array.binary_search_rightmost(KDELowX, rsi), KDELowX.size() - 1)
  98.         nearestIndex = (math.abs(rsi - KDELowX.get(lowXIndexL)) < math.abs(rsi - KDELowX.get(lowXIndexR))) ? lowXIndexL : lowXIndexR
  99.         lowProb := prefixSum(KDELowYSum, nearestIndex, KDELowYSum.size() - 1)


  100. diffToHighKDE = math.abs(rsi - MidKDEHigh)
  101. diffToLowKDE = math.abs(rsi - MidKDELow)
  102. //#endregion

  103. //#region Draw Pivots
  104. color curColor = na
  105. if (not na(KDELowY)) and (not na(KDEHighY))

  106.     if lowProb > KDELowY.sum() * 0.75
  107.         curColor := bullishColor
  108.     else if highProb > KDEHighY.sum() * 0.75
  109.         curColor := bearishColor
  110. //barcolor(curColor)

  111. atr = ta.atr(50)

  112. long = na(curColor) and curColor[1] == bullishColor and barstate.isconfirmed
  113. short = na(curColor) and curColor[1] == bearishColor and barstate.isconfirmed

  114. plotarrow(long ? 1 : na, "Possible Bullish Pivot", bullishColor, bullishColor, minheight = 20, maxheight = 20)
  115. plotarrow(short ? -1 : na, "Possible Bearish Pivot", bearishColor, bearishColor, minheight = 20, maxheight = 20)
复制代码
任务需求补充bigwin 补充于2024-10-16 20:40
[code]//+------------------------------------------------------------------+ //|
任务需求补充bigwin 补充于2024-10-16 20:39
#property copyright \"Copyright 2024,TradingVUE Ltd.\" #property link \"https://www.tradingvue
任务需求补充bigwin 补充于2024-10-16 20:38
//+------------------------------------------------------------------+ //|
举报

评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)