Skip to content

Free tool

Pine Script to MQL5 portability checker

Paste a TradingView Pine script and see, construct by construct, what ports to MQL5 as it is, what has to be rewritten for MetaTrader 5 and what needs your decision first, with a complexity score and the price band. Your code stays in your browser.

Pine v4, v5 or v6. The check runs in your browser: the script is not uploaded or stored. Ctrl + Enter checks it.

On MetaTrader 5 you want

Portability report

Paste a script (or load an example) and press “Check the script”. The report shows here.

What the checker looks for

45 rules over Pine v4, v5 and v6. Each one names the Pine construct, what it does and how the same thing is done in MQL5. “Ports directly” maps one to one; “Needs rewriting” works on MetaTrader but is written differently; “Needs a decision” has no MetaTrader equivalent or changes the results, so it is agreed with you first.

Data requests

6 rules
PineVerdictIn MQL5
Other timeframe or symbol data (request.security)request.security evaluates an expression on another timeframe or symbol and maps it back onto the chart's bars. On the live bar the higher-timeframe value keeps changing until that bar closes.Needs rewritingCopyRates / CopyBuffer on the other timeframe with iBarShift to align bars; the port reads the last closed higher-timeframe bar (shift 1) so live and tester results agree, and checks that the history is loaded.
Data from another symbolA request reads a symbol other than the chart's (a literal ticker or an input.symbol).Needs rewritingThe symbol must exist under the broker's own name (suffixes such as EURUSD.m) and be selected in Market Watch; SymbolSelect and a history check before use.
Intrabar data (request.security_lower_tf)Returns an array of lower-timeframe values inside each chart bar.Needs rewritingCopyRates on the lower timeframe between the bar's open and close times; the lower-timeframe history must exist at the broker for the whole test period.
Data MetaTrader does not haverequest.financial, request.economic, request.quandl, request.dividends / earnings / splits, request.seed or request.currency_rate read TradingView data feeds.Needs a decisionMetaTrader 5 has no such feeds. Options: drop the part, import the data from a file or an API you choose (WebRequest), or use a broker symbol that carries it.
Non-standard chart types (ticker.heikinashi, renko …)The script calculates on Heikin Ashi, Renko, Kagi, Line Break or Point & Figure bars.Needs rewritingHeikin Ashi is computed from the normal bars in code. Renko, Kagi, Line Break and Point & Figure need a custom bar builder (or a custom symbol), and the brick rules must be agreed first.
VolumeThe script uses volume (or a volume indicator such as VWAP, OBV, MFI or VWMA).Needs a decisionOn forex and CFD symbols MetaTrader gives tick volume (number of price changes), not traded volume; real volume exists only on exchange symbols. The port uses tick volume unless you say otherwise.

Repainting

7 rules
PineVerdictIn MQL5
Lookahead on a higher-timeframe requestbarmerge.lookahead_on lets a historical bar see the higher-timeframe bar's final value before it closed: the history looks better than live trading can be, unless the expression is offset by [1].Needs a decisionNo lookahead exists in MQL5. We port the honest version (the closed bar); you decide whether that is the intended behaviour.
Bar state checks (barstate.*)barstate.isrealtime, islast, isconfirmed, isnew, ishistory change what the script does on the live bar.Needs rewritingMQL5 has no bar states: a new-bar check (the open time of bar 0 changed) and an explicit closed-bar shift replace them.
Intrabar persistent variables (varip)varip keeps values between ticks of the same bar; in history they behave differently than live.Needs rewritingStatic or global variables updated in OnTick / OnCalculate; the tester's tick model decides how many updates a bar gets.
Wall-clock time (timenow)timenow is the current time, so the result depends on when the script runs.Needs rewritingTimeCurrent() (server time) or TimeGMT(); in the tester it is the simulated time.
Strategy calculates on every tickcalc_on_every_tick = true lets the strategy enter on the forming bar; the history then shows fills that live trading would not repeat.Needs a decisionAn EA always gets every tick. We decide together whether signals use the forming bar (bar 0) or only closed bars (bar 1).
Pivots (ta.pivothigh / ta.pivotlow)A pivot is known only after the right-hand bars have closed; plotting it with an offset draws it in the past.Needs rewritingA loop over the last left + right bars; the signal is used right-bars late, exactly as Pine confirms it, so live and tester agree.
Plots shifted into the past (offset)A negative offset draws values on earlier bars than the ones they were calculated on, so the signals look earlier than they could have been known.Needs a decisionPlotIndexSetInteger(PLOT_SHIFT) draws the same way, but an EA must act on the bar where the value became known. We confirm which you want.

Strategy orders

