pinescriptからmql4へ
解決したいこと
このpinescriptのコードをmql4に書き換えようとしましたができません
どなたかよろしくお願いいたします
該当するソースコード
//@version=6
indicator('Top/Bottom', overlay = true)
devTooltip = '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.'
depthTooltip = 'The minimum number of bars that will be taken into account when calculating the indicator.'
// Inputs
threshold_multiplier = input.float(title = 'Deviation', defval = 2, minval = 0, tooltip = devTooltip, display = display.none)
dev_threshold = ta.atr(10) / close * 100 * threshold_multiplier
depth = input.int(title = 'Depth', defval = 14, minval = 1, tooltip = depthTooltip, display = display.none)
LineColor = input.color(color.new(color.gray, 0), 'Line Color', display = display.none)
deleteLastLine = input(false, 'Show Lines', display = display.none)
ShapePlot = input(true, 'Plot marks', display = display.none)
WhiteMode = input(true, 'White or Black Text', display = display.none)
Periods = input.int(14, 'ATR Length', minval = 1, display = display.none)
Multiplier = input.float(2.0, 'ATR Multiplier', minval = 0.1, maxval = 10, step = 0.1, display = display.none)
changeATR = input.bool(true, 'Use ATR instead of SMA of True Range', display = display.none)
// ATR Calculation
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
// Trend Calculation
up = close - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = close + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
var line lineLast = na
var int iLast = 0
var int iPrev = 0
var float pLast = 0
var isHighLast = false
var top = false
var bottom = false
pivots(src, length, isHigh) =>
c = src[0]
ok = true
for i = 1 to length by 1
if isHigh and src[i] >= c
ok := false
ok
if not isHigh and src[i] <= c
ok := false
ok
if ok and trend == (isHigh ? 1 : -1)
[bar_index[0], c]
else
[int(na), float(na)]
[iH, pH] = pivots(high, depth, true)
[iL, pL] = pivots(low, depth, false)
calc_dev(base_price, price) =>
100 * (price - base_price) / price
pivotFound(dev, isHigh, index, price) =>
pivotH = false
if isHighLast == isHigh and not na(lineLast)
if isHighLast ? price > pLast : price < pLast
pivotH := true
line.set_xy2(lineLast, index, price)
[lineLast, isHighLast]
else
[line(na), bool(na)]
else
if math.abs(dev) > dev_threshold
id = line.new(iLast, pLast, index, price, color = LineColor, width = 2, style = line.style_dashed)
if ShapePlot
if isHigh
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)
else
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)
[id, isHigh]
else
[line(na), bool(na)]
if not na(iH)
dev = calc_dev(pLast, pH)
[id, isHigh] = pivotFound(dev, true, iH, pH)
if not na(id)
if id != lineLast and not deleteLastLine
line.delete(lineLast)
lineLast := id
isHighLast := isHigh
iPrev := iLast
iLast := iH
pLast := pH
pLast
else
if not na(iL)
dev = calc_dev(pLast, pL)
[id, isHigh] = pivotFound(dev, false, iL, pL)
if not na(id)
if id != lineLast and not deleteLastLine
line.delete(lineLast)
lineLast := id
isHighLast := isHigh
iPrev := iLast
iLast := iL
pLast := pL
pLast
0 likes