QF Workshop 2026
Current location: Home > Workshops > QF Workshop 2026

QF Workshop #5: Introduction to MetaTrader 5 (MT5) & MQL5

Posted:2026-10-29 14:34:04 Click:186

 

QF Workshop #5: Introduction to MetaTrader 5 (MT5) & MQL5

Duration: ~1 hour  |  Instructor: Dr. Raymond S. T. Lee

This self-contained session introduces the MetaTrader 5 platform and MetaQuotes Language 5 (MQL5) — the essential tools for implementing Quantum Finance Forecast Systems described in the book.

1. What is MetaTrader 5? (10 min)

MetaTrader 5 (MT5) is a multi-asset trading platform developed by MetaQuotes. It is widely used by retail and institutional traders for forex, stocks, futures, and cryptocurrencies. Key features relevant to Quantum Finance:

  • Real-time and historical price data (OHLCV) for 100+ instruments
  • Built-in charting and technical indicators
  • Expert Advisors (EAs) for automated trading
  • Custom indicators, scripts, and services
  • Strategy Tester for backtesting
Note: Download MT5 free from MetaQuotes or your broker (Forex.com, AvaTrade, etc.). Create a demo account for practice.

2. MetaEditor and MQL5 Basics (15 min)

MQL5 is the programming language for MT5. Open MetaEditor from MT5 (Tools → MetaQuotes Language Editor or F4).

  • Expert Advisor (EA): Automated trading program attached to a chart
  • Custom Indicator: Technical indicator that plots on chart
  • Script: One-time execution program
  • Include / Library: Reusable code modules

Basic MQL5 structure:

//+------------------------------------------------------------------+
//|                                                     SimpleEA.mq5 |
//+------------------------------------------------------------------+
#property copyright "Dr. Raymond Lee"
#property version   "1.00"

int OnInit()
{
   Print("EA initialized");
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   Print("EA removed");
}

void OnTick()
{
   // Called on every new tick
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   Print("Current Ask: ", ask);
}

3. Accessing Price Data in MQL5 (15 min)

MQL5 uses a handle-based system for indicators and timeseries.

// Get historical closes
double closes[];
ArraySetAsSeries(closes, true);
int copied = CopyClose(_Symbol, PERIOD_D1, 0, 100, closes);
if(copied > 0)
   Print("Latest close: ", closes[0]);

// Simple Moving Average example
int ma_handle = iMA(_Symbol, PERIOD_H1, 20, 0, MODE_SMA, PRICE_CLOSE);
double ma_buffer[];
ArraySetAsSeries(ma_buffer, true);
if(CopyBuffer(ma_handle, 0, 0, 1, ma_buffer) > 0)
   Print("MA(20): ", ma_buffer[0]);

4. Mini Lab: First MQL5 Script (10 min)

Create a script that prints the last 10 daily closes of the current symbol.

// Save as GetLastCloses.mq5 and run on any chart
void OnStart()
{
   double closes[];
   ArraySetAsSeries(closes, true);
   int n = CopyClose(_Symbol, PERIOD_D1, 0, 10, closes);
   if(n > 0)
   {
      for(int i = 0; i < n; i++)
         Print(i, ": ", closes[i]);
   }
}

Workshop Assignment (6 questions)

  1. Install MT5, open a demo account, and attach any chart (e.g., EURUSD D1). Take a screenshot of the main window and label the Navigator, Market Watch, and Toolbox panels.
  2. Create a new Expert Advisor in MetaEditor. Write an EA that prints the current Bid and Ask prices every tick. Attach it to a chart and show the Experts log.
  3. Modify the script above to also print the High, Low, and Open of the last 5 daily bars. Submit the code.
  4. Explain the difference between an Expert Advisor, a Script, and a Custom Indicator in MT5.
  5. What is the purpose of ArraySetAsSeries() and CopyClose() / CopyBuffer() in MQL5?
  6. List three advantages of using MT5/MQL5 for implementing the Quantum Finance Forecast System compared with pure Python.

Submit screenshots + MQL5 code files by next session.

QF Workshop #5 – Introduction to MT5 & MQL5 | Dr. Raymond S. T. Lee

到价提醒[关闭]