9 rules
PineVerdictIn MQL5
Strategy entries (strategy.entry / strategy.order)Pine fills market orders at the next bar's open by default, and strategy.entry in the opposite direction reverses the position.Needs rewritingCTrade market or pending orders with the broker's filling mode, stop and freeze levels, lot normalised to the volume step, a check of every result code, and the reversal done as close then open.
Exits (strategy.exit)profit / loss in ticks, limit / stop prices and trail_points / trail_offset, evaluated by the broker emulator inside each bar.Needs rewritingStop loss and take profit as prices on the position; the trailing stop is code in OnTick (MetaTrader has no server-side trailing for EAs).
Closing and cancelling (strategy.close, close_all, cancel)Close a position or cancel a pending order by its id.Ports directlyPositionClose / OrderDelete on the positions and orders the EA opened (its magic number and a comment per Pine id).
Position size in percent of equity or cashdefault_qty_type = strategy.percent_of_equity or strategy.cash (or qty_percent on exits).Needs rewritingThe lot is computed from money: tick value, tick size and the stop distance, then normalised to the symbol's minimum, step and maximum.
Pyramidingpyramiding > 1 allows several entries in the same direction.Needs rewritingOn a hedging account each entry is its own position; on a netting account they merge into one, so the account type must be fixed in the spec.
One-cancels-all groupsoca_name / strategy.oca.* link orders so that one fill cancels or reduces the others.Needs rewritingMetaTrader has no OCA groups: the EA watches fills (OnTradeTransaction) and deletes the other orders itself.
Risk rules (strategy.risk.*)max_drawdown, max_intraday_loss, max_intraday_filled_orders, max_cons_loss_days, allow_entry_in, max_position_size.Needs rewritingAccount-level guards in code: equity checks against the start-of-day balance, a day counter and a lock that closes positions and stops new entries.
Strategy state (position size, average price, trades, equity)strategy.position_size, position_avg_price, opentrades, closedtrades.*, equity, netprofit, openprofit.Needs rewritingPositionsTotal / PositionGetDouble for open positions, HistorySelect and HistoryDealGet* for closed trades, AccountInfoDouble for equity, filtered by the EA's magic number.
Strategy Tester settings in the scriptcommission, slippage, initial_capital, margin, process_orders_on_close, use_bar_magnifier or fill_orders_on_standard_ohlc set how TradingView simulates fills.Needs a decisionThese live in MetaTrader's Strategy Tester (deposit, leverage, the tick model, the broker's real commission and spread), not in the EA; results will differ from TradingView's.

Collections

4 rules
PineVerdictIn MQL5
User-defined types and methodstype and method declarations (Pine v5/v6 objects).Needs rewritingMQL5 structs or classes with the same fields and member functions; object lifetimes are managed explicitly.
Arraysarray.new, array.from, array<type> or type[] values and their methods (push, shift, get, set …).Needs rewritingMQL5 dynamic arrays with ArrayResize, ArrayInsert, ArrayRemove and explicit indexes; the Pine array functions have no one-to-one names.
Matricesmatrix.new and its methods.Needs rewritingMQL5's own matrix and vector types; most operations exist under other names, the rest are written out.
Mapsmap.new and its methods (key → value collections).Needs rewritingCHashMap from the MQL5 standard library (Generic\HashMap.mqh).

Drawing

4 rules
PineVerdictIn MQL5
Plots (plot, plotshape, plotchar, plotarrow, hline, fill, plotcandle)Lines, shapes, arrows, levels, fills and candles drawn from series values.Ports directlyIndicator buffers with DRAW_LINE, DRAW_ARROW, DRAW_FILLING, DRAW_CANDLES or DRAW_COLOR_* styles and indicator levels. In an EA they become a companion indicator or are left out.
Background and bar colours (bgcolor, barcolor)Colours the chart background or the bars by condition.Needs rewritingBars: DRAW_COLOR_CANDLES. The background: rectangle objects per bar range (MetaTrader has no per-bar background).
Drawing objects (line.new, label.new, box.new, polyline.new, linefill.new)Objects created and moved by code, often for zones, structure or labels; Pine deletes the oldest past max_lines_count / max_boxes_count.Needs rewritingChart objects (ObjectCreate with OBJ_TREND, OBJ_TEXT, OBJ_RECTANGLE …), each with a unique name, updated and deleted by the code, with the same count limits.
Tables (table.new)An on-chart table or dashboard fixed to a screen corner.Needs rewritingA panel of label and rectangle objects (OBJ_LABEL, OBJ_RECTANGLE_LABEL) or a CAppDialog, laid out in pixels.

Alerts

