Back to course
Lesson 55MQL5 indicator labAdvanced165 min

MQL5 indicator handles and CopyBuffer for closed-bar signals

Read indicator values correctly in MQL5 using handles, CopyBuffer, bar shifts, and closed-bar signal rules.

Lesson outcomes

  • Create MQL5 indicator handles for common MT5 indicators.
  • Use CopyBuffer safely with enough bars and error checks.
  • Avoid current-candle signals unless the strategy explicitly accepts intrabar change.

Workshop lab

Complete the demo, notebook, platform, or code task before treating the lesson as finished.

Evidence pack

Keep screenshots, exports, logs, calculations, or code versions in a dated learning folder.

Pass standard

You should be able to explain the failure modes, show your work, and name the stop rule.

Free education, not signals. This lesson is part of EarnSouthAfrica's free forex course. It does not tell you what to buy or sell, it does not promise income, and it should be practised on a demo account before any real-money decision.

Many beginner EAs fail because the coder looks at an indicator on the chart and assumes the EA sees the same thing. MQL5 uses handles and buffers. The EA must request values, check that enough data was copied, decide which bar shift is valid, and log the result.

This lesson is a bridge from manual indicator reading to automation that can be debugged.

What you should be able to do after this lesson

  • Create MQL5 indicator handles for common MT5 indicators.
  • Use CopyBuffer safely with enough bars and error checks.
  • Avoid current-candle signals unless the strategy explicitly accepts intrabar change.

Closed-bar logic

Buffer shift 0 usually refers to the currently forming bar. That value can change. A closed-bar strategy commonly reads shift 1 or older bars. The rule must be written before testing: does the system act intrabar, at bar close, or at the next bar open?

Safe CopyBuffer skeleton

int maHandle = iMA(_Symbol, PERIOD_H1, 50, 0, MODE_EMA, PRICE_CLOSE);
double maBuffer[3];
ArraySetAsSeries(maBuffer, true);
int copied = CopyBuffer(maHandle, 0, 0, 3, maBuffer);
if(copied < 3)
{
   Print("Not enough MA data. copied=", copied, " error=", GetLastError());
   return;
}
double closedBarMA = maBuffer[1];

The snippet is for demo learning. A production-quality EA also needs handle validation, release logic, symbol/timeframe checks, and structured logs.

Signal audit

Log the indicator value, bar time, signal condition, and rejection reason. Then compare the log to the chart screenshot. If the screenshot and log disagree, the learner must solve that before trusting the EA.

Academy-grade study plan

Indicator automation should not scrape chart visuals. The professional approach is to understand indicator handles, buffers, bar indexing, new-bar timing, and the difference between closed-bar evidence and still-forming candle noise.

Course elementWhat you must produce
Primary artifactIndicator-to-EA bridge specification
Lesson focusMQL5 indicator handles and CopyBuffer for closed-bar signals
Working environmentDemo account, notebook, exported platform data, or local code sandbox. Never live funds for first practice.
Completion standardYou can explain the concept, reproduce the exercise, identify failure modes, and show evidence without relying on a seller's claims.

Instructor workflow

Use this workflow as if an instructor were marking the lesson. The important question is not whether the topic sounds familiar. The question is whether your notes, screenshots, calculations, logs, or code prove that you can apply mql5 indicator handles and copybuffer for closed-bar signals under controlled conditions.

  • Choose the indicator for a specific measurement job, such as trend, momentum, volatility, bands, or volume.
  • Create indicator handles deliberately and copy only the buffers and bars required for the decision.
  • Avoid using current-bar values as final evidence unless the strategy is explicitly designed for intrabar behaviour.
  • Log buffer values, signal state, and rejection reasons so the EA can be debugged without staring at the chart.

Worked case study: Indicator signal repaints in the learner's head

A learner watches RSI cross a level during a live candle and assumes the signal is confirmed. By candle close, the value changes and the signal disappears. The paid-course response is to decide whether the strategy uses closed bars or intrabar data, then code CopyBuffer calls and logs to match that decision.

