Built-in and custom indicators

MQL4 indicator functions and parameter order

MQL4 indicator functions return a value for a symbol, timeframe, output mode, and bar shift. NULL means the current symbol, timeframe 0 means the current chart, and shift 0 is the current bar. Read each signature because iADX, iBands, iRSI, iStochastic, and iCustom use different parameter orders.

Open the Coding Agent, then choose MQL4 from the language menu.

IndicatorSnapshot.mq4.mq4
#property strict

void OnStart()
  {
   int shift = 1;
   if(Bars < 50)
     {
      Print("Not enough history.");
      return;
     }

   double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, shift);
   double adx = iADX(NULL, 0, 14, PRICE_CLOSE, MODE_MAIN, shift);
   double upper = iBands(NULL, 0, 20, 2.0, 0,
                         PRICE_CLOSE, MODE_UPPER, shift);
   double stochastic = iStochastic(NULL, 0, 5, 3, 3,
                                    MODE_SMA, 0, MODE_MAIN, shift);

   PrintFormat("RSI=%.2f ADX=%.2f Upper=%.5f Stoch=%.2f",
               rsi, adx, upper, stochastic);
  }
  • NULL and 0 use the current chart
  • Mode selects an output line
  • Shift selects the bar
  • iCustom inputs must match declarations

The shared arguments still need explicit choices

Indicator calls commonly begin with symbol and timeframe, but their remaining parameters differ. Periods, deviations, slowing, methods, applied prices, output modes, and shifts must match the exact reference entry.

When another symbol or timeframe is requested, local history may be missing or updating. Treat an unavailable data state separately from a legitimate numeric value.

FunctionKey choiceCommon output mode
iADXperiod and applied priceMODE_MAIN, MODE_PLUSDI, MODE_MINUSDI
iBandsperiod, deviation, band shiftMODE_UPPER, MODE_MAIN, MODE_LOWER
iRSIperiod and applied priceSingle returned line
iStochasticK, D, slowing, method, price fieldMODE_MAIN or MODE_SIGNAL
iCustomindicator name and declared inputsBuffer mode and shift

iCustom is a dependency contract

The custom indicator name resolves inside MQL4/Indicators. Input values after the name must follow the target indicator’s input declarations in order. The final mode and shift identify the output buffer and bar.

A single-file page cannot prove an iCustom call without the referenced indicator. If portability matters, include the calculation in one source file or explicitly deliver the dependent indicator and version.

  • Record the indicator filename and version
  • Match every input type and order
  • Confirm the requested buffer index
  • Handle missing history and dependency failures

Indicator values are data, not a trading rule

An RSI or band value becomes a signal only after the code defines timing, threshold, confirmation, duplicate handling, and order behavior. Use shift 1 when the rule requires a closed bar and shift 0 only when intrabar changes are intended.

Test values visually against the target MT4 chart and settings before connecting the calculation to order execution.

Review the complete example

The script reads four built-in indicators on the latest closed bar. The calls show that output mode and shift appear in different positions, so signatures should not be inferred from another function.

The example reads and logs indicator values. It does not define a complete signal or place trades. Verify settings and bar timing on the target chart.

IndicatorSnapshot.mq4.mq4
#property strict

void OnStart()
  {
   int shift = 1;
   if(Bars < 50)
     {
      Print("Not enough history.");
      return;
     }

   double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, shift);
   double adx = iADX(NULL, 0, 14, PRICE_CLOSE, MODE_MAIN, shift);
   double upper = iBands(NULL, 0, 20, 2.0, 0,
                         PRICE_CLOSE, MODE_UPPER, shift);
   double stochastic = iStochastic(NULL, 0, 5, 3, 3,
                                    MODE_SMA, 0, MODE_MAIN, shift);

   PrintFormat("RSI=%.2f ADX=%.2f Upper=%.5f Stoch=%.2f",
               rsi, adx, upper, stochastic);
  }
Where Pineify fits

Move from the rule to editable MQL4 source

Pineify can generate or revise one self-contained .mq4 file with MQL4-specific reference context. Its independent static checker returns MetaEditor diagnostics so you can repair source issues before testing in your own MT4 environment.

Open MQL4 Coding Agent

Static diagnostics do not prove runtime behavior, backtest results, broker compatibility, or live-trading safety.

Pineify MQL4 Coding Agent with MQL4 selected and an editable MetaTrader 4 code artifact

A practical workflow

  1. 1

    Open the exact signature

    Confirm parameter order in the MQL4 reference for the selected function.

  2. 2

    Choose data context

    Set symbol, timeframe, applied price, mode, and bar shift deliberately.

  3. 3

    Guard history and dependencies

    Check that the required symbol data and custom indicator are available.

  4. 4

    Compare chart values

    Log the result and compare it with the same MT4 indicator settings.

Frequently asked questions

What does NULL mean in an MQL4 indicator function?

NULL selects the current chart symbol. A timeframe value of 0 selects the current chart timeframe.

What is shift in MQL4 indicator functions?

Shift is the bar index relative to the current bar. Shift 0 is current and shift 1 is the latest closed bar.

How does iCustom work in MQL4?

iCustom loads a custom indicator by name, passes inputs in declaration order, then reads the selected output buffer and shift.

Why does an indicator function return zero?

Zero may be a valid value or an unavailable-data result. Check history state and GetLastError before deciding.

Can I use MQL5 indicator-handle examples in MQL4?

Not directly. Classic MQL4 indicator functions usually return values, while MQL5 commonly uses handles and buffer copying.

Last verified against the linked official references on . Compile and test the final source in the MetaTrader 4 build, broker, symbol, and account environment you plan to use.

Continue with one reviewable MQL4 file

Define the requirement, inspect the generated source, repair diagnostics, and test the behavior in your own MT4 environment.

Open Coding Agent