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

MQL5 to Pine Script converter

Paste a MetaTrader 5 (.mq5) indicator or CTrade EA and read the Pine Script v6 beside it, line for line.

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

Sample .mq5 indicatorPine Script v6, ready to paste

Pine Script v6numbers: MQL5 source line

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

Indicator draft: MT5 OnInit() handles + CopyBuffer() bound to Pine v6 series

All 11 MQL5 statements converted to Pine v6

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

  • NoteMT5 handle "hFast" + CopyBuffer(..., 0, ..., FastBuf) bound to Pine v6 series "FastBuf".
  • NoteMT5 handle "hSlow" + CopyBuffer(..., 0, ..., SlowBuf) bound to Pine v6 series "SlowBuf".
  • NoteMT5 handle "hRsi" + CopyBuffer(..., 0, ..., rsiVals) bound to Pine v6 series "rsiVals".

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/mql5-to-pine-script-converter" title="MQL5 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">MQL5 to Pine Script converter by <a href="https://proea.app/en/tools/mql5-to-pine-script-converter?utm_source=embed&utm_medium=referral&utm_campaign=mql5-to-pine-script-converter">ProEA</a></p>

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

The math: h = iMA(_Symbol, _Period, 21, 0, MODE_EMA, PRICE_CLOSE) + CopyBuffer(h, 0, ...) = ta.ema(close, 21)

How MQL5 OnInit() handles + CopyBuffer() become Pine Script v6

Unlike MQL4 (where iMA() returns a price directly inside the loop), MetaTrader 5 creates an integer indicator handle once in OnInit() and copies buffer slices via CopyBuffer(handle, bufferNum, startPos, count, arr). Every row below is generated at build time by pineForMql5().

MetaTrader 5 MQL5 (.mq5)Pine Script v6
int hFast = iMA(_Symbol, _Period, 21, 0, MODE_EMA, PRICE_CLOSE);hFast = ta.ema(close, 21)
int hSmma = iMA(_Symbol, _Period, 50, 0, MODE_SMMA, PRICE_MEDIAN);hSmma = ta.rma(hl2, 50)
int hHtf = iMA(_Symbol, PERIOD_H1, 20, 0, MODE_EMA, PRICE_CLOSE);hHtf = request.security(syminfo.tickerid, "60", (ta.ema(close, 20))[1], lookahead = barmerge.lookahead_on)
int hRsi = iRSI(_Symbol, _Period, 14, PRICE_CLOSE);hRsi = ta.rsi(close, 14)
int hAtr = iATR(_Symbol, _Period, 14);hAtr = ta.atr(14)
int hCci = iCCI(_Symbol, _Period, 20, PRICE_TYPICAL);hCci = ta.cci(hlc3, 20)
int hBb = iBands(_Symbol, _Period, 20, 0, 2.0, PRICE_CLOSE);[_hBb_mid, _hBb_upper, _hBb_lower] = ta.bb(close, 20, 2.0)
int hMacd = iMACD(_Symbol, _Period, 12, 26, 9, PRICE_CLOSE);[_hMacd_macd, _hMacd_signal, _hMacd_hist] = ta.macd(close, 12, 26, 9)
int hStoc = iStochastic(_Symbol, _Period, 14, 3, 3, MODE_SMA, STO_LOWHIGH);hStoc = ta.sma(ta.stoch(close, high, low, 14), 3)
int hAdx = iADX(_Symbol, _Period, 14);[_hAdx_diPlus, _hAdx_diMinus, _hAdx_adx] = ta.dmi(14, 14)
double hi = iHigh(_Symbol, _Period, iHighest(_Symbol, _Period, MODE_HIGH, 20, 1));hi = ta.highest(high, 20)[1]
int shift = iHighest(_Symbol, _Period, MODE_HIGH, 20, 0);shift = -ta.highestbars(high, 20)
double pt = SymbolInfoDouble(_Symbol, SYMBOL_POINT);pt = syminfo.mintick
Why ArraySetAsSeries(arr, true) vs rates_total - 1 indexing matters

