MQL5 → Pine Script cheat sheet

Short answer

The MQL5 functions and their Pine Script v6 equivalents on one page: 30 entries from iMA and iRSI to OnCalculate, CopyBuffer and CTrade, each linked to a full explanation with code. Each row names the closest Pine Script v6 equivalent of an MQL5 function or construct.

Each row names the closest Pine Script v6 equivalent of an MQL5 function or construct. The linked page shows the code on both sides and the differences that change values. For the other direction see the Pine Script → MQL5 cheat sheet.

Indicator functions

MQL5Pine Script v6 equivalent
CopyBuffer(handle, buffer_num, start_pos, count, buffer[])No call needed: the ta.* result is the series; start_pos n is [n]
iADX(symbol, period, adx_period) / iADXWilder(symbol, period, adx_period)iADXWilder ≈ ta.dmi(n, n); iADX is an EMA-based variant with no Pine builtin
iATR(symbol, period, ma_period)ta.sma(ta.tr(false), n); ta.atr is Wilder's RMA and does not match
iBands(symbol, period, bands_period, bands_shift, deviation, applied_price)[basis, upper, lower] = ta.bb(source, period, deviation); shift is plot offset
iCCI(symbol, period, ma_period, applied_price)ta.cci(source, length); PRICE_TYPICAL is hlc3; same 0.015 constant
iCustom(symbol, period, name, inputs...)No equivalent: inline the indicator, import a library, or input.source
iIchimoku(symbol, period, tenkan_sen, kijun_sen, senkou_span_b)Hand-written: (ta.highest + ta.lowest) / 2 per line; plot offset = Kijun period
iMA(symbol, period, ma_period, ma_shift, ma_method, applied_price)ta.sma / ta.ema / ta.rma / ta.wma by ma_method; ma_shift is plot offset
iMACD(symbol, period, fast_ema, slow_ema, signal_period, applied_price)macd = ta.ema(src,f) - ta.ema(src,s); signal = ta.sma(macd, n), not ta.macd
iMFI(symbol, period, ma_period, applied_volume)ta.mfi(hlc3, length); same formula, volume comes from the chart feed
iMomentum(symbol, period, mom_period, applied_price)src / src[n] * 100 (a ratio around 100); ta.mom is a difference around 0
iOBV(symbol, period, applied_volume)ta.obv; same steps, but MT5 starts from the first bar's volume
iRSI(symbol, period, ma_period, applied_price)ta.rsi(source, length); same Wilder smoothing and SMA seed
iSAR(symbol, period, step, maximum)ta.sar(step, step, maximum); the first trend can differ until the first reversals
iStochastic(symbol, period, Kperiod, Dperiod, slowing, ma_method, price_field)%K = sum(close-LL, slowing)/sum(HH-LL, slowing)*100; %D = ta.sma(%K, Dperiod)

Program structure and trading

MQL5Pine Script v6 equivalent
Alert(...), SendNotification(msg), PlaySound(file), SendMail(subject, body)alert(msg, alert.freq_once_per_bar_close) or alertcondition(); channel set in the dialog
ArraySetAsSeries(array[], true) then array[shift]Nothing to set: every Pine series is newest-first; series[shift] with shift >= 0
Buf[i] = EMPTY_VALUE; PlotIndexSetDouble(n, PLOT_EMPTY_VALUE, v); PLOT_DRAW_BEGINna; plot(cond ? value : na); warm-up is na automatically; test with na(x)
CopyRates(symbol, tf, start, count, MqlRates &rates[]); rates[i].closeBuilt-ins: rates[i].close → close[i]; tick_volume → volume; time → time/1000
iClose(symbol, timeframe, shift), iHigh, iLow, iOpen, iVolume, iTimeclose[shift] on the chart TF; request.security(..., close[1], lookahead_on) for another
input int X = 14; // Title sinput, enum inputs, input group "Name"input.int(14, "Title"); enum → input.enum or input.string(options=); group=
int OnCalculate(rates_total, prev_calculated, time[], open[], ...)No handler: the script body runs once per bar; drop the loop, keep the body
int OnInit() { SetIndexBuffer(...); handle = iMA(...); IndicatorSetString(...); }indicator()/strategy() declaration + input.*; ta.* calls replace handles
ObjectCreate(chart, name, OBJ_TREND / OBJ_RECTANGLE / OBJ_TEXT / OBJ_HLINE, sub, t1, p1, ...)line.new / box.new / label.new handles (var + set_*); hline() for constant levels
PositionSelect(symbol); PositionGetDouble(POSITION_PRICE_OPEN / VOLUME / PROFIT / SL)strategy.position_size, position_avg_price, openprofit; SL/TP kept in your own var
SetIndexBuffer(index, array[], INDICATOR_DATA) + #property indicator_typeN/colorNplot(series, title, color, linewidth, style); colour-index buffer → colour expression
SymbolInfoDouble(sym, SYMBOL_POINT / TRADE_TICK_SIZE / TRADE_TICK_VALUE / VOLUME_MIN)syminfo.mintick; tick value = syminfo.pointvalue * mintick; no volume step
TimeCurrent(), TimeToStruct(t, MqlDateTime &dt), dt.hour, dt.day_of_week, iTime()time / timenow (ms); dt.hour → hour(time, tz); day_of_week → dayofweek(time, tz) - 1
trade.Buy(lots, sym, price, sl, tp) / OrderSend(MqlTradeRequest, MqlTradeResult)strategy.entry(id, dir, qty) + strategy.exit(stop=sl, limit=tp); close → strategy.close
void OnTick() with an iTime(...,0) new-bar gatestrategy() body runs once per bar close; shift 1 becomes [0]; isconfirmed for ticks

Convert the whole script

Paste a Pine Script indicator or strategy and get MQL5 with this and every other call mapped, checked against the original on the same bars, and every construct that could not be carried over reported.

Open the converter