Complete Suite: all 12 tools. 6 Premium desks inside.All 12 tools $606.98 one by one

$606.98 one by one $97 once Save $509.98Get the SuiteGet it

MQL4 to Pine Script converter

Paste an MQL4 (.mq4) indicator or EA and read the Pine Script v6 beside it, line for line, with TODOs marked.

Updated 11 November 2026. Runs in your browser; nothing you type is uploaded.

Sample .mq4 indicatorPine Script v6, ready to paste

Pine Script v6numbers: MQL4 source line

//@version=6
indicator("Dual EMA + RSI Trend Filter", overlay = true)
FastLen = input.int(21, "Fast EMA Length")
SlowLen = input.int(55, "Slow EMA Length")
RsiLen = input.int(14, "RSI Length")
rsi = ta.rsi(close, RsiLen)
FastBuf = ta.ema(close, FastLen)
SlowBuf = ta.ema(close, SlowLen)
plot(FastBuf, "Fast EMA", color = color.blue, linewidth = 2)
plot(SlowBuf, "Slow EMA", color = color.orange, linewidth = 2)

Indicator draft: MQL4 buffers unfolded into Pine v6 series

All 7 MQL4 statements converted to Pine v6

Static v6 & repaint check passed with no flags. TradingView's Pine Editor compiler is the final word.

  • NoteMQL4 bar loop (i) unfolded: Pine evaluates every expression once per bar automatically.

Share this calculator

Post on XPost to Reddit
Embed or cite it on your site

Free on any site, blog, Notion page or Substack: paste this code to show the live calculator. The credit line is optional; keep it, edit it, add rel="nofollow" or remove it.

<iframe src="https://proea.app/embed/tools/mql4-to-pine-script-converter" title="MQL4 to Pine Script converter" loading="lazy" referrerpolicy="strict-origin-when-cross-origin" style="display:block;width:100%;height:820px;border:0;border-radius:12px"></iframe>
<p style="font-size:12px">MQL4 to Pine Script converter by <a href="https://proea.app/en/tools/mql4-to-pine-script-converter?utm_source=embed&utm_medium=referral&utm_campaign=mql4-to-pine-script-converter">ProEA</a></p>

Writing about it instead? Cite the method and link the page:

The math: iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 0) = ta.ema(close, 21) · SetIndexBuffer = plot()

MQL4 indicator functions in Pine Script v6

Generated directly by pineForMql4() at build time so every row matches the live converter.

MQL4 (.mq4)Pine Script v6
double x = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 0);x = ta.ema(close, 21)
double x = iMA(NULL, 0, 50, 0, MODE_SMA, PRICE_CLOSE, 1);x = ta.sma(close, 50)[1]
double x = iMA(NULL, 0, 14, 0, MODE_SMMA, PRICE_MEDIAN, 0);x = ta.rma(hl2, 14)
double x = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);x = ta.rsi(close, 14)
double x = iATR(NULL, 0, 14, 0);x = ta.atr(14)
double x = iCCI(NULL, 0, 20, PRICE_TYPICAL, 0);x = ta.cci(hlc3, 20)
double x = iBands(NULL, 0, 20, 2.0, 0, PRICE_CLOSE, MODE_UPPER, 0);x = (ta.sma(close, 20) + 2.0 * ta.stdev(close, 20))
double x = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0);x = (ta.ema(close, 12) - ta.ema(close, 26))
double x = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);x = ta.sma((ta.ema(close, 12) - ta.ema(close, 26)), 9)
double x = iStochastic(NULL, 0, 14, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);x = ta.sma(ta.stoch(close, high, low, 14), 3)
double x = High[iHighest(NULL, 0, MODE_HIGH, 20, 1)];x = ta.highest(high, 20)[1]
int barIdx = iHighest(NULL, 0, MODE_HIGH, 20, 0);barIdx = (-ta.highestbars(high, 20))
double x = MathMax(MathAbs(Close[0] - Open[0]), Point);x = math.max(math.abs(close - open), syminfo.mintick)

Higher timeframes and external symbols

MQL4 passes PERIOD_D1 or PERIOD_H4 inside any indicator call; Pine routes them through request.security().

MQL4 (.mq4)Pine Script v6
double x = iClose(NULL, PERIOD_D1, 1);x = request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)
double x = iHigh(NULL, PERIOD_H4, 1);x = request.security(syminfo.tickerid, "240", high[1], lookahead = barmerge.lookahead_on)
double x = iMA(NULL, PERIOD_H1, 20, 0, MODE_EMA, PRICE_CLOSE, 1);x = request.security(syminfo.tickerid, "60", ta.ema(close, 20)[1], lookahead = barmerge.lookahead_on)
double x = iClose("EURUSD", PERIOD_D1, 1);x = request.security("EURUSD", "D", close[1], lookahead = barmerge.lookahead_on)
Why shift 1 on higher timeframes prevents historical repainting

In MetaTrader 4, calling iHigh(NULL, PERIOD_D1, 0) on an M15 chart reads today's developing daily high, whereas shift 1 reads yesterday's completed daily bar. In Pine Script v6, request.security(syminfo.tickerid, "D", high[1], lookahead = barmerge.lookahead_on) locks onto that same completed daily bar without peeking into unfinished future intraday bars.