In MQL5's OnCalculate(), default arrays are indexed oldest-first (0 is the oldest candle and rates_total - 1 is the live candle), whereas calling ArraySetAsSeries(arr, true) flips index 0 to the live candle and 1 to the last closed candle—matching Pine Script's series[0] and series[1]. The converter tracks ArraySetAsSeries() and chronological for (int i = start; i < rates_total; i++) loops so arr[i - 1] and arr[1] both map to series[1].

MQL5 inputs and CTrade Expert Advisor orders

input / sinput declarations and trailing comments become TradingView settings; CTrade market calls become Pine v6 strategy.entry() and strategy.close_all().

MetaTrader 5 MQL5 (.mq5)Pine Script v6
input int FastLen = 21; // Fast EMA LengthFastLen = input.int(21, "Fast EMA Length")
input double AtrMult = 1.5; // ATR MultiplierAtrMult = input.float(1.5, "ATR Multiplier")
input ENUM_APPLIED_PRICE PriceSrc = PRICE_TYPICAL; // Source PricePriceSrc = input.source(hlc3, "Source Price")
trade.Buy(0.10, _Symbol, 0, 0, 0, "Long Cross");strategy.entry("Long Cross", strategy.long)
trade.Sell(0.10, _Symbol, 0, 0, 0, "Short Cross");strategy.entry("Short Cross", strategy.short)
trade.PositionClose(_Symbol);strategy.close_all()

What cannot convert automatically (and why)

Flagged inline with TODO(MQL5) and 1-based source line numbers rather than silent guesswork.

Compiled .ex5 binaries, iCustom(), MqlTradeRequest structs and OnBookEvent()
Method and privacy

Method: Runs in your browser over src/lib/tools/mql5-to-pine: pairs MetaTrader 5 OnInit() indicator handles (iMA, iRSI, iATR, iBands, iMACD, iStochastic, iCCI, iADX, iMomentum, iStdDev, iWPR, iMFI, iOBV, including higher-timeframe PERIOD_* handles via closed-bar request.security()) with CopyBuffer() and ArraySetAsSeries(), maps #property indicator_* and SetIndexBuffer() metadata into plot(), plotshape() and hline(), translates input/sinput declarations and CTrade Buy/Sell/PositionClose calls into Pine v6 settings and strategy.entry(), and checks the draft with our static Pine v6 checker. Compiled .ex5 binaries, iCustom(), raw MqlTradeRequest OrderSend() structs, chart objects and OnBookEvent() are flagged TODO rather than guessed.

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 a compiled .ex5 file to Pine Script?

No. An .ex5 file is a compiled MetaTrader 5 binary, not human-readable MQL5 source code, and we never decompile compiled binaries. Open or request the plain-text .mq5 source file to convert its indicator handles or entry rules into Pine Script v6.

How do MQL5 OnInit() indicator handles and CopyBuffer() convert to Pine Script v6?

Unlike MQL4, MQL5 creates an integer handle once in OnInit()—such as hFast = iMA(_Symbol, _Period, 21, 0, MODE_EMA, PRICE_CLOSE)—and copies slice values inside OnCalculate() or OnTick() via CopyBuffer(hFast, 0, 0, count, buf). The converter traces each handle variable to its CopyBuffer() destination array and emits the matching Pine Script v6 ta.* series or tuple.

How does ArraySetAsSeries(arr, true) change bar indexing between MQL5 and Pine Script?

By default, MQL5 OnCalculate() arrays index bar 0 as the oldest historical bar and rates_total - 1 as the live bar. Calling ArraySetAsSeries(arr, true) flips index 0 to the live bar and index 1 to the last closed bar, matching Pine Script's series[0] and series[1]. The converter tracks both chronological loops (arr[i - 1]) and series-indexed arrays (arr[1]) so both map to [1] in Pine v6.

How do MQL5 CTrade.Buy() and OrderSend(MqlTradeRequest) convert?

Standard Library CTrade calls—trade.Buy(), trade.Sell() and trade.PositionClose()—convert directly to strategy.entry() and strategy.close_all() in a Pine v6 strategy(). Low-level OrderSend(request, result) structs specify broker fill policies and ticket modifications, so they are flagged TODO with their MQL5 line number so you can attach an explicit strategy.exit().

Is my .mq5 source code uploaded anywhere?

No. File reading and MQL5-to-Pine v6 conversion run strictly inside your browser tab; your source code is never transmitted, logged or saved.

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