3 rules
PineVerdictIn MQL5
alert()Sends an alert message when the code runs it, with a frequency (once per bar, per bar close, all).Ports directlyAlert(), SendNotification() (push to the MT5 phone app) or SendMail(), with a once-per-bar guard for the frequency.
Alert conditions (alertcondition)Declares conditions the user picks in TradingView's alert dialog; nothing fires until an alert is created there.Needs rewritingMetaTrader has no alert dialog for indicators: each condition becomes an input switch and an Alert / push / e-mail call in code.
Alert placeholders and webhooksMessages with {{ticker}}, {{close}} … placeholders, or JSON meant for a webhook (a bot or a broker bridge).Needs a decisionPlaceholders become StringFormat. A webhook needs WebRequest, with the URL added in Tools → Options → Expert Advisors; WebRequest does not run in indicators, so an EA sends it.

Inputs

3 rules
PineVerdictIn MQL5
Inputs (input.int, float, bool, string, color)Settings the user changes in the script's dialog, with groups and tooltips.Ports directlyinput variables with enums for option lists and input group for the sections.
Source inputs (input.source)Lets the user pick a price (close, hl2 …) or another indicator's plot as the source.Needs rewritingPrices map to ENUM_APPLIED_PRICE; another indicator's output needs iCustom or the indicator built into the port.
Symbol and timeframe inputsinput.symbol / input.timeframe let the user choose the symbol or timeframe of a request.Needs rewritingA string input for the broker's symbol name and ENUM_TIMEFRAMES; TradingView timeframes MetaTrader lacks (for example 3h, 2D, 45 seconds) are not available.

Sessions and time

2 rules
PineVerdictIn MQL5
Sessions and time zonesSession strings such as "0930-1600", time(timeframe, session), session.* or a time zone such as "America/New_York".Needs rewritingMetaTrader works in the broker's server time. Sessions are compared on that clock, with the time zone offset and daylight saving handled in code; the broker's offset is part of the spec.
Hour, minute and weekdayhour, minute, dayofweek and similar on the bar's time.Ports directlyTimeToStruct on the bar time (server time).

Calculations

5 rules
PineVerdictIn MQL5
History of calculated values ([n] on your own variables)Pine keeps every variable's past values; x[1] works on any series.Needs rewritingA calculated value with history becomes an indicator buffer or a series array the code fills bar by bar.
Indicators MetaTrader 5 has built inta.sma, ema, rma, wma, rsi, bb, cci, sar, mfi, obv, wpr, stdev, highest, lowest, dmi, tr …Ports directlyiMA (SMA, EMA, SMMA = rma, LWMA = wma), iRSI, iBands, iCCI, iSAR, iMFI, iOBV, iWPR, iStdDev, iHighest / iLowest, iADXWilder (Pine's dmi uses Wilder smoothing).
Indicators MetaTrader calculates differentlyta.atr smooths the true range with RMA, MetaTrader's iATR with a simple average; ta.macd's signal line is an EMA, iMACD's a simple average; ta.mom is a difference, iMomentum a ratio; ta.stoch is the raw %K, and iStochastic's slowing smooths it differently.Needs rewritingComputed in code with Pine's formula, so the values match TradingView bar for bar.
Indicators with no MetaTrader built-inta.supertrend, vwap, vwma, hma, alma, linreg, kc, cmo, tsi, cog, swma, percentrank, correlation, valuewhen, barssince …Needs rewritingWritten in MQL5 from their formulas (short loops or buffers); each is checked against TradingView's values on the same bars.
Crosses and changes (ta.crossover, crossunder, change, rising, falling)Comparisons of the current and previous values.Ports directlyThe same comparisons on bar 1 and bar 2 (closed bars) or bar 0 and bar 1 (forming bar).

Script

2 rules
PineVerdictIn MQL5
Pine libraryThe script is a library(): exported functions and types other scripts import.Needs rewritingBecomes an .mqh include file with the same functions; every script that imports it includes the file.
Imported libraryimport pulls functions from another author's published library; its source is not in this script.Needs a decisionWe need the library's source too (and its licence must allow the port); its functions are rewritten as an .mqh include.

What it does not do

  • It does not convert code. Pine and MQL5 run differently (Pine recalculates a whole series per bar; MQL5 reacts to ticks and buffers), so a port is written for MetaTrader, then checked against TradingView’s values on the same bars.
  • It reads the script’s constructs, not your strategy’s logic: two scripts with the same functions can be very different jobs. The written spec fixes the price before any code is written.
  • It does not upload your script. The text box, the file you open and the report stay in this browser tab; “Send for a quote” only fills the brief, which you send yourself.

Before you send a script

  • Send a script you wrote, or one whose licence allows a port. Open scripts on TradingView often carry the Mozilla Public License 2.0; the port then keeps the author’s credit and the licence. Invite-only and protected scripts are not ported.
  • Results in MetaTrader’s Strategy Tester differ from TradingView’s: the tick model, the broker’s spread and commission, and the fill rules are MetaTrader’s own.
  • Want an open-source script on MT5 for everyone? Suggest it on the port request board.