teratail header banner
teratail header banner
質問するログイン新規登録

質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.30%
MQL4

MQL4とは、MT4(MetaTrader4)で用いられるプログラム言語です。MT4は無料で使えるチャートソフトあり、MQL4を使うことで分析ツールのオリジナルスクリプトの作成ができます。

PineScript

PineScriptは、チャートツールであるTradingView向けに作られたプログラミング言語です。独自のインジケーターやストラテジーを作成できます。拡張性に優れ、シンプルな文法で比較的少ない手順で作成することが可能です。

Q&A

0回答

78閲覧

pinescriptからmql4へ

V_V_V

総合スコア0

MQL4

MQL4とは、MT4(MetaTrader4)で用いられるプログラム言語です。MT4は無料で使えるチャートソフトあり、MQL4を使うことで分析ツールのオリジナルスクリプトの作成ができます。

PineScript

PineScriptは、チャートツールであるTradingView向けに作られたプログラミング言語です。独自のインジケーターやストラテジーを作成できます。拡張性に優れ、シンプルな文法で比較的少ない手順で作成することが可能です。

0グッド

0クリップ

投稿2025/06/12 07:32

0

0

実現したいこと

以下のコードを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等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

チャート上に何も映らなかった

補足

特になし

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問