After reading the scenario, write the decision you would make before checking the suggested workflow above. Then compare your decision with the operating model. The gap between those two answers is the part of the lesson that deserves another demo repetition.

Professional template

Complete this template in your own notebook. A paid course would normally hide this kind of operating document behind worksheets; here it is part of the free lesson.

FieldStandard
Indicator handleMQL5 function, symbol, timeframe, parameters, and release/initialization plan.
Buffer readBuffer number, shift, number of bars, closed-bar rule, and error handling.
Signal logicCondition, filter, confirmation, rejection reason, and log output.
Test evidenceVisual chart screenshot, printed buffer values, Strategy Tester run, and forward-demo check.

Failure-mode lab

Paid courses often sell confidence. A serious course teaches you how the idea breaks. Before continuing, test the failure modes below on demo, paper, or code review. If you cannot describe the failure, you are not ready to trust the concept.

  • Reading buffer shift 0 as if it were a closed candle.
  • Not checking whether CopyBuffer returned enough values.
  • Mixing indicator timeframes without aligning bars and timestamps.
  • Using visual indicator crossings that the EA cannot reproduce from data.

Evidence pack and pass standard

Do not mark this lesson complete because you read it. Mark it complete only when you can show the evidence below. Keep the files in a dated folder so your learning history survives platform updates, memory gaps, and sales pressure.

  • A one-page note explaining mql5 indicator handles and copybuffer for closed-bar signals without sales language or copied definitions.
  • A screenshot, export, calculation, log, or code file that proves the practical work was completed on demo.
  • A written stop rule that says when this topic must not be used with real money.
  • A small MQL5 snippet that logs indicator buffer values for at least three closed bars.
  • A screenshot matching the chart indicator with the logged values used by the EA.

Assessment rubric

LevelWhat it looks like
Not readyYou can repeat the vocabulary but cannot complete the demo task, calculate the risk, explain the failure mode, or show evidence.
Course passYou can complete the practical task on demo, explain the decision rules, show evidence, and name the conditions where the idea must not be used.
Strong passYou can teach the concept to someone else, find edge cases, document a rejected example, and improve the template without weakening risk controls.

Advanced homework

  • Compare MA, RSI, ATR, and Bollinger buffer reads and document which buffer each signal uses.
  • Build a closed-bar-only signal and prove it does not change after the bar closes.
  • Add logs that explain why an indicator signal was rejected.

Practical drill

Do this lesson as a controlled exercise, not as a reason to trade live. Open a demo account or notebook, write the lesson title, and record what you changed, clicked, calculated, or checked. If the lesson includes code, compile it only in a demo environment and keep the original version unchanged so you can compare edits safely.

  • Write a one-paragraph explanation of mql5 indicator handles and copybuffer for closed-bar signals in your own words.
  • Take one screenshot or note that proves you completed the platform, maths, research, or code task.
  • Record one risk rule that would stop you from using this idea with real money.
  • If anything feels unclear, repeat the lesson before moving to the next module.

How scammers misuse this topic

Scammers often take real concepts and wrap them in urgency. They may use platform jargon, bot screenshots, copied profit charts, or official-sounding language to make a paid offer feel safe. A real concept is not the same as a safe offer. Before paying anyone, ask whether you can verify the provider, reproduce the calculation, test the claim on demo, understand the risk, and walk away without pressure.

Checkpoint before continuing

  • You know why shift 0 can be dangerous for closed-bar systems.
  • You check CopyBuffer return values before using data.
  • Your EA logs indicator values used for decisions.

Official references

These lessons are written as free education. When platform features or rules matter, verify against the official source before using real money.

Risk note: leveraged forex and contracts for difference can lose money quickly. EarnSouthAfrica is an educational publisher, not a broker, adviser, signal provider, or money manager.

Keep exploring

Read the latest guides, take the side-hustle quiz, or contact the editorial desk if you spot a correction.