実現したいこと
以下のコードをpinescriptからmql4へ書き換えたいです
発生している問題・分からないこと
書き換えることができなかった
該当のソースコード
pinescript
1//@version=6 2indicator('Top/Bottom', overlay = true) 3 4devTooltip = 'Deviation is a multiplier that affects how much the price should deviate from the previous pivot in order for the bar to become a new pivot.' 5depthTooltip = 'The minimum number of bars that will be taken into account when calculating the indicator.' 6 7// Inputs 8threshold_multiplier = input.float(title = 'Deviation', defval = 2, minval = 0, tooltip = devTooltip, display = display.none) 9dev_threshold = ta.atr(10) / close * 100 * threshold_multiplier 10depth = input.int(title = 'Depth', defval = 14, minval = 1, tooltip = depthTooltip, display = display.none) 11LineColor = input.color(color.new(color.gray, 0), 'Line Color', display = display.none) 12deleteLastLine = input(false, 'Show Lines', display = display.none) 13ShapePlot = input(true, 'Plot marks', display = display.none) 14WhiteMode = input(true, 'White or Black Text', display = display.none) 15Periods = input.int(14, 'ATR Length', minval = 1, display = display.none) 16Multiplier = input.float(2.0, 'ATR Multiplier', minval = 0.1, maxval = 10, step = 0.1, display = display.none) 17changeATR = input.bool(true, 'Use ATR instead of SMA of True Range', display = display.none) 18 19// ATR Calculation 20atr2 = ta.sma(ta.tr, Periods) 21atr = changeATR ? ta.atr(Periods) : atr2 22 23// Trend Calculation 24up = close - Multiplier * atr 25up1 = nz(up[1], up) 26up := close[1] > up1 ? math.max(up, up1) : up 27dn = close + Multiplier * atr 28dn1 = nz(dn[1], dn) 29dn := close[1] < dn1 ? math.min(dn, dn1) : dn 30trend = 1 31trend := nz(trend[1], trend) 32trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend 33 34var line lineLast = na 35var int iLast = 0 36var int iPrev = 0 37var float pLast = 0 38var isHighLast = false 39var top = false 40var bottom = false 41 42pivots(src, length, isHigh) => 43 c = src[0] 44 ok = true 45 for i = 1 to length by 1 46 if isHigh and src[i] >= c 47 ok := false 48 ok 49 if not isHigh and src[i] <= c 50 ok := false 51 ok 52 if ok and trend == (isHigh ? 1 : -1) 53 [bar_index[0], c] 54 else 55 [int(na), float(na)] 56 57[iH, pH] = pivots(high, depth, true) 58[iL, pL] = pivots(low, depth, false) 59 60calc_dev(base_price, price) => 61 100 * (price - base_price) / price 62 63pivotFound(dev, isHigh, index, price) => 64 pivotH = false 65 if isHighLast == isHigh and not na(lineLast) 66 if isHighLast ? price > pLast : price < pLast 67 pivotH := true 68 line.set_xy2(lineLast, index, price) 69 [lineLast, isHighLast] 70 else 71 [line(na), bool(na)] 72 else 73 if math.abs(dev) > dev_threshold 74 id = line.new(iLast, pLast, index, price, color = LineColor, width = 2, style = line.style_dashed) 75 if ShapePlot 76 if isHigh 77 label.new(index, high, color = color.red, yloc = yloc.abovebar, style = label.style_label_down, text = 'Top', textcolor = WhiteMode ? color.white : color.black, size = size.normal) 78 else 79 label.new(index, low, color = color.green, yloc = yloc.belowbar, style = label.style_label_up, text = 'Bottom', textcolor = WhiteMode ? color.white : color.black, size = size.normal) 80 [id, isHigh] 81 else 82 [line(na), bool(na)] 83 84if not na(iH) 85 dev = calc_dev(pLast, pH) 86 [id, isHigh] = pivotFound(dev, true, iH, pH) 87 if not na(id) 88 if id != lineLast and not deleteLastLine 89 line.delete(lineLast) 90 lineLast := id 91 isHighLast := isHigh 92 iPrev := iLast 93 iLast := iH 94 pLast := pH 95 pLast 96else 97 if not na(iL) 98 dev = calc_dev(pLast, pL) 99 [id, isHigh] = pivotFound(dev, false, iL, pL) 100 if not na(id) 101 if id != lineLast and not deleteLastLine 102 line.delete(lineLast) 103 lineLast := id 104 isHighLast := isHigh 105 iPrev := iLast 106 iLast := iL 107 pLast := pL 108 pLast 109
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
チャート上に何も映らなかった
補足
特になし

あなたの回答
tips
プレビュー