MQL5 custom indicator diagnosis

MQL5 Indicator Not Showing on Chart

When an MQL5 indicator is not showing on the chart, first confirm that OnInit succeeds and OnCalculate runs. Then verify the chart or separate-window property, indicator buffer and plot counts, SetIndexBuffer mappings, draw type, visible color, and calculated values. The official OnCalculate reference notes that returning zero hides values from the Data Window.

Open the Coding Agent and choose MQL5 from the language menu.

Minimal visible indicator.mq5
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue

double Output[];

int OnInit()
  {
   return SetIndexBuffer(0,Output,INDICATOR_DATA)
          ? INIT_SUCCEEDED : INIT_FAILED;
  }

int OnCalculate(const int rates_total,const int prev_calculated,
                const int begin,const double &price[])
  {
   for(int i=MathMax(prev_calculated-1,begin);i<rates_total;i++)
      Output[i]=price[i];
   return rates_total;
  }
  • Initialize: OnInit succeeds
  • Bind: buffers match plots
  • Calculate: return rates_total
  • Render: valid values and style

Check initialization before appearance

Read the Experts and Journal tabs for OnInit failures. An INVALID_HANDLE dependency, failed buffer binding, or rejected input can prevent the indicator from reaching its calculation path.

Match properties, buffers, and plots

MQL5 indicator properties define whether output belongs in the chart or a separate window and how many buffers and plots exist. SetIndexBuffer indexes start at zero even though property numbering starts at one.

  • Declare indicator_chart_window or indicator_separate_window.
  • Keep indicator_buffers large enough for data and color-index buffers.
  • Keep indicator_plots consistent with configured plot properties.
  • Use a visible draw type, color, line width, and scale.

Prove OnCalculate writes visible values

Log rates_total and prev_calculated over a small interval. Ensure the loop reaches valid indexes, writes finite values rather than EMPTY_VALUE for the visible region, and returns rates_total. If source data comes from another handle, require BarsCalculated and check CopyBuffer counts.

Use a focused diagnostic

This minimal indicator declares one plot and one buffer, binds them, writes finite prices, and returns rates_total. Compare each contract with the non-rendering indicator.

A clean compile or a cleared error code does not prove strategy logic, broker compatibility, backtest quality, or live-trading safety. Reproduce the result in the target MetaTrader 5 terminal and account environment.

Minimal visible indicator.mq5
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue

double Output[];

int OnInit()
  {
   return SetIndexBuffer(0,Output,INDICATOR_DATA)
          ? INIT_SUCCEEDED : INIT_FAILED;
  }

int OnCalculate(const int rates_total,const int prev_calculated,
                const int begin,const double &price[])
  {
   for(int i=MathMax(prev_calculated-1,begin);i<rates_total;i++)
      Output[i]=price[i];
   return rates_total;
  }
Where Pineify fits

Repair editable MQL5 source with compiler feedback

Pineify can generate or revise MQL5 source and use MQL5 compilation diagnostics during the coding workflow. Keep the exact error, source location, program type, and intended behavior in the request so the change remains reviewable.

Open MQL5 Coding Agent

Pineify does not run your broker terminal, Strategy Tester, market data, or live orders. Validate the final program in your own MetaTrader 5 environment.

Review MQL5 AI Coding Agent capabilities
Pineify MQL5 AI Coding Agent with an editable MetaTrader 5 code artifact

A practical verification workflow

  1. 1

    Read initialization logs

    Confirm OnInit returns INIT_SUCCEEDED and every handle or SetIndexBuffer call succeeds.

  2. 2

    Audit indicator declarations

    Match the window, buffer count, plot count, draw type, color, and SetIndexBuffer indexes.

  3. 3

    Trace OnCalculate

    Log rates_total, prev_calculated, loop bounds, source readiness, and the number of output values written.

  4. 4

    Test visible output

    Use a simple known series, return rates_total, attach to a fresh chart, and then restore the original calculation in stages.

Frequently asked questions

Why is my MQL5 indicator not showing on the chart?

Check failed initialization, incorrect window or plot properties, unbound buffers, an OnCalculate signature or return issue, invalid loop bounds, and output containing only EMPTY_VALUE or non-finite values.

Can returning 0 from OnCalculate hide the indicator?

The official OnCalculate reference says returning zero prevents indicator values from being shown in the Data Window. A normal completed calculation usually returns rates_total.

What if the indicator handle cannot be created?

Treat INVALID_HANDLE as initialization failure and inspect GetLastError. Runtime error 4802 means the indicator cannot be created.

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

Continue with reviewable MQL5 source

Provide the exact diagnostic and intended behavior, inspect the generated change, compile it, and verify it in your MT5 test environment.

Open MQL5 Coding Agent