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 Length | FastLen = input.int(21, "Fast EMA Length") |
extern double BandsDev = 2.0; // Bollinger Deviation | BandsDev = input.float(2.0, "Bollinger Deviation") |
input bool UseFilter = true; // Enable Filter | UseFilter = 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
.ex4file is compiled bytecode, not text. You need the editable.mq4file (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()andlabel.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.