{"id":21765,"date":"2026-09-08T10:36:47","date_gmt":"2026-09-08T07:36:47","guid":{"rendered":"https:\/\/roboforex.com\/blog\/?p=21765"},"modified":"2026-09-08T10:40:11","modified_gmt":"2026-09-08T07:40:11","slug":"first-mql5-expert-advisor","status":"publish","type":"post","link":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/","title":{"rendered":"Your First MQL5 Expert Advisor: A Ready-Made Robot You Can Copy and Launch Today"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><p class=\"wp-block-paragraph\">Plenty of traders never automate a strategy because building a trading robot looks like it needs a programming background. The entry barrier is lower than that. Your first MQL5 <a href=\"https:\/\/roboforex.com\/beginners\/info\/expert-advisors\/\" data-internallinksmanager029f6b8e52c=\"21\" title=\"expert advisors\">expert advisor<\/a> is about a hundred lines of code, and this article hands you all of them, together with the steps that turn them into a robot running on a <a href=\"https:\/\/roboforex.com\/forex-trading\/platforms\/metatrader5-mt5\/\" data-internallinksmanager029f6b8e52c=\"8\" title=\"metatrader 5\">MetaTrader 5<\/a> chart.<\/p>\n\n\n\n<div class=\"ea-wrap\">\n<div class=\"ea\">\n\n  <p>The worked example uses a classic trend strategy: a crossover of two exponential moving averages, EMA 9 and EMA 21. The logic is simple enough to stay out of the way, which leaves room to understand the structure every expert advisor shares, from the file that MQL Wizard generates to the compiled robot placing its first test trade.<\/p>\n\n  <div class=\"ea-kratko\">\n    <div class=\"ea-kratko-label\">In Brief<\/div>\n    <ul>\n      <li>The robot trades one rule: EMA 9 crossing EMA 21 upwards opens a buy, crossing downwards opens a sell.<\/li>\n      <li>Everything happens inside MetaEditor 5, which ships with MetaTrader 5, so there is no extra software to install.<\/li>\n      <li>The example uses a fixed 0.10 lot with a stop-loss and a take-profit attached to every position, and it evaluates <a href=\"https:\/\/roboforex.com\/blog\/education\/signals-on-forex-where-to-search-how-to-find-filter-and-create\/\" data-internallinksmanager029f6b8e52c=\"101\" title=\"Signals\">signals<\/a> once per closed candle.<\/li>\n      <li>A ready template gives you code you can read and verify. An AI chat is the better tool once you want to extend that code.<\/li>\n      <li>Run it in the Strategy Tester first, then on a demo account, and check the Experts log before any live account is involved.<\/li>\n    <\/ul>\n  <\/div>\n\n  <h2><span class=\"ez-toc-section\" id=\"The_Working_Environment_How_to_Open_MetaEditor_5\"><\/span>The Working Environment: How to Open MetaEditor 5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>Building a trading robot takes no third-party software. MetaTrader 5 already includes MetaEditor 5, the development environment for writing and editing MQL5 programs.<\/p>\n\n  <p>MetaEditor combines the code editor, the compiler, the debugger, the MQL5 reference documentation and the built-in MQL Wizard, which generates ready-made templates for expert advisors, <a href=\"https:\/\/roboforex.com\/blog\/education\/top-10-forex-indicators-that-every-trader-needs\/\" data-internallinksmanager029f6b8e52c=\"99\" title=\"Indicators\">indicators<\/a> and scripts.<\/p>\n\n  <p>Two ways to open it from the trading terminal:<\/p>\n\n  <ul>\n    <li>Press <strong>F4<\/strong>.<\/li>\n    <li>Select <strong>Tools &rarr; MetaQuotes Language Editor<\/strong> from the top menu.<\/li>\n  <\/ul>\n\n  <h2><span class=\"ez-toc-section\" id=\"Creating_the_Robot_File_with_the_MQL_Wizard\"><\/span>Creating the Robot File with the MQL Wizard<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>With MetaEditor open, the MQL Wizard builds the skeleton of the program for you. Start with <strong>File &rarr; New<\/strong>. The wizard offers a choice of program types, and the one for this example is <strong>Expert Advisor (template)<\/strong>.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_1.png\" alt=\"MQL Wizard in MetaEditor with Expert Advisor template selected\"><\/a><figcaption class=\"wp-element-caption\">Step one of the MQL Wizard: choosing the program type. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>Next comes the program description. The <strong>Name<\/strong> field takes the path and the file name, for example <code>Experts\\MyFirstRobot<\/code>. <strong>Author<\/strong> and <strong>Link<\/strong> are optional and can stay empty.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_2.png\" alt=\"MQL Wizard general properties with the expert advisor name filled in\"><\/a><figcaption class=\"wp-element-caption\">Step two: naming the expert advisor. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>The wizard then offers extra event handlers, including <strong>OnTimer<\/strong> and <strong>OnTrade<\/strong>. This robot uses neither, so the defaults stay as they are.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_3.png\" alt=\"MQL Wizard event handler selection with OnTimer and OnTrade unchecked\"><\/a><figcaption class=\"wp-element-caption\">Step three: additional event handlers, left at their defaults. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>The last screen covers the <strong>OnTester<\/strong> testing events. They are also unused here, so the parameters stay untouched and the wizard finishes.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_4.png\" alt=\"MQL Wizard tester event handler screen\"><\/a><figcaption class=\"wp-element-caption\">Step four: tester events, also left at their defaults. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>MetaEditor now holds a new <code>.mq5<\/code> file containing the basic structure of an expert advisor. That skeleton is the starting point for the trading logic.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_5.png\" alt=\"Generated MQL5 expert advisor template open in the MetaEditor code window\"><\/a><figcaption class=\"wp-element-caption\">The generated template, with empty OnInit, OnDeinit and OnTick functions. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <h2><span class=\"ez-toc-section\" id=\"The_Ready-Made_MQL5_Robot_Code\"><\/span>The Ready-Made MQL5 Robot Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>Below is the complete expert advisor built on the EMA 9 and EMA 21 crossover. Select everything in the generated template, delete it, and paste this in its place, so the <code>.mq5<\/code> file holds only the robot code. After that it is ready to compile.<\/p>\n\n  <div class=\"ea-code-wrap\">\n    <div class=\"ea-code-label\">MyFirstRobot.mq5<\/div>\n    <pre class=\"ea-code\"><code>\/\/+------------------------------------------------------------------+\n\/\/|                                                 MyFirstRobot.mq5 |\n\/\/|                          EMA 9 \/ EMA 21 crossover Expert Advisor |\n\/\/+------------------------------------------------------------------+\n#property copyright \"MyFirstRobot\"\n#property version   \"1.00\"\n#property description \"Simple EMA 9\/21 crossover Expert Advisor\"\n\n#include &lt;Trade\/Trade.mqh&gt;\nCTrade trade;\n\n\/\/--- Trading parameters\ninput double InpLotSize    = 0.10;    \/\/ Lot size\ninput int    InpFastEMA    = 9;       \/\/ Fast EMA period\ninput int    InpSlowEMA    = 21;      \/\/ Slow EMA period\ninput int    InpStopLoss   = 200;     \/\/ <a href=\"https:\/\/roboforex.com\/blog\/education\/what-is-stop-loss-and-take-profit\/\" data-internallinksmanager029f6b8e52c=\"228\" title=\"Stop Loss\">Stop Loss<\/a> in points\ninput int    InpTakeProfit = 400;     \/\/ <a href=\"https:\/\/roboforex.com\/blog\/education\/what-is-stop-loss-and-take-profit\/\" data-internallinksmanager029f6b8e52c=\"56\" title=\"Take Profit\">Take Profit<\/a> in points\ninput ulong  InpMagic      = 123456;  \/\/ Magic number\n\n\/\/--- Indicator handles\nint fastEMAHandle;\nint slowEMAHandle;\n\n\/\/--- Opening time of the last processed bar\ndatetime lastBarTime = 0;\n\n\/\/+------------------------------------------------------------------+\n\/\/| Expert initialization function                                   |\n\/\/+------------------------------------------------------------------+\nint OnInit()\n{\n   \/\/--- Create the Fast EMA indicator handle\n   fastEMAHandle = iMA(_Symbol, _Period, InpFastEMA, 0, MODE_EMA, PRICE_CLOSE);\n\n   \/\/--- Create the Slow EMA indicator handle\n   slowEMAHandle = iMA(_Symbol, _Period, InpSlowEMA, 0, MODE_EMA, PRICE_CLOSE);\n\n   \/\/--- Stop the robot if either handle failed\n   if(fastEMAHandle == INVALID_HANDLE || slowEMAHandle == INVALID_HANDLE)\n   {\n      Print(\"Failed to create EMA indicators\");\n      return(INIT_FAILED);\n   }\n\n   \/\/--- Tag every <a href=\"https:\/\/roboforex.com\/blog\/education\/main-order-types-in-trading\/\" data-internallinksmanager029f6b8e52c=\"311\" title=\"Order\">order<\/a>, so the robot only ever manages its own positions\n   trade.SetExpertMagicNumber(InpMagic);\n\n   Print(\"MyFirstRobot started successfully\");\n   return(INIT_SUCCEEDED);\n}\n\n\/\/+------------------------------------------------------------------+\n\/\/| Expert tick function                                             |\n\/\/+------------------------------------------------------------------+\nvoid OnTick()\n{\n   \/\/--- Opening time of the current bar\n   datetime currentBarTime = iTime(_Symbol, _Period, 0);\n\n   \/\/--- Work once per bar, on the first tick after a new bar opens\n   if(currentBarTime == lastBarTime)\n      return;\n   lastBarTime = currentBarTime;\n\n   \/\/--- Dynamic arrays: the timeseries flag needs them\n   double fastEMA[];\n   double slowEMA[];\n\n   \/\/--- Index 0 is the forming bar, 1 the last closed bar, 2 the one before it\n   ArraySetAsSeries(fastEMA, true);\n   ArraySetAsSeries(slowEMA, true);\n\n   \/\/--- Copy the last three EMA values of each average\n   if(CopyBuffer(fastEMAHandle, 0, 0, 3, fastEMA) &lt; 3)\n      return;\n   if(CopyBuffer(slowEMAHandle, 0, 0, 3, slowEMA) &lt; 3)\n      return;\n\n   \/\/--- Both checks read closed bars only, never the forming bar\n   bool buySignal  = fastEMA[2] &lt;= slowEMA[2] &amp;&amp; fastEMA[1] &gt; slowEMA[1];\n   bool sellSignal = fastEMA[2] &gt;= slowEMA[2] &amp;&amp; fastEMA[1] &lt; slowEMA[1];\n\n   \/\/+--------------------------------------------------------------+\n   \/\/| Buy signal                                                    |\n   \/\/+--------------------------------------------------------------+\n   if(buySignal)\n   {\n      \/\/--- Look only at a position this robot opened itself\n      if(PositionSelect(_Symbol) &amp;&amp;\n         PositionGetInteger(POSITION_MAGIC) == (long)InpMagic)\n      {\n         long positionType = PositionGetInteger(POSITION_TYPE);\n\n         \/\/--- A buy is already running, nothing to do\n         if(positionType == POSITION_TYPE_BUY)\n            return;\n\n         \/\/--- Close the opposite position before reversing\n         if(positionType == POSITION_TYPE_SELL)\n            trade.PositionClose(_Symbol);\n      }\n\n      double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);\n      double sl  = NormalizeDouble(ask - InpStopLoss   * _Point, _Digits);\n      double tp  = NormalizeDouble(ask + InpTakeProfit * _Point, _Digits);\n\n      trade.Buy(InpLotSize, _Symbol, 0, sl, tp, \"EMA 9\/21 Buy\");\n   }\n\n   \/\/+--------------------------------------------------------------+\n   \/\/| Sell signal                                                   |\n   \/\/+--------------------------------------------------------------+\n   if(sellSignal)\n   {\n      if(PositionSelect(_Symbol) &amp;&amp;\n         PositionGetInteger(POSITION_MAGIC) == (long)InpMagic)\n      {\n         long positionType = PositionGetInteger(POSITION_TYPE);\n\n         if(positionType == POSITION_TYPE_SELL)\n            return;\n\n         if(positionType == POSITION_TYPE_BUY)\n            trade.PositionClose(_Symbol);\n      }\n\n      double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);\n      double sl  = NormalizeDouble(bid + InpStopLoss   * _Point, _Digits);\n      double tp  = NormalizeDouble(bid - InpTakeProfit * _Point, _Digits);\n\n      trade.Sell(InpLotSize, _Symbol, 0, sl, tp, \"EMA 9\/21 Sell\");\n   }\n}\n\n\/\/+------------------------------------------------------------------+\n\/\/| Expert deinitialization function                                 |\n\/\/+------------------------------------------------------------------+\nvoid OnDeinit(const int reason)\n{\n   \/\/--- Release the indicator handles\n   if(fastEMAHandle != INVALID_HANDLE)\n      IndicatorRelease(fastEMAHandle);\n   if(slowEMAHandle != INVALID_HANDLE)\n      IndicatorRelease(slowEMAHandle);\n}\n\/\/+------------------------------------------------------------------+<\/code><\/pre>\n  <\/div>\n\n  <div class=\"ea-promo\">\n    <div>\n      <div class=\"ea-promo-title\">Test This Robot on a Free Demo Account<\/div>\n      <div class=\"ea-promo-sub\">Full MetaTrader 5 access and real market conditions, with none of your own funds at stake.<\/div>\n    <\/div>\n    <div class=\"ea-promo-actions\">\n      <a class=\"ea-promo-btn\" href=\"https:\/\/my.roboforex.com\/en\/register\/\" target=\"_blank\" rel=\"nofollow\">Open a Demo Account<\/a>\n    <\/div>\n  <\/div>\n\n  <h2><span class=\"ez-toc-section\" id=\"Code_Anatomy_What_Each_Block_Does\"><\/span>Code Anatomy: What Each Block Does<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>The robot splits into five functional parts, each responsible for one stage of its work, from reading its settings to sending an order. Here is the map, followed by the detail on the parts worth understanding before you run it.<\/p>\n\n  <div class=\"ea-table-wrap\">\n    <table class=\"rf\">\n      <thead>\n        <tr><th>Block<\/th><th>What it does<\/th><\/tr>\n      <\/thead>\n      <tbody>\n        <tr>\n          <td data-label=\"Block\"><strong>input<\/strong> parameters<\/td>\n          <td data-label=\"What it does\">Settings you can change from the robot's dialog in MetaTrader 5, with no edit to the source: EMA periods, lot size, stop-loss, take-profit and the magic number.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Block\"><strong>OnInit()<\/strong><\/td>\n          <td data-label=\"What it does\">Runs once when the robot starts. Creates the two EMA handles and refuses to start if either one fails.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Block\"><strong>OnTick()<\/strong>, new bar filter<\/td>\n          <td data-label=\"What it does\">Runs on every incoming tick, then exits immediately unless a new bar has opened, so the strategy is evaluated once per candle.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Block\"><strong>CopyBuffer()<\/strong> and the crossover test<\/td>\n          <td data-label=\"What it does\">Reads the last three values of each EMA and compares the two closed bars to decide whether a crossover happened.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Block\"><strong>CTrade<\/strong>, trade execution<\/td>\n          <td data-label=\"What it does\">Sends the order, attaches the stop-loss and take-profit, and closes an opposite position first when the signal reverses.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Block\"><strong>OnDeinit()<\/strong><\/td>\n          <td data-label=\"What it does\">Runs once when the robot is removed from the chart and releases both indicator handles.<\/td>\n        <\/tr>\n      <\/tbody>\n    <\/table>\n  <\/div>\n\n  <h3>Input Parameters<\/h3>\n\n  <p>The settings at the top of the file carry the <code>input<\/code> modifier, which exposes them in the robot's parameter window inside MetaTrader 5. In this example that covers the fast and slow EMA periods, <code>InpFastEMA<\/code> and <code>InpSlowEMA<\/code>, along with <code>InpLotSize<\/code>, <code>InpStopLoss<\/code>, <code>InpTakeProfit<\/code> and <code>InpMagic<\/code>.<\/p>\n\n  <p>The advantage is that changing a setting takes no edit to the source code. Values can be adjusted right before launching the robot, and the Strategy Tester can sweep through them during optimisation.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_7.png\" alt=\"Inputs tab of the expert advisor dialog in MetaTrader 5 showing the editable parameters\"><\/a><figcaption class=\"wp-element-caption\">The Inputs tab exposes every parameter declared with the input modifier. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <h3>Initialization with OnInit()<\/h3>\n\n  <p>OnInit() runs once when the robot starts, which happens when you attach it to a chart or restart the terminal. It prepares the resources the robot needs later, creating the indicator handles that supply the EMA values.<\/p>\n\n  <p>When that preparation fails, the function returns <code>INIT_FAILED<\/code> and the terminal stops the robot instead of running it half-configured. It also sets the magic number, the tag that marks every order this robot sends and lets it tell its own positions apart from anything else on the same symbol.<\/p>\n\n  <h3>The Tick Event and the New Bar Filter<\/h3>\n\n  <p>OnTick() is the main function. The terminal calls it whenever a new tick arrives, meaning any change in the quote. Evaluating the strategy on every tick would be wasted work here, so a new bar filter cuts the processing down to once per candle.<\/p>\n\n  <p>The robot reads the opening time of the current bar with <code>iTime()<\/code> and compares it with the time it processed last:<\/p>\n\n  <div class=\"ea-code-wrap ea-code-inline\">\n    <pre class=\"ea-code\"><code>if(currentBarTime == lastBarTime)\n   return;<\/code><\/pre>\n  <\/div>\n\n  <p>When a new candle opens, that time changes and the robot continues. The strategy therefore reacts once per candle instead of following every price change inside it.<\/p>\n\n  <p>After the filter, the robot copies both EMAs with <code>CopyBuffer()<\/code> and checks for a crossover. Index 1 holds the last closed bar and index 2 the bar before it, so the comparison never touches the candle still forming. EMA 9 crossing above EMA 21 raises <code>buySignal<\/code>, crossing below raises <code>sellSignal<\/code>, and only then does the execution block take over.<\/p>\n\n  <!-- WIDGET: EMA crossover visualiser -->\n  <div class=\"ea-widget\" id=\"ea-ema-widget\">\n    <div class=\"ea-widget-title\">Where the robot sees a signal<\/div>\n    <div class=\"ea-widget-sub\">Move the slider to advance the chart one bar at a time. The robot compares the last two closed bars, the same two values its code reads as index 1 and index 2.<\/div>\n\n    <div class=\"ea-ema-chart\">\n      <svg id=\"ea-ema-svg\" viewbox=\"0 0 720 250\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Price with EMA 9 and EMA 21, advancing bar by bar\">\n        <path id=\"ea-ema-price\" class=\"ea-ema-line-price\" d=\"\" fill=\"none\"><\/path>\n        <path id=\"ea-ema-slow\" class=\"ea-ema-line-slow\" d=\"\" fill=\"none\"><\/path>\n        <path id=\"ea-ema-fast\" class=\"ea-ema-line-fast\" d=\"\" fill=\"none\"><\/path>\n        <g id=\"ea-ema-marks\"><\/g>\n        <circle id=\"ea-ema-dot\" class=\"ea-ema-dot\" cx=\"-10\" cy=\"-10\" r=\"5\"><\/circle>\n      <\/svg>\n    <\/div>\n\n    <div class=\"ea-ema-legend\">\n      <span class=\"ea-leg ea-leg-fast\">EMA 9<\/span>\n      <span class=\"ea-leg ea-leg-slow\">EMA 21<\/span>\n      <span class=\"ea-leg ea-leg-price\">Close price<\/span>\n    <\/div>\n\n    <label class=\"ea-range-label\" for=\"ea-ema-range\">Bar on the chart<\/label>\n    <input type=\"range\" class=\"ea-range\" id=\"ea-ema-range\" min=\"21\" max=\"55\" value=\"21\" step=\"1\">\n\n    <div class=\"ea-ema-stats\">\n      <div class=\"ea-stat\"><div class=\"ea-stat-lbl\">EMA 9, last closed bar<\/div><div class=\"ea-stat-val\" id=\"ea-ema-fastval\">0<\/div><\/div>\n      <div class=\"ea-stat\"><div class=\"ea-stat-lbl\">EMA 21, last closed bar<\/div><div class=\"ea-stat-val\" id=\"ea-ema-slowval\">0<\/div><\/div>\n      <div class=\"ea-stat\"><div class=\"ea-stat-lbl\">What the robot does<\/div><div class=\"ea-stat-val\" id=\"ea-ema-signal\">Waits<\/div><\/div>\n    <\/div>\n\n    <div class=\"ea-ema-verdict\" id=\"ea-ema-verdict\">No crossover on the last two closed bars, so the robot holds its position and waits for the next candle.<\/div>\n  <\/div>\n\n  <script>\n  (function() {\n    var range = document.getElementById('ea-ema-range');\n    var svg   = document.getElementById('ea-ema-svg');\n    if(!range || !svg) return;\n\n    var pricePath = document.getElementById('ea-ema-price');\n    var fastPath  = document.getElementById('ea-ema-fast');\n    var slowPath  = document.getElementById('ea-ema-slow');\n    var marks     = document.getElementById('ea-ema-marks');\n    var dot       = document.getElementById('ea-ema-dot');\n    var fastOut   = document.getElementById('ea-ema-fastval');\n    var slowOut   = document.getElementById('ea-ema-slowval');\n    var sigOut    = document.getElementById('ea-ema-signal');\n    var verdict   = document.getElementById('ea-ema-verdict');\n\n    \/\/ Deterministic sample path: a decline, a rally, then a decline again,\n    \/\/ so the reader sees one upward crossover and one downward crossover.\n    var close = [\n      1.2700,1.2712,1.2695,1.2680,1.2688,1.2665,1.2650,1.2658,1.2640,1.2622,\n      1.2630,1.2610,1.2595,1.2602,1.2585,1.2570,1.2578,1.2560,1.2566,1.2555,\n      1.2572,1.2590,1.2585,1.2604,1.2620,1.2612,1.2635,1.2650,1.2644,1.2668,\n      1.2685,1.2678,1.2700,1.2715,1.2708,1.2730,1.2745,1.2738,1.2758,1.2770,\n      1.2762,1.2780,1.2795,1.2788,1.2770,1.2740,1.2745,1.2715,1.2690,1.2695,\n      1.2665,1.2640,1.2648,1.2620,1.2600,1.2608\n    ];\n\n    function ema(src, period) {\n      var out = [], k = 2 \/ (period + 1), seed = 0, i;\n      for(i = 0; i < period; i++) seed += src[i];\n      seed = seed \/ period;\n      for(i = 0; i < src.length; i++) {\n        if(i < period - 1) { out.push(null); continue; }\n        if(i === period - 1) { out.push(seed); continue; }\n        out.push(src[i] * k + out[i - 1] * (1 - k));\n      }\n      return out;\n    }\n\n    var fast = ema(close, 9);\n    var slow = ema(close, 21);\n\n    \/\/ Fixed vertical scale, so the lines stay put as the slider moves.\n    var lo = Math.min.apply(null, close);\n    var hi = Math.max.apply(null, close);\n    var pad = (hi - lo) * 0.12;\n    lo -= pad; hi += pad;\n\n    var W = 720, H = 250, PX = 12, PY = 14;\n\n    function x(i) { return PX + (i \/ (close.length - 1)) * (W - 2 * PX); }\n    function y(v) { return H - PY - ((v - lo) \/ (hi - lo)) * (H - 2 * PY); }\n\n    function line(series, upto) {\n      var d = '', started = false;\n      for(var i = 0; i <= upto; i++) {\n        if(series[i] === null || series[i] === undefined) continue;\n        d += (started ? 'L' : 'M') + x(i).toFixed(1) + ' ' + y(series[i]).toFixed(1) + ' ';\n        started = true;\n      }\n      return d;\n    }\n\n    \/\/ A crossover is read exactly the way the robot reads it: the bar before\n    \/\/ the last closed one, then the last closed one.\n    function crossAt(i) {\n      if(i < 21 || fast[i] === null || fast[i - 1] === null) return 0;\n      if(fast[i - 1] <= slow[i - 1] && fast[i] > slow[i]) return 1;\n      if(fast[i - 1] >= slow[i - 1] && fast[i] < slow[i]) return -1;\n      return 0;\n    }\n\n    function render() {\n      var i = parseInt(range.value, 10);\n\n      pricePath.setAttribute('d', line(close, i));\n      fastPath.setAttribute('d', line(fast, i));\n      slowPath.setAttribute('d', line(slow, i));\n\n      dot.setAttribute('cx', x(i).toFixed(1));\n      dot.setAttribute('cy', y(close[i]).toFixed(1));\n\n      \/\/ Every crossover already passed stays marked on the chart.\n      var m = '';\n      for(var j = 21; j <= i; j++) {\n        var c = crossAt(j);\n        if(c !== 0) {\n          m += '<circle class=\"' + (c === 1 ? 'ea-ema-cross-up' : 'ea-ema-cross-down') +\n               '\" cx=\"' + x(j).toFixed(1) + '\" cy=\"' + y(fast[j]).toFixed(1) + '\" r=\"6\">';\n        }\n      }\n      marks.innerHTML = m;\n\n      fastOut.innerHTML = fast[i].toFixed(4);\n      slowOut.innerHTML = slow[i].toFixed(4);\n\n      var state = crossAt(i);\n      if(state === 1) {\n        sigOut.innerHTML = 'Opens a buy';\n        sigOut.className = 'ea-stat-val ea-stat-buy';\n        verdict.innerHTML = 'EMA 9 was at or below EMA 21 on the previous bar and closed above it on the last bar. That raises <strong>buySignal, and the robot opens a buy, closing an open sell first.';\n        verdict.className = 'ea-ema-verdict ea-ema-verdict-buy';\n      } else if(state === -1) {\n        sigOut.innerHTML = 'Opens a sell';\n        sigOut.className = 'ea-stat-val ea-stat-sell';\n        verdict.innerHTML = 'EMA 9 was at or above EMA 21 on the previous bar and closed below it on the last bar. That raises <strong>sellSignal, and the robot opens a sell, closing an open buy first.';\n        verdict.className = 'ea-ema-verdict ea-ema-verdict-sell';\n      } else {\n        sigOut.innerHTML = 'Waits';\n        sigOut.className = 'ea-stat-val';\n        verdict.innerHTML = 'No crossover on the last two closed bars, so the robot holds its position and waits for the next candle.';\n        verdict.className = 'ea-ema-verdict';\n      }\n    }\n\n    range.addEventListener('input', render);\n    render();\n  })();\n  <\/script>\n\n  <div class=\"ea-callout\">\n    <div class=\"ea-callout-label\">Why the arrays are declared empty<\/div>\n    <p>The two arrays are declared as <code>double fastEMA[]<\/code> with no size, then passed to <code>ArraySetAsSeries()<\/code>. That flag reverses the indexing so index 0 is the newest bar, which is how the rest of the code reads. MQL5 refuses to set that flag on an array whose size is fixed in the source, so a sized declaration such as <code>double fastEMA[3]<\/code> would silently leave the indexing reversed and turn every buy signal into a sell.<\/p>\n  <\/div>\n\n  <h3>Trade Execution<\/h3>\n\n  <p>Orders go through <code>CTrade<\/code>, a class from the standard MQL5 library that wraps the work of assembling a trade request by hand. Depending on the signal, the robot calls <code>trade.Buy()<\/code> or <code>trade.Sell()<\/code> and passes the position volume together with the stop-loss and take-profit levels.<\/p>\n\n  <p>Both levels are calculated in points from the current price and then passed through <code>NormalizeDouble()<\/code>, which trims them to the number of decimals the symbol actually uses. Servers reject prices carrying more precision than the instrument allows, and this is where that shows up.<\/p>\n\n  <p>Before opening anything, the robot checks whether a position on the symbol already belongs to it by comparing <code>POSITION_MAGIC<\/code> with its own magic number. That check keeps it from closing a trade you opened by hand or one belonging to another robot on the same instrument.<\/p>\n\n  <h2><span class=\"ez-toc-section\" id=\"A_Ready-Made_Template_and_AI-Generated_Code\"><\/span>A Ready-Made Template and AI-Generated Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>AI tools have made expert advisors much easier to start. A trader with no programming experience can describe a trading idea in plain words and get the basis of an MQL5 robot back.<\/p>\n\n  <p>There is still a difference between working from a template and generating code from scratch. A model can produce complicated trading logic quickly, and that code still has to be read, compiled and tested. MQL5 is a narrower target than mainstream languages, so a model is more likely to invent a function signature, blend MQL4 habits into MQL5 code, or leave out a safeguard nobody asked for.<\/p>\n\n  <div class=\"ea-table-wrap ea-table-wide\">\n    <table class=\"rf\">\n      <thead>\n        <tr><th>Criterion<\/th><th>Ready-made template<\/th><th>AI-generated code<\/th><\/tr>\n      <\/thead>\n      <tbody>\n        <tr>\n          <td data-label=\"Criterion\"><strong>Reliability<\/strong><\/td>\n          <td data-label=\"Ready-made template\">The structure is fixed and the logic of the example is documented. Compiling and testing are still required.<\/td>\n          <td data-label=\"AI-generated code\">Depends on the prompt and the model. The code needs the same compile and test pass, from a lower starting point.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Criterion\"><strong>Safeguards<\/strong><\/td>\n          <td data-label=\"Ready-made template\">The new bar filter and the magic number check are already in place.<\/td>\n          <td data-label=\"AI-generated code\">Safeguards appear when the prompt asks for them. A prompt describing only the entry rule tends to return only the entry rule.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Criterion\"><strong>Speed to a running robot<\/strong><\/td>\n          <td data-label=\"Ready-made template\">High. Paste, compile, test.<\/td>\n          <td data-label=\"AI-generated code\">High on a simple task. Complex logic often takes several rounds of generating and fixing.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Criterion\"><strong>Flexibility<\/strong><\/td>\n          <td data-label=\"Ready-made template\">Limited to the logic of this robot and the parameters it exposes.<\/td>\n          <td data-label=\"AI-generated code\">High. The strategy can be shaped around your own rules, indicators and filters.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Criterion\"><strong>Strategy complexity<\/strong><\/td>\n          <td data-label=\"Ready-made template\">Suits simple, legible trading models.<\/td>\n          <td data-label=\"AI-generated code\">Handles more elaborate concepts, and the more elaborate the code, the more the verification matters.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Criterion\"><strong>Verification<\/strong><\/td>\n          <td data-label=\"Ready-made template\">Required. A clean compile says nothing about whether the trading logic is sound.<\/td>\n          <td data-label=\"AI-generated code\">Required twice over: the syntax, and whether the code matches the idea you described.<\/td>\n        <\/tr>\n      <\/tbody>\n    <\/table>\n  <\/div>\n\n  <p>A ready template is the faster way to see how an expert advisor is put together. AI becomes genuinely useful at the next step, once you have working code in front of you and want it explained, extended or adapted. Most beginners get the most out of both: start from a working example, then use an AI chat to walk through individual blocks and add conditions of your own.<\/p>\n\n  <h2><span class=\"ez-toc-section\" id=\"How_to_Compile_and_Launch_the_Robot_in_MetaTrader_5\"><\/span>How to Compile and Launch the Robot in MetaTrader 5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>With the trading logic in the file, three steps turn it into a robot running on a chart.<\/p>\n\n  <h3>Step 1. Put the Code in the File<\/h3>\n\n  <p>This uses the <code>.mq5<\/code> file the MQL Wizard created earlier. The generated template holds boilerplate code, and all of it gets replaced by the listing above, so the file contains the robot and nothing else.<\/p>\n\n  <h3>Step 2. Compile<\/h3>\n\n  <p>Compiling converts MQL5 source into the executable format the terminal runs, producing an <code>.ex5<\/code> file. Start it with the Compile button on the MetaEditor toolbar or with <strong>F7<\/strong>.<\/p>\n\n  <p>The result appears at the bottom of the window. With no syntax errors, the message reads:<\/p>\n\n  <div class=\"ea-code-wrap ea-code-inline\">\n    <pre class=\"ea-code\"><code>0 error(s), 0 warning(s)<\/code><\/pre>\n  <\/div>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_10.png\" alt=\"MetaEditor Toolbox showing a successful compile with zero errors and zero warnings\"><\/a><figcaption class=\"wp-element-caption\">A clean compile produces the .ex5 file the terminal can run. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>A clean compile confirms the code is valid to the compiler. It says nothing about whether the strategy makes money or whether the logic does what you intended, which is what the Strategy Tester is for.<\/p>\n\n  <h3>Step 3. Attach the Robot to a Chart<\/h3>\n\n  <p>The compiled robot now appears in MetaTrader 5. Open the <strong>Navigator<\/strong> window, go to <strong>Expert Advisors<\/strong> and find <strong>MyFirstRobot<\/strong>. Drag it onto the chart of the instrument you want it to trade.<\/p>\n\n  <p>The parameter window opens. Check the input settings here, including the trading volume, the EMA periods and the stop-loss and take-profit levels. On the <strong>Common<\/strong> tab, confirm that <strong>Allow Algo Trading<\/strong> is ticked, then accept the dialog.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_11.png\" alt=\"Expert advisor dialog in MetaTrader 5 with Allow Algo Trading enabled on the Common tab\"><\/a><figcaption class=\"wp-element-caption\">The Common tab, where the robot is granted permission to trade. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>When the <strong>Algo Trading<\/strong> button in the terminal toolbar is active as well, the robot can send orders according to its logic and starts following the market on the parameters you set.<\/p>\n\n  <h2><span class=\"ez-toc-section\" id=\"Testing_in_the_Strategy_Tester\"><\/span>Testing in the Strategy Tester<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>Before a robot goes anywhere near a live account, it belongs in the Strategy Tester built into MetaTrader 5. A test on historical data shows how the robot would have executed its rules across different market conditions, and it surfaces technical faults long before money is involved.<\/p>\n\n  <h3>How to Run the Test<\/h3>\n\n  <p>Open the tester with <strong>Ctrl + R<\/strong>. In its settings, select the <strong>MyFirstRobot<\/strong> expert advisor, the instrument, for example GBPUSD, and the H1 <a href=\"https:\/\/roboforex.com\/blog\/education\/how-to-choose-a-timeframe-for-trading\/\" data-internallinksmanager029f6b8e52c=\"135\" title=\"Timeframe\">timeframe<\/a> this example is written for. For the most realistic simulation, choose the <strong>Every tick based on real ticks<\/strong> modelling mode and set the historical period.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_14.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_14.png\" alt=\"Strategy Tester settings in MetaTrader 5 with the expert advisor, symbol and timeframe selected\"><\/a><figcaption class=\"wp-element-caption\">Strategy Tester setup: expert advisor, symbol, timeframe, period and modelling mode. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>MetaTrader 5 then replays the historical price movement and simulates the robot: signals appearing, positions opening and closing, and the running financial result. Watch that positions open and close as expected and that the stop-loss and take-profit land where they should.<\/p>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_15.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_15.png\" alt=\"Strategy Tester report in MetaTrader 5 showing the balance curve and result metrics\"><\/a><figcaption class=\"wp-element-caption\">The tester report after a completed run. Source: MetaTrader 5. Past results do not guarantee future performance.<\/figcaption><\/figure>\n\n  <p>A <a href=\"https:\/\/roboforex.com\/blog\/education\/how-to-test-a-trading-strategy\/\" data-internallinksmanager029f6b8e52c=\"296\" title=\"Test a strategy\">backtest<\/a> shows how the rules performed on price history that is already known. It is a check that the robot executes its logic correctly, and it carries no forecast of future income. The more complex a strategy and the more tightly it is fitted to historical data, the more its live results tend to fall short of the test.<\/p>\n\n  <p><em>For the full tick-testing setup, see <a href=\"https:\/\/roboforex.com\/blog\/education\/a-15-minute-backtest-how-to-test-a-trading-robot-in-metatrader-5\/\">A 15-Minute Backtest: How to Test a Trading Robot in MetaTrader 5<\/a>.<\/em><\/p>\n\n  <h3>Which Numbers to Read in the Report<\/h3>\n\n  <p>MetaTrader 5 produces a detailed report. Four figures are enough for a first assessment.<\/p>\n\n  <div class=\"ea-table-wrap ea-table-wide\">\n    <table class=\"rf\">\n      <thead>\n        <tr><th>Metric<\/th><th>What it shows<\/th><th>What to watch<\/th><\/tr>\n      <\/thead>\n      <tbody>\n        <tr>\n          <td data-label=\"Metric\"><strong>Profit Factor<\/strong><\/td>\n          <td data-label=\"What it shows\">Total profit divided by total loss across the test. Above 1 means winning trades outweighed losing ones.<\/td>\n          <td data-label=\"What to watch\">A low value points to weak statistics. Values above 1.2 to 1.5 are a common first filter, and no universal threshold exists.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Metric\"><strong>Max Drawdown<\/strong><\/td>\n          <td data-label=\"What it shows\">The deepest fall in the balance from a previous peak.<\/td>\n          <td data-label=\"What to watch\">A large drawdown means heavy pressure on the deposit. Read it together with the return and the position size.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Metric\"><strong>Total Trades<\/strong><\/td>\n          <td data-label=\"What it shows\">How many trades the robot made over the tested period.<\/td>\n          <td data-label=\"What to watch\">A small sample carries little statistical weight. A few dozen good trades support no firm conclusion about reliability.<\/td>\n        <\/tr>\n        <tr>\n          <td data-label=\"Metric\"><strong>Win Rate<\/strong><\/td>\n          <td data-label=\"What it shows\">The share of profitable trades in the total.<\/td>\n          <td data-label=\"What to watch\">On its own it settles nothing. Read it against the average win, the average loss and the stop-loss and take-profit in use.<\/td>\n        <\/tr>\n      <\/tbody>\n    <\/table>\n  <\/div>\n\n  <h3>What the Report Shows Beyond the Profit Line<\/h3>\n\n  <p>Reading only the bottom-line profit is the most common shortcut among new algo traders. A strategy can post an impressive return while carrying a deep drawdown or resting on a handful of trades. Weigh the profit factor and the final profit together with the maximum drawdown, the number of trades, the shape of the equity curve and how results are spread over time.<\/p>\n\n  <p>One more thing deserves attention: how well the result survives a change of test period or a small change of parameters. When a minor adjustment flips a profitable strategy into a losing one, the strategy is likely fitted to its history.<\/p>\n\n  <div class=\"ea-callout\">\n    <div class=\"ea-callout-label\">What a first backtest is for<\/div>\n    <p>The goal of a first backtest is confirmation that the robot implements the trading logic correctly and produces nothing obviously broken. Finding an ideal strategy comes later, across other historical periods and then on a demo account.<\/p>\n  <\/div>\n\n  <div class=\"ea-promo\">\n    <div>\n      <div class=\"ea-promo-title\">From the Tester to a Live Chart<\/div>\n      <div class=\"ea-promo-sub\">A <a href=\"https:\/\/roboforex.com\/forex-trading\/trading\/cent-account\/\" data-internallinksmanager029f6b8e52c=\"48\" title=\"Cent accounts\">cent account<\/a> lets the robot trade the minimum lot on live prices, so the first supervised run costs a fraction of a standard account.<\/div>\n    <\/div>\n    <div class=\"ea-promo-actions\">\n      <a class=\"ea-promo-btn\" href=\"https:\/\/my.roboforex.com\/en\/register\/\" target=\"_blank\" rel=\"nofollow\">Open an Account<\/a>\n    <\/div>\n  <\/div>\n\n  <h2><span class=\"ez-toc-section\" id=\"The_Pre-Launch_Checklist\"><\/span>The Pre-Launch Checklist<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>A successful compile does not mean the robot is ready for a live account. Work through these before switching automated trading on.<\/p>\n\n  <!-- WIDGET: interactive checklist -->\n  <div class=\"ea-checklist\" id=\"ea-checklist\">\n    <div class=\"ea-check-head\">\n      <div class=\"ea-check-count\" id=\"ea-check-count\">0 of 5 checked<\/div>\n      <div class=\"ea-check-track\"><div class=\"ea-check-bar\" id=\"ea-check-bar\"><\/div><\/div>\n    <\/div>\n    <button type=\"button\" class=\"ea-check-item\" data-ea-check=\"tester\">The robot has been through the Strategy Tester on the instrument and timeframe you intend to trade, as covered in the previous section.<\/button>\n    <button type=\"button\" class=\"ea-check-item\" data-ea-check=\"algo\">The <strong>Algo Trading<\/strong> button in the terminal toolbar is active, and <strong>Allow Algo Trading<\/strong> is ticked in the robot's own dialog. Both are needed before a single order can go out.<\/button>\n    <button type=\"button\" class=\"ea-check-item\" data-ea-check=\"log\">The <strong>Experts<\/strong> tab in the Toolbox shows the startup message and no errors. The <strong>Journal<\/strong> tab is worth a look as well.<\/button>\n    <button type=\"button\" class=\"ea-check-item\" data-ea-check=\"lot\">The lot size in the Inputs tab is set to the minimum your <a href=\"https:\/\/roboforex.com\/\" data-internallinksmanager029f6b8e52c=\"31\" title=\"forex broker\">broker<\/a> allows, commonly 0.01 on standard currency instruments, instead of the 0.10 the example ships with.<\/button>\n    <button type=\"button\" class=\"ea-check-item\" data-ea-check=\"account\">The account is a demo one, or a live account carrying only money you have set aside for this test.<\/button>\n    <div class=\"ea-check-done\" id=\"ea-check-done\">&#10003; All five checked. The robot is ready for its first supervised run.<\/div>\n  <\/div>\n\n  <script>\n  (function() {\n    var box = document.getElementById('ea-checklist');\n    if(!box) return;\n\n    var items = box.querySelectorAll('[data-ea-check]');\n    var count = document.getElementById('ea-check-count');\n    var bar   = document.getElementById('ea-check-bar');\n    var done  = document.getElementById('ea-check-done');\n    var KEY   = 'ea-mql5-checklist';\n\n    function load() {\n      try { return JSON.parse(localStorage.getItem(KEY)) || {}; }\n      catch(e) { return {}; }\n    }\n    function save(state) {\n      try { localStorage.setItem(KEY, JSON.stringify(state)); }\n      catch(e) { \/* private mode, the checklist still works for this visit *\/ }\n    }\n\n    var state = load();\n\n    function render() {\n      var n = 0;\n      for(var i = 0; i < items.length; i++) {\n        var key = items[i].getAttribute('data-ea-check');\n        var on  = state[key] === true;\n        items[i].className = 'ea-check-item' + (on ? ' ea-is-done' : '');\n        items[i].setAttribute('aria-pressed', on ? 'true' : 'false');\n        if(on) n++;\n      }\n      count.innerHTML = n + ' of ' + items.length + ' checked';\n      bar.style.width = (n \/ items.length * 100) + '%';\n      done.style.display = (n === items.length) ? 'block' : 'none';\n    }\n\n    for(var i = 0; i < items.length; i++) {\n      items[i].addEventListener('click', function() {\n        var key = this.getAttribute('data-ea-check');\n        state[key] = !state[key];\n        save(state);\n        render();\n      });\n    }\n\n    render();\n  })();\n  <\/script>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_12.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_12.png\" alt=\"Algo Trading button on the MetaTrader 5 toolbar in the enabled state\"><\/a><figcaption class=\"wp-element-caption\">The terminal-level Algo Trading switch, the second of the two permissions. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <figure class=\"wp-block-image size-large\"><a href=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_13.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/MQL5_expert_Advisor_13.png\" alt=\"Experts tab of the MetaTrader 5 Toolbox showing expert advisor log messages\"><\/a><figcaption class=\"wp-element-caption\">The Experts tab reports startup, trades and errors, and reads MyFirstRobot (EURUSD,H1): initialized on a clean start. Source: MetaTrader 5.<\/figcaption><\/figure>\n\n  <p>Give the first weeks to watching how the robot behaves in live conditions: that it receives quotes, opens positions only when its conditions are met, attaches its protective orders and takes no trades you did not expect.<\/p>\n\n  <h2><span class=\"ez-toc-section\" id=\"Two_Situations_to_Handle_on_the_First_Launch\"><\/span>Two Situations to Handle on the First Launch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>A first launch can surface problems that neither the compiler nor the first test showed. The code compiles, the robot sits on the chart, Algo Trading is on, and still nothing happens. In practice the cause often sits in the account conditions, the instrument settings or the way the terminal is running. Two cases come up most often.<\/p>\n\n  <h3>The Robot Stays Silent Because of Margin<\/h3>\n\n  <p>Picture a robot on GBPUSD H1. EMA 9 crosses EMA 21, and no position appears. The first place to look is the <strong>Journal<\/strong> tab and the messages under <strong>Experts<\/strong>. A line reading <code>Not enough money<\/code> points at free margin.<\/p>\n\n  <p>Opening a position makes the broker reserve part of the account as margin collateral. The amount depends on the trade volume, the price of the instrument, the contract type, the <a href=\"https:\/\/roboforex.com\/clients\/services\/2000-up-leverage\/\" data-internallinksmanager029f6b8e52c=\"44\" title=\"Leverage\">leverage<\/a> and the account conditions. A fixed <code>InpLotSize = 0.1<\/code> can be too large for a small deposit on some instruments, so the lot size only makes sense read against the balance and the available margin.<\/p>\n\n  <p>Check that the account holds enough free funds for the volume you configured. The required margin per lot is listed in the instrument specification in MetaTrader 5. On a small account, the minimum allowed volume is the sensible starting point. Sufficient margin and a safe position size are separate questions: having enough margin to open a trade says nothing about what that trade can cost you.<\/p>\n\n  <!-- WIDGET: margin calculator -->\n  <div class=\"ea-widget\" id=\"ea-margin-widget\">\n    <div class=\"ea-widget-title\">Will the robot be able to open this position?<\/div>\n    <div class=\"ea-widget-sub\">Enter your own numbers to see how much margin the volume in <code>InpLotSize<\/code> would tie up. Take the price from your terminal.<\/div>\n\n    <div class=\"ea-calc-grid\">\n      <div class=\"ea-calc-field\">\n        <label class=\"ea-calc-lbl\" for=\"ea-calc-balance\">Free funds on the account, USD<\/label>\n        <input class=\"ea-calc-in\" type=\"number\" id=\"ea-calc-balance\" value=\"100\" min=\"1\" step=\"10\">\n      <\/div>\n      <div class=\"ea-calc-field\">\n        <label class=\"ea-calc-lbl\" for=\"ea-calc-lots\">Lot size, InpLotSize<\/label>\n        <input class=\"ea-calc-in\" type=\"number\" id=\"ea-calc-lots\" value=\"0.10\" min=\"0.01\" step=\"0.01\">\n      <\/div>\n      <div class=\"ea-calc-field\">\n        <label class=\"ea-calc-lbl\" for=\"ea-calc-lev\">Leverage<\/label>\n        <select class=\"ea-calc-in\" id=\"ea-calc-lev\">\n          <option value=\"5\">1:5<\/option>\n          <option value=\"10\">1:10<\/option>\n          <option value=\"20\">1:20<\/option>\n          <option value=\"50\">1:50<\/option>\n          <option value=\"100\" selected>1:100<\/option>\n          <option value=\"200\">1:200<\/option>\n          <option value=\"500\">1:500<\/option>\n          <option value=\"1000\">1:1000<\/option>\n        <\/select>\n      <\/div>\n      <div class=\"ea-calc-field\">\n        <label class=\"ea-calc-lbl\" for=\"ea-calc-price\">Instrument price<\/label>\n        <input class=\"ea-calc-in\" type=\"number\" id=\"ea-calc-price\" value=\"1.2700\" min=\"0.0001\" step=\"0.0001\">\n      <\/div>\n      <div class=\"ea-calc-field ea-calc-field-wide\">\n        <label class=\"ea-calc-lbl\" for=\"ea-calc-contract\">Contract size, units in one lot<\/label>\n        <input class=\"ea-calc-in\" type=\"number\" id=\"ea-calc-contract\" value=\"100000\" min=\"0.01\" step=\"1\">\n        <div class=\"ea-calc-hint\">This differs by instrument. A standard currency lot is 100,000 units of the base currency, while metals, <a href=\"https:\/\/roboforex.com\/forex-trading\/assets\/indices\/\" data-internallinksmanager029f6b8e52c=\"11\" title=\"indices trading\">indices<\/a> and other CFDs each use their own value. Read yours from the instrument specification in MetaTrader 5: right-click the symbol in Market Watch and open <strong>Specification<\/strong>.<\/div>\n      <\/div>\n    <\/div>\n\n    <div class=\"ea-calc-out\">\n      <div class=\"ea-stat\"><div class=\"ea-stat-lbl\">Position size<\/div><div class=\"ea-stat-val\" id=\"ea-calc-notional\">0<\/div><\/div>\n      <div class=\"ea-stat\"><div class=\"ea-stat-lbl\">Margin required<\/div><div class=\"ea-stat-val\" id=\"ea-calc-margin\">0<\/div><\/div>\n      <div class=\"ea-stat\"><div class=\"ea-stat-lbl\">Free funds left<\/div><div class=\"ea-stat-val\" id=\"ea-calc-left\">0<\/div><\/div>\n    <\/div>\n\n    <div class=\"ea-calc-verdict\" id=\"ea-calc-verdict\">&#10003; The order goes through.<\/div>\n\n    <div class=\"ea-calc-note\">An estimate for an instrument quoted against the US dollar, using the standard formula: lots multiplied by contract size and price, divided by leverage. Instruments not quoted against the dollar carry a conversion the terminal handles for you, and swap, spread and commission come on top. Your account type and the symbol specification are the authority on all of it. Margin covering the trade is also a separate question from the position being a sensible size for the account.<\/div>\n  <\/div>\n\n  <script>\n  (function() {\n    var bal = document.getElementById('ea-calc-balance');\n    var lot = document.getElementById('ea-calc-lots');\n    var lev = document.getElementById('ea-calc-lev');\n    var prc = document.getElementById('ea-calc-price');\n    var con = document.getElementById('ea-calc-contract');\n    if(!bal || !lot || !lev || !prc || !con) return;\n\n    var outNotional = document.getElementById('ea-calc-notional');\n    var outMargin   = document.getElementById('ea-calc-margin');\n    var outLeft     = document.getElementById('ea-calc-left');\n    var outVerdict  = document.getElementById('ea-calc-verdict');\n\n    function money(v) {\n      return v.toFixed(2).replace(\/\\B(?=(\\d{3})+(?!\\d))\/g, ',') + ' USD';\n    }\n\n    function render() {\n      var balance  = parseFloat(bal.value) || 0;\n      var lots     = parseFloat(lot.value) || 0;\n      var leverage = parseFloat(lev.value) || 1;\n      var price    = parseFloat(prc.value) || 0;\n      \/\/ Units in one lot. 100,000 for a standard currency lot, and something\n      \/\/ else for metals, indices and other CFDs, so the reader supplies it.\n      var contract = parseFloat(con.value) || 0;\n\n      var notional = lots * contract * price;\n      var margin   = notional \/ leverage;\n      var left     = balance - margin;\n\n      outNotional.innerHTML = money(notional);\n      outMargin.innerHTML   = money(margin);\n\n      if(left >= 0) {\n        outLeft.innerHTML   = money(left);\n        outLeft.className   = 'ea-stat-val';\n        outVerdict.innerHTML = '&#10003; The margin fits. The robot opens the position and ' +\n                               money(margin) + ' stays reserved while it is open.';\n        outVerdict.className = 'ea-calc-verdict ea-calc-ok';\n      } else {\n        outLeft.innerHTML   = money(left);\n        outLeft.className   = 'ea-stat-val ea-stat-sell';\n        outVerdict.innerHTML = '&#10007; Short by ' + money(Math.abs(left)) +\n                               '. The terminal declines the request and the Journal tab reports ' +\n                               '<strong>Not enough money. Lower the lot size, or fund the account.';\n        outVerdict.className = 'ea-calc-verdict ea-calc-bad';\n      }\n    }\n\n    [bal, lot, prc, con].forEach(function(el) { el.addEventListener('input', render); });\n    lev.addEventListener('change', render);\n    render();\n  })();\n  <\/script>\n\n  <div class=\"ea-callout\">\n    <div class=\"ea-callout-label\">Practical tip<\/div>\n    <p>When the robot skips a signal, read the Experts and Journal tabs before touching the code. The terminal message usually names the reason the trade request was declined.<\/p>\n  <\/div>\n\n  <h3>The Robot Only Runs While the Terminal Runs<\/h3>\n\n  <p>The second case is the assumption that a robot on a chart keeps working whatever happens to the computer. On a local setup it does not. An MQL5 expert advisor runs inside a running copy of MetaTrader 5. Close the terminal or switch the machine off, and the local robot stops receiving ticks and stops executing its logic.<\/p>\n\n  <p>If EMA 9 and EMA 21 cross during that time, the signal goes unprocessed until the terminal is running again. The same applies to managing a position that is already open, whenever that logic lives inside the robot.<\/p>\n\n  <p>For a robot meant to work around the clock, the answer is a Virtual Private Server. MetaTrader 5 includes a virtual hosting service that migrates the robot's trading environment onto remote infrastructure, and RoboForex offers a <a href=\"https:\/\/roboforex.com\/clients\/services\/forex-vps\/\" data-internallinksmanager029f6b8e52c=\"14\" title=\"vps for forex\">VPS<\/a> for the same job. Once migrated, the robot keeps running whether or not your own computer is on.<\/p>\n\n  <!-- TODO before publication: link \"RoboForex VPS\" above once a verified URL\n       is supplied. See notes.md, open question 1. -->\n\n  <p>A VPS solves continuity of the trading environment. It makes no strategy more reliable and fixes no error in the code.<\/p>\n\n  <div class=\"ea-callout\">\n    <div class=\"ea-callout-label\">Before moving to a live account<\/div>\n    <p>Check the whole workflow, not the strategy alone: free margin, automated trading permissions, the selected symbol, whether the robot is receiving quotes, and the Experts and Journal tabs. Running through that list separates a problem in the strategy from an ordinary launch error.<\/p>\n  <\/div>\n\n  <h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n  <p>Building a first expert advisor on MQL5 covers the whole development cycle in one sitting: the trading logic, the compile, the test and the launch. The EMA 9 and EMA 21 crossover is deliberately plain, which is what makes the structure underneath it visible, and that structure is the same in robots far more complex than this one.<\/p>\n\n  <p>The next step is practical. Open MetaEditor, paste in the code, compile it, run it through the Strategy Tester, then put it on a demo account and watch how it behaves without any capital at stake. After that, the working system can be refined or replaced with your own, moved onto a cent account at RoboForex with the minimum lot, and connected to a VPS for round-the-clock operation.<\/p>\n\n  <!-- TODO before publication: link \"cent account\" above once a verified URL\n       is supplied. See notes.md, open question 2. -->\n\n  <p>Keep the focus on whether the robot does what the rules say, how stable the algorithm is and how the position sizing is controlled. That is the foundation the rest of an automated trading system is built on.<\/p>\n\n  <div class=\"ea-cta\">\n    <a href=\"https:\/\/my.roboforex.com\/en\/register\/\" target=\"_blank\" rel=\"nofollow\">Open a Trading Account with RoboForex<\/a>\n  <\/div>\n\n  <h2><span class=\"ez-toc-section\" id=\"FAQ\"><\/span>FAQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n  <div class=\"ea-faq\">\n    <details class=\"ea-faq-item\">\n      <summary class=\"ea-faq-q\">Do I need programming skills to use this robot?<\/summary>\n      <div class=\"ea-faq-a\">No. Copying the code into the file the MQL Wizard creates and following the compile steps is enough to run it. Programming becomes useful once you want to change how the robot decides to trade.<\/div>\n    <\/details>\n    <details class=\"ea-faq-item\">\n      <summary class=\"ea-faq-q\">Why does the robot check for a new bar instead of trading on every tick?<\/summary>\n      <div class=\"ea-faq-a\">The strategy is defined on closed candles. Without the new bar filter, the same crossover would be evaluated hundreds of times inside one candle, and the robot would act on values that are still changing.<\/div>\n    <\/details>\n    <details class=\"ea-faq-item\">\n      <summary class=\"ea-faq-q\">Can I run it on any instrument and timeframe?<\/summary>\n      <div class=\"ea-faq-a\">Yes, the code reads the symbol and timeframe of the chart it sits on. The worked example uses GBPUSD H1. Results differ by instrument, so test in the Strategy Tester before running it anywhere new. Fixed stop levels of 200 and 400 points also behave differently on instruments with a wide spread.<\/div>\n    <\/details>\n    <details class=\"ea-faq-item\">\n      <summary class=\"ea-faq-q\">What is the difference between MetaEditor and MetaTrader 5?<\/summary>\n      <div class=\"ea-faq-a\">MetaEditor is where the code is written and compiled. MetaTrader 5 is where the compiled robot runs on a live chart. They are two parts of the same installation, and F4 switches from one to the other.<\/div>\n    <\/details>\n    <details class=\"ea-faq-item\">\n      <summary class=\"ea-faq-q\">The robot is on the chart and nothing happens. What should I check first?<\/summary>\n      <div class=\"ea-faq-a\">Check that both Algo Trading permissions are on, then read the Experts and Journal tabs in the Toolbox. Most first-launch cases are reported there in plain words, with insufficient free margin the most common one.<\/div>\n    <\/details>\n  <\/div>\n\n  <div class=\"ea-disclaimer\">\n    <em>Any information provided in articles on this website is based solely on the personal opinions of the authors. These articles should not be construed as trading recommendations or a call to action. The authors and RoboForex accept no responsibility for the results of any trades made on the basis of these recommendations and reviews. Past performance is not indicative of future results. Trading <a href=\"https:\/\/roboforex.com\/forex-trading\/assets\/stocks\/\" data-internallinksmanager029f6b8e52c=\"10\" title=\"invest in stocks\">stocks<\/a> and CFDs involves a high risk of capital loss.<\/em>\n  <\/div>\n\n<\/div>\n<\/div>\n\n\n\n<style>\n:root {\n  --green:        #5ab02b;\n  --green-hover:  #489022;\n  --green-bg:     #f0f7eb;\n  --text:         #2E3A59;\n  --text-light:   #666666;\n  --heading:      #2E3A59;\n  --dark:         #1a2535;\n  --border:       #e0e0e0;\n  --table-head:   #f5f5f5;\n  --table-stripe: #fafafa;\n  --promo-bg:     #f8f8f8;\n  --promo-border: #e8e8e8;\n  --toc-bg:       #f9f9f9;\n  --link:         #0384c6;\n  --radius:       4px;\n  --font:         'Roboto', Arial, sans-serif;\n  --max-w:        1160px;\n}\n\n\/* &#9472;&#9472; Outer wrapper &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;\n   No side padding. The theme's own container already provides it, and 20px\n   of padding here made every pasted block 1120px wide against the 1160px of\n   a text block added in the editor.\n   See docs\/decisions\/0014-wrapper-carries-no-side-padding.md *\/\n.ea-wrap { box-sizing: border-box; max-width: 1160px; margin: 0 auto; padding: 0; }\n\n\/* &#9472;&#9472; Base prose &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea {\n  font-family: var(--font);\n  font-size: 20px;\n  line-height: 1.7;\n  color: var(--text);\n  max-width: var(--max-w);\n}\n.ea.ea, .ea.ea * {\n  font-family: 'Roboto', Arial, sans-serif !important;\n}\n.ea p { margin: 0 0 20px; }\n\/* Text links: --link, never underlined, hover included. Scoped so buttons\n   keep their own colour. See docs\/decisions\/0012-text-link-colour.md *\/\n.ea p a, .ea li a, .ea figcaption a, .ea td a,\n.ea .ea-faq-a a, .ea .ea-disclaimer a {\n  color: var(--link); text-decoration: none;\n}\n.ea p a:hover, .ea li a:hover, .ea figcaption a:hover, .ea td a:hover,\n.ea .ea-faq-a a:hover, .ea .ea-disclaimer a:hover { text-decoration: none; }\n.ea strong { color: var(--heading); font-weight: 700; }\n.ea em { font-style: italic; }\n.ea code { background: var(--toc-bg); border-radius: 3px; padding: 1px 6px; font-size: 0.9em; }\n.ea ul { padding-left: 22px; margin: 0 0 18px; display: flex; flex-direction: column; gap: 6px; }\n.ea li { font-size: 20px; line-height: 1.7; color: var(--text); }\n\n\/* &#9472;&#9472; Headings &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea h2 { font-size: 32px; font-weight: 700; color: var(--heading); margin: 40px 0 16px; scroll-margin-top: 68px; }\n.ea h3 { font-size: 22px; font-weight: 700; color: var(--heading); margin: 28px 0 12px; scroll-margin-top: 68px; }\n\n\/* &#9472;&#9472; Key takeaways &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n\/* No background fill. The border alone separates the block from body text.\n   See docs\/decisions\/0013-in-brief-no-background.md *\/\n.ea-kratko { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px 0; margin: 28px 0; }\n.ea-kratko-label { font-size: 18px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-light); margin-bottom: 0; }\n.ea-kratko ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0; }\n.ea-kratko li { font-size: 16px; line-height: 1.65; color: var(--text); padding: 10px 0 10px 28px; border-bottom: 1px solid var(--border); position: relative; }\n.ea-kratko li:last-child { border-bottom: none; }\n.ea-kratko li::before { content: none !important; }\n.ea-kratko li::after { content: \"\\2713\"; position: absolute; left: 0; top: 50%; transform: translateY(-50%); color: var(--green); font-weight: 700; }\n\n\/* &#9472;&#9472; MetaEditor navigation diagram &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-nav { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); margin: 24px 0; overflow: hidden; }\n.ea-nav-item { display: flex; gap: 16px; align-items: flex-start; padding: 16px 20px; border-bottom: 1px solid var(--border); background: #fff; }\n.ea-nav-item:last-child { border-bottom: none; }\n.ea-nav-item:nth-child(even) { background: var(--table-stripe); }\n.ea-nav-num { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--green); color: #fff !important; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: center; }\n.ea-nav-title { font-size: 17px; font-weight: 700; color: var(--heading); margin-bottom: 4px; }\n.ea-nav-desc { font-size: 15px; color: var(--text-light); line-height: 1.55; }\n\n\/* &#9472;&#9472; Code block &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-code-wrap { border: 1px solid var(--border); border-radius: var(--radius); margin: 24px 0; overflow: hidden; background: #1a2535; }\n.ea-code-label { background: #0f1622; color: #9aa5b8 !important; font-size: 13px; font-weight: 700; padding: 8px 16px; font-family: 'Roboto Mono', 'Consolas', monospace !important; }\n.ea-code { margin: 0; padding: 18px 20px; overflow-x: auto; font-size: 14px; line-height: 1.6; }\n.ea-code code { background: none; padding: 0; color: #d7dde5 !important; font-family: 'Roboto Mono', 'Consolas', monospace !important; }\n\/* Short inline listings: no filename bar, tighter padding. *\/\n.ea-code-wrap.ea-code-inline { max-width: 720px; }\n.ea-code-wrap.ea-code-inline .ea-code { padding: 14px 20px; }\n@media (max-width: 600px) { .ea-code { font-size: 12px; padding: 14px 16px; } }\n\n\/* &#9472;&#9472; Images. Native WordPress block, overflow guard only. &#9472; *\/\n.wp-block-image { margin: 24px 0; }\n.wp-block-image img { max-width: 100%; height: auto; display: block; }\n.ea .wp-element-caption { font-size: 14px; color: var(--text-light); line-height: 1.5; margin: 8px 0 0; }\n\n\/* &#9472;&#9472; Callout &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-callout { background: var(--toc-bg); border-left: 3px solid var(--green); border-radius: var(--radius); padding: 18px 22px; margin: 24px 0; max-width: 900px; }\n.ea-callout-label { font-size: 15px; font-weight: 700; color: var(--heading); margin-bottom: 6px; }\n.ea-callout p { font-size: 17px; line-height: 1.6; margin: 0; color: var(--text); }\n\n\/* &#9472;&#9472; Table. Two columns cap at 720px, three columns at 900. &#9472;&#9472; *\/\n.ea-table-wrap { max-width: 720px; overflow-x: auto; margin: 24px 0; border: 1px solid var(--border); border-radius: var(--radius); }\n.ea-table-wrap.ea-table-wide { max-width: 900px; }\n.ea table.rf { width: 100%; border-collapse: collapse; font-size: 16px; margin-bottom: 0; }\n.ea table.rf thead tr { background: var(--table-head); }\n.ea table.rf th { padding: 10px 14px; text-align: left; font-size: 16px; font-weight: 700; color: var(--heading); border-bottom: 2px solid var(--border); }\n.ea table.rf td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; line-height: 1.4; color: var(--text); }\n.ea table.rf tr:last-child td { border-bottom: none; }\n.ea table.rf tr:nth-child(even) td { background: var(--table-stripe); }\n.ea-table-wrap thead th { background: var(--table-head) !important; color: var(--heading) !important; }\n\n@media (max-width: 600px) {\n  .ea table.rf thead { display: none; }\n  .ea table.rf tr { display: block; margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); }\n  .ea table.rf td { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); text-align: right; }\n  .ea table.rf td::before { content: attr(data-label); font-weight: 700; color: var(--text-light); text-align: left; }\n}\n\n\/* &#9472;&#9472; Promo &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-promo { background: var(--promo-bg); border: 1px solid var(--promo-border); border-radius: var(--radius); margin: 36px 0; padding: 24px 28px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 24px; }\n@media (max-width: 600px) { .ea-promo { grid-template-columns: 1fr; } }\n.ea-promo-title { font-size: 20px; font-weight: 700; color: var(--heading); margin-bottom: 5px; line-height: 1.3; }\n.ea-promo-sub { font-size: 15px; color: var(--text-light); line-height: 1.5; }\n.ea-promo-actions { display: flex; gap: 8px; flex-wrap: wrap; }\n.ea-promo-btn { display: inline-block; background: var(--green) !important; color: #fff !important; text-decoration: none !important; font-size: 15px; font-weight: 700; padding: 10px 15px; border-radius: 3px; white-space: nowrap; transition: background .15s; }\n.ea-promo-btn:hover { background: var(--green-hover) !important; }\n\n\/* &#9472;&#9472; Step-by-step diagram &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-steps { display: flex; flex-direction: column; gap: 12px; margin: 24px 0; }\n.ea-step { display: flex; gap: 16px; align-items: center; padding: 14px 18px; background: var(--toc-bg); border: 1px solid var(--border); border-radius: var(--radius); }\n.ea-step-num { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: #fff !important; font-weight: 700; font-size: 16px; display: flex; align-items: center; justify-content: center; }\n.ea-step-text { font-size: 17px; color: var(--text); line-height: 1.5; }\n\n\/* &#9472;&#9472; Interactive checklist &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;\n   Items are buttons, so they are keyboard reachable and carry aria-pressed.\n   The tick only appears once an item is actually checked. *\/\n.ea-checklist { display: flex; flex-direction: column; gap: 0; margin: 24px 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; max-width: 900px; }\n\n.ea-check-head { padding: 14px 20px; background: var(--promo-bg); border-bottom: 1px solid var(--border); }\n.ea-check-count { font-size: 14px; font-weight: 700; color: var(--text-light); margin-bottom: 8px; }\n.ea-check-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }\n.ea-check-bar { height: 100%; width: 0; background: var(--green); border-radius: 3px; transition: width .2s ease; }\n\n.ea-check-item {\n  position: relative; display: block; width: 100%; box-sizing: border-box;\n  text-align: left; padding: 14px 20px 14px 50px; font-size: 17px;\n  color: var(--text); line-height: 1.5; border: none;\n  border-bottom: 1px solid var(--border); background: #fff;\n  cursor: pointer; -webkit-appearance: none; appearance: none;\n  transition: background .15s;\n}\n.ea-check-item:nth-of-type(even) { background: var(--table-stripe); }\n.ea-check-item:hover { background: var(--green-bg); }\n.ea-check-item:focus-visible { outline: 2px solid var(--link); outline-offset: -2px; }\n\/* Empty box by default. The tick is drawn only on a checked item. *\/\n.ea-check-item::before {\n  content: \"\"; position: absolute; left: 18px; top: 50%;\n  transform: translateY(-50%); width: 19px; height: 19px;\n  border: 2px solid #c3c9d4; border-radius: 3px; background: #fff;\n  transition: border-color .15s, background .15s;\n}\n.ea-check-item.ea-is-done::before { border-color: var(--green); background: var(--green); }\n.ea-check-item.ea-is-done::after {\n  content: \"\\2713\"; position: absolute; left: 22.5px; top: 50%;\n  transform: translateY(-54%); color: #fff; font-weight: 700; font-size: 13px;\n}\n.ea-check-item.ea-is-done { color: var(--text-light); }\n\n.ea-check-done { display: none; padding: 14px 20px; font-size: 16px; font-weight: 700; color: #2e7d1e; background: rgba(90,176,43,0.1); border-top: 1px solid var(--border); }\n\n\/* &#9472;&#9472; Trap cards &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-traps { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 24px 0; }\n@media (max-width: 600px) { .ea-traps { grid-template-columns: 1fr; } }\n.ea-trap { border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; background: #fff; border-left: 3px solid #e6a800; }\n.ea-trap-title { font-size: 17px; font-weight: 700; color: var(--heading); margin-bottom: 6px; }\n.ea-trap-desc { font-size: 15px; color: var(--text-light); line-height: 1.55; }\n\n\/* &#9472;&#9472; Widgets, shared shell &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;\n   Single responsive layout, collapsing at 600px, instead of the\n   ea-desktop \/ ea-mobile pair. Both widgets are simple grids, and a second\n   DOM copy would duplicate every input id the scripts look up. *\/\n.ea-widget { border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; margin: 28px 0; background: #fff; max-width: 900px; }\n.ea-widget-title { font-size: 19px; font-weight: 700; color: var(--heading); margin-bottom: 6px; }\n.ea-widget-sub { font-size: 15px; color: var(--text-light); line-height: 1.55; margin-bottom: 18px; }\n@media (max-width: 600px) { .ea-widget { padding: 18px 16px; } }\n\n\/* Stat strip shared by both widgets *\/\n.ea-stat { flex: 1; min-width: 0; text-align: center; padding: 10px 8px; background: var(--table-stripe); border: 1px solid var(--border); border-radius: var(--radius); }\n.ea-stat-lbl { font-size: 12px; color: var(--text-light); line-height: 1.35; margin-bottom: 4px; }\n.ea-stat-val { font-size: 17px; font-weight: 700; color: var(--heading); word-break: break-word; }\n.ea-stat-buy { color: #2e7d1e; }\n.ea-stat-sell { color: #c0392b; }\n\n\/* &#9472;&#9472; EMA crossover visualiser &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-ema-chart { border: 1px solid var(--border); border-radius: var(--radius); background: var(--table-stripe); padding: 8px; margin-bottom: 12px; }\n.ea-ema-chart svg { display: block; width: 100%; height: auto; }\n.ea-ema-line-price { stroke: #b9c0cc; stroke-width: 1.5; }\n.ea-ema-line-fast { stroke: var(--green); stroke-width: 2.5; }\n.ea-ema-line-slow { stroke: #2E3A59; stroke-width: 2.5; }\n.ea-ema-dot { fill: #fff; stroke: #2E3A59; stroke-width: 2.5; }\n.ea-ema-cross-up { fill: rgba(90,176,43,0.25); stroke: var(--green); stroke-width: 2.5; }\n.ea-ema-cross-down { fill: rgba(192,57,43,0.2); stroke: #c0392b; stroke-width: 2.5; }\n\n.ea-ema-legend { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }\n.ea-leg { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 12px; border: 1px solid var(--border); }\n.ea-leg-fast { color: #3f7d1e; border-color: var(--green); background: rgba(90,176,43,0.1); }\n.ea-leg-slow { color: #2E3A59; border-color: #2E3A59; background: rgba(46,58,89,0.07); }\n.ea-leg-price { color: var(--text-light); }\n\n.ea-range-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-light); margin-bottom: 6px; }\n.ea-range { width: 100%; margin: 0 0 18px; accent-color: #5ab02b; }\n\n.ea-ema-stats { display: flex; gap: 10px; margin-bottom: 14px; }\n@media (max-width: 600px) { .ea-ema-stats { flex-direction: column; } }\n\n.ea-ema-verdict { font-size: 16px; line-height: 1.55; color: var(--text); padding: 14px 16px; border-radius: var(--radius); background: var(--toc-bg); border-left: 3px solid var(--border); }\n.ea-ema-verdict-buy { background: rgba(90,176,43,0.08); border-left-color: var(--green); }\n.ea-ema-verdict-sell { background: rgba(192,57,43,0.07); border-left-color: #c0392b; }\n\n\/* &#9472;&#9472; Margin calculator &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }\n@media (max-width: 600px) { .ea-calc-grid { grid-template-columns: 1fr; } }\n.ea-calc-lbl { display: block; font-size: 13px; font-weight: 600; color: var(--text-light); margin-bottom: 5px; }\n.ea-calc-in { width: 100%; box-sizing: border-box; font-size: 16px; color: var(--text); padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; font-family: 'Roboto', Arial, sans-serif; }\n.ea-calc-in:focus { outline: none; border-color: var(--green); }\n.ea-calc-out { display: flex; gap: 10px; margin-bottom: 14px; }\n@media (max-width: 600px) { .ea-calc-out { flex-direction: column; } }\n.ea-calc-verdict { font-size: 16px; line-height: 1.55; padding: 14px 16px; border-radius: var(--radius); background: var(--toc-bg); border-left: 3px solid var(--border); margin-bottom: 12px; }\n.ea-calc-ok { background: rgba(90,176,43,0.08); border-left-color: var(--green); color: var(--text); }\n.ea-calc-bad { background: rgba(192,57,43,0.07); border-left-color: #c0392b; color: var(--text); }\n.ea-calc-note { font-size: 13px; color: var(--text-light); line-height: 1.5; }\n.ea-calc-field-wide { grid-column: 1 \/ -1; }\n.ea-calc-hint { font-size: 13px; color: var(--text-light); line-height: 1.5; margin-top: 6px; }\n\n\/* &#9472;&#9472; CTA &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-cta { text-align: center; margin: 36px 0; }\n.ea-cta a { display: inline-block; background: var(--green) !important; color: #fff !important; text-decoration: none !important; font-size: 20px; font-weight: 700; padding: 13px 32px; border-radius: 3px; transition: background .15s; }\n.ea-cta a:hover { background: var(--green-hover) !important; }\n\n\/* &#9472;&#9472; FAQ &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-faq { margin: 8px 0; max-width: 900px; }\n.ea-faq details.ea-faq-item { border-bottom: 1px solid var(--border); }\n.ea-faq details.ea-faq-item:last-child { border-bottom: none; }\n.ea-faq details.ea-faq-item summary.ea-faq-q { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0; margin: 0; font-size: 18px; font-weight: 700; color: var(--heading); user-select: none; }\n.ea-faq details.ea-faq-item summary.ea-faq-q::-webkit-details-marker { display: none; }\n.ea-faq details.ea-faq-item summary.ea-faq-q::after { content: '+'; flex-shrink: 0; font-size: 22px; font-weight: 300; color: var(--green); line-height: 1; }\n.ea-faq details.ea-faq-item[open] summary.ea-faq-q::after { content: '-'; }\n.ea-faq .ea-faq-a { font-size: 18px; color: var(--text); line-height: 1.65; margin: 0 0 16px; padding: 0; animation: ea-faq-open .18s ease; }\n@keyframes ea-faq-open { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }\n@media (max-width: 600px) {\n  .ea-faq details.ea-faq-item summary.ea-faq-q { font-size: 17px; }\n  .ea-faq .ea-faq-a { font-size: 17px; }\n}\n\n\/* &#9472;&#9472; Disclaimer &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; *\/\n.ea-disclaimer { font-size: 12px; color: var(--text-light); line-height: 1.65; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }\n.ea-disclaimer em { font-style: italic; }\n<\/style>\n\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Plenty of traders never automate a strategy because building a trading robot looks like it needs a programming background. The entry barrier is lower than that. Your first MQL5 expert advisor is about a hundred lines of code, and this article hands you all of them, together with the steps that turn them into a [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":21766,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_post_was_ever_published":false},"categories":[29],"tags":[250],"class_list":["post-21765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-education","tag-trading-robot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Your First MQL5 Expert Advisor: Ready-Made Code | RoboForex Blog<\/title>\n<meta name=\"description\" content=\"A ready-made code for your first MQL5 expert advisor, explained block by block, with a step-by-step guide to compile, test and launch it in MetaTrader 5.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Your First MQL5 Expert Advisor: Ready-Made Code | RoboForex Blog\" \/>\n<meta property=\"og:description\" content=\"A ready-made code for your first MQL5 expert advisor, explained block by block, with a step-by-step guide to compile, test and launch it in MetaTrader 5.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/\" \/>\n<meta property=\"og:site_name\" content=\"RoboForex Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RoboForexOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-08T07:36:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-08T07:40:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1160\" \/>\n\t<meta property=\"og:image:height\" content=\"652\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@RoboForexGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@RoboForexGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrey Goilov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/\"},\"headline\":\"Your First MQL5 Expert Advisor: A Ready-Made Robot You Can Copy and Launch Today\",\"datePublished\":\"2026-09-08T07:36:47+00:00\",\"dateModified\":\"2026-09-08T07:40:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/\"},\"wordCount\":4001,\"publisher\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png\",\"keywords\":[\"trading robot\"],\"articleSection\":[\"Education\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/\",\"url\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/\",\"name\":\"Your First MQL5 Expert Advisor: Ready-Made Code | RoboForex Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png\",\"datePublished\":\"2026-09-08T07:36:47+00:00\",\"dateModified\":\"2026-09-08T07:40:11+00:00\",\"description\":\"A ready-made code for your first MQL5 expert advisor, explained block by block, with a step-by-step guide to compile, test and launch it in MetaTrader 5.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#primaryimage\",\"url\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png\",\"contentUrl\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png\",\"width\":1160,\"height\":652,\"caption\":\"Your First MQL5 Expert Advisor A Ready-Made Robot\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/education\\\/first-mql5-expert-advisor\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Main\",\"item\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Education\",\"item\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/category\\\/education\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Your First MQL5 Expert Advisor: A Ready-Made Robot You Can Copy and Launch Today\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/\",\"name\":\"RoboForex Blog\",\"description\":\"RoboForex Blog for Traders: Trading News, Analysis, Forecasts - Forex and Stocks\",\"publisher\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#organization\"},\"alternateName\":\"RoboForex Ltd\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#organization\",\"name\":\"RoboForex Ltd\",\"alternateName\":\"RoboForex\",\"url\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/android-chrome-512x512-1.png\",\"contentUrl\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/android-chrome-512x512-1.png\",\"width\":512,\"height\":512,\"caption\":\"RoboForex Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/roboforex.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/RoboForexOfficial\\\/\",\"https:\\\/\\\/x.com\\\/RoboForexGlobal\",\"https:\\\/\\\/www.youtube.com\\\/RoboForexOfficial\",\"https:\\\/\\\/t.me\\\/roboforex_official\",\"https:\\\/\\\/www.instagram.com\\\/roboforex\\\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Your First MQL5 Expert Advisor: Ready-Made Code | RoboForex Blog","description":"A ready-made code for your first MQL5 expert advisor, explained block by block, with a step-by-step guide to compile, test and launch it in MetaTrader 5.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/","og_locale":"en_US","og_type":"article","og_title":"Your First MQL5 Expert Advisor: Ready-Made Code | RoboForex Blog","og_description":"A ready-made code for your first MQL5 expert advisor, explained block by block, with a step-by-step guide to compile, test and launch it in MetaTrader 5.","og_url":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/","og_site_name":"RoboForex Blog","article_publisher":"https:\/\/www.facebook.com\/RoboForexOfficial\/","article_published_time":"2026-09-08T07:36:47+00:00","article_modified_time":"2026-09-08T07:40:11+00:00","og_image":[{"width":1160,"height":652,"url":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@RoboForexGlobal","twitter_site":"@RoboForexGlobal","twitter_misc":{"Written by":"Andrey Goilov","Est. reading time":"21 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#article","isPartOf":{"@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/"},"headline":"Your First MQL5 Expert Advisor: A Ready-Made Robot You Can Copy and Launch Today","datePublished":"2026-09-08T07:36:47+00:00","dateModified":"2026-09-08T07:40:11+00:00","mainEntityOfPage":{"@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/"},"wordCount":4001,"publisher":{"@id":"https:\/\/roboforex.com\/blog\/#organization"},"image":{"@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#primaryimage"},"thumbnailUrl":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png","keywords":["trading robot"],"articleSection":["Education"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/","url":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/","name":"Your First MQL5 Expert Advisor: Ready-Made Code | RoboForex Blog","isPartOf":{"@id":"https:\/\/roboforex.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#primaryimage"},"image":{"@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#primaryimage"},"thumbnailUrl":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png","datePublished":"2026-09-08T07:36:47+00:00","dateModified":"2026-09-08T07:40:11+00:00","description":"A ready-made code for your first MQL5 expert advisor, explained block by block, with a step-by-step guide to compile, test and launch it in MetaTrader 5.","breadcrumb":{"@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#primaryimage","url":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png","contentUrl":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png","width":1160,"height":652,"caption":"Your First MQL5 Expert Advisor A Ready-Made Robot"},{"@type":"BreadcrumbList","@id":"https:\/\/roboforex.com\/blog\/education\/first-mql5-expert-advisor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Main","item":"https:\/\/roboforex.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Education","item":"https:\/\/roboforex.com\/blog\/category\/education\/"},{"@type":"ListItem","position":3,"name":"Your First MQL5 Expert Advisor: A Ready-Made Robot You Can Copy and Launch Today"}]},{"@type":"WebSite","@id":"https:\/\/roboforex.com\/blog\/#website","url":"https:\/\/roboforex.com\/blog\/","name":"RoboForex Blog","description":"RoboForex Blog for Traders: Trading News, Analysis, Forecasts - Forex and Stocks","publisher":{"@id":"https:\/\/roboforex.com\/blog\/#organization"},"alternateName":"RoboForex Ltd","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/roboforex.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/roboforex.com\/blog\/#organization","name":"RoboForex Ltd","alternateName":"RoboForex","url":"https:\/\/roboforex.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/roboforex.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/06\/android-chrome-512x512-1.png","contentUrl":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/06\/android-chrome-512x512-1.png","width":512,"height":512,"caption":"RoboForex Ltd"},"image":{"@id":"https:\/\/roboforex.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RoboForexOfficial\/","https:\/\/x.com\/RoboForexGlobal","https:\/\/www.youtube.com\/RoboForexOfficial","https:\/\/t.me\/roboforex_official","https:\/\/www.instagram.com\/roboforex\/"]}]}},"jetpack_featured_media_url":"https:\/\/roboforex.com\/blog\/wp-content\/uploads\/2026\/09\/Your-First-MQL5-Expert-Advisor-A-Ready-Made-Robot.png","views":"","_links":{"self":[{"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/posts\/21765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/comments?post=21765"}],"version-history":[{"count":6,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/posts\/21765\/revisions"}],"predecessor-version":[{"id":21772,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/posts\/21765\/revisions\/21772"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/media\/21766"}],"wp:attachment":[{"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/media?parent=21765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/categories?post=21765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roboforex.com\/blog\/wp-json\/wp\/v2\/tags?post=21765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}