Inputs, externs and OrderSend()

Trailing MQL4 comments become the human-readable input labels in TradingView's settings dialog.

MQL4 (.mq4)Pine Script v6
input int FastLen = 21; // Fast EMA LengthFastLen = input.int(21, "Fast EMA Length")
extern double BandsDev = 2.0; // Bollinger DeviationBandsDev = input.float(2.0, "Bollinger Deviation")
input bool UseFilter = true; // Enable FilterUseFilter = input.bool(true, "Enable Filter")
OrderSend(Symbol(), OP_BUY, 0.10, Ask, 3, 0, 0, "Long", 101, 0, clrGreen);strategy.entry("Long", strategy.long, qty = 0.10)

What cannot convert automatically (and why)

Flagged inline with TODO(MQL4) and source line numbers instead of silent guesswork.

Compiled .ex4 binaries, iCustom(), ticket loops and tick execution
  • Compiled .ex4 files: An .ex4 file is compiled bytecode, not text. You need the editable .mq4 file (check with our .ex4 and .mq4 file inspector).
  • iCustom(): Calls another indicator on your MT4 disk. Paste that indicator's math into the same Pine script or merge two scripts with our Pine Script indicator merger.
  • Ticket management (OrdersTotal, OrderSelect, OrderModify): MT4 EAs loop over live broker tickets on every tick; Pine strategies declare exits with strategy.exit() and evaluate on bar close by default.
  • Chart objects (ObjectCreate): Rewrite trendlines, boxes and text labels with Pine v6 line.new(), box.new() and label.new().

Have a MetaTrader 5 .mq5 file instead? Use the MQL5 to Pine Script v6 converter. Going the other direction (TradingView to MetaTrader 5)? Use the Pine Script to MQL5 port planner or Pine Fixer for compiler-grade Pine v6 fixes.

Method and privacy

Method: The converter runs in your browser over src/lib/tools/mql4-to-pine: it unfolds MQL4 OnCalculate and start() bar loops into Pine v6 series, maps SetIndexBuffer and SetIndexStyle calls into plot() and plotshape(), translates iMA, iRSI, iATR, iCCI, iStdDev, iBands, iMACD, iStochastic, iHighest, iLowest and iClose..iVolume (using request.security() for higher timeframes), maps OrderSend() into strategy.entry(), and checks the draft with our static Pine v6 checker. Compiled .ex4 binaries, iCustom(), ticket-modification loops and chart objects are flagged TODO rather than guessed. TradingView's compiler is the final word.

Calculations run entirely in your browser — nothing you type is uploaded. Your last numbers stay in this browser so you can pick up where you left off; Forget them clears them. A link with your numbers carries them after the # sign, which browsers do not send to servers, and the page takes them out of the address before any analytics loads. Copy and download actions save your calculation locally. The site may record coarse tool actions under its privacy policy, without inputs, results, file contents or filenames.

Common questions

Can you convert an .ex4 file to Pine Script?

No. An .ex4 file is a compiled MetaTrader 4 binary, not human-readable MQL4 source code. You need the editable .mq4 file to convert its indicator formulas or entry rules into Pine Script v6.

How do MQL4 indicator buffers convert to Pine Script v6?

In MQL4, an indicator declares double arrays, binds them in OnInit() with SetIndexBuffer(0, Buf) and SetIndexStyle(), and fills Buf[i] inside a bar loop. Pine Script v6 evaluates every expression once per bar automatically, so the converter unfolds the loop into a series assignment and emits a matching plot(), plotshape() or hline().

What is the Pine Script v6 equivalent of MQL4 iMA and iBands?

iMA with MODE_SMA, MODE_EMA, MODE_SMMA and MODE_LWMA maps to ta.sma(), ta.ema(), ta.rma() and ta.wma(). iBands maps to ta.sma(src, period) plus or minus deviation times ta.stdev(src, period). When the MQL4 timeframe argument is a higher timeframe such as PERIOD_D1, the converter wraps the call in request.security().

Why does an MQL4 OrderSend() EA trade differently in a Pine strategy?

An MT4 Expert Advisor runs OnTick() on every incoming broker quote and manages individual order tickets via OrdersTotal(), OrderSelect() and OrderModify(). A Pine Script v6 strategy() evaluates after each bar closes by default and manages exits declaratively with strategy.exit(), so compare trades bar by bar on closed-candle signals first.

Is my .mq4 source code uploaded anywhere?

No. Conversion and file reading run strictly inside your browser tab: your MQL4 source code is never sent to a server, saved or placed in a URL.

Fix, build or get finished Pine v6

  • Pine Fixer An AI skill pack for 45 compiler-verified Pine v6 failure classes, with a repaint clinic. $9.99 once.
  • Pine Starter Stack Prompt Vault, Builder Lite and Pine Fixer in one zip. $19.99 once.
  • Pine Pro Library 19 TradingView desks with their full Pine v6 source and every update. $49 once.

Goes deeper

Limits and trading risk

These tools calculate from your inputs, supported historical records or explicitly labelled teaching examples. They do not verify a live account, predict future returns or confirm that a broker or prop-firm rule has been met. Missing costs, floating losses and changed market conditions can materially change outcomes. Trading can lose the capital committed to it; check the stated method and your account specifications.

Read the risk disclosure