Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal


XML parser - library for MetaTrader 5

yu-sha | English Русский 中文 Español Deutsch 日本語 Português

votes: 24
2011.11.29 13:46
2016.11.22 07:32
xmlbase.mqh (0.56 KB)view
xmldocument.mqh (11.89 KB)view
xmlelement.mqh (18.89 KB)view
xml_test.mq5 (1.39 KB)view

A library for parsing of XML documents. Pure MQL5, it doesn't uses any external libraries.

To use the library, just include it:

#include <Xml\XmlBase.mqh>


#include <Xml\XmlBase.mqh>

CXmlDocument doc;

void OnStart() 
  string file = "File.xml";
  string err;
  if (doc.CreateFromText(file,err))
    CXmlElement * xmlItem = doc.FDocumentElement.GetChild(0);
    for (int i=0; i<xmlItem.GetChildCount(); i++) 
    if (xmlItem.GetChild(i).GetName() == "LAYER")
      CXmlElement* layer = xmlItem.GetChild(i);
      for (int j=0; j<layer.GetChildCount(); ++j) 
        if (layer.GetChild(j).GetName() == "NEURON")
           /* .... */


  • The library was written when constuctors in MQL5 were without parameters;
  • Only basic functions of Xml standard is supported;
  • Plese inform me about errors, suggestions and bug fixes.

Main components:

CXmlDocument class provides methods for downloading of XML documents from file/string and save to file.

CreateX functions parses XML documents and create hierarchy of DOM model, the working with it can be done using FDocumentElement 

class CXmlDocument 

    void DoElementTrimText(CXmlElement &aXmlItem) ;
    CXmlElement FDocumentElement;

    void CXmlDocument ();
    void ~CXmlDocument ();
    void Clear();
    void CopyTo (CXmlDocument &xmlDoc);
    bool  CreateFromText (const string& xml, string& err);
    bool  CreateFromFile (const string filename, string& err);
    bool  SaveToFile (const string filename);

    string GetXml();


CXmlElement class is a base interface of any XML document. It provides access to elements, attributes and content

class CXmlElement 
    string         FName;
    CXmlAttribute* FAttributes[];
    CXmlElement   *FElements[];
    string         FText;
    CXmlElement*   FParent;
    //--- constructor methods
    void  CXmlElement ();
    void ~CXmlElement ();
    void Init (const string aName, const CXmlElement* aParent=NULL, const string aText="");
    void CopyTo (CXmlElement &aDst);
    virtual void Clear ();
    //--- main service methods
    string GetName () const;
    void SetName (const string aName);
    string GetText () const;
    void SetText (const string aText);
    CXmlElement* GetParent () const;
    void SetParent (CXmlElement* aParent);
    //--- attribute service methods
    int GetAttributeCount () const;
    int GetAttributeIndex (CXmlAttribute* aAttr) const;
    CXmlAttribute* GetAttribute (const string aName) const;
    CXmlAttribute* GetAttribute (int aPos) const;
    string GetAttributeValue (const string aName) const;
    CXmlAttribute* AttributeInsertAt (CXmlAttribute* aAttr, int aPos);
    CXmlAttribute* AttributeAdd (CXmlAttribute* aAttr);
    CXmlAttribute* AttributeInsertAfter (CXmlAttribute* aAfter, CXmlAttribute* aAttr);
    CXmlAttribute* AttributeInsertBefore (CXmlAttribute* aBefore, CXmlAttribute* aAttr);
    CXmlAttribute* AttributeRemove (CXmlAttribute* aAttr);
    CXmlAttribute* AttributeRemove (int aPos);
    void AttributeDelete (CXmlAttribute* aAttr);
    void AttributeDelete (int aPos);
    void AttributeDeleteAll ();
    //--- child service methods
    int GetChildCount() const;
    int GetChildIndex (CXmlElement* aElement) const;
    CXmlElement* GetChild (const string aName) const;
    CXmlElement* GetChild (int aPos) const;
    string GetChildText (const string aName) const;

    CXmlElement* ChildInsertAt (CXmlElement* aElement, int aPos);
    CXmlElement* ChildAdd (CXmlElement* aElement);
    CXmlElement* ChildInsertAfter (CXmlElement* aAfter, CXmlElement* aElement);
    CXmlElement* ChildInsertBefore (CXmlElement* aBefore, CXmlElement* aElement);
    CXmlElement* ChildRemove (CXmlElement* aElement);
    CXmlElement* ChildRemove (int aPos);
    void ChildDelete (CXmlElement* aElement);
    void ChildDelete (int aPos);
    void ChildDeleteAll ();
    string GetXml(int aLevel);


CXmlAttribute is a simple class for working with attributes

class CXmlAttribute 
    string FName;
    string FValue;
    //--- constructor methods
    void CXmlAttribute ();
    void ~CXmlAttribute ();

    void Init (const string aName, const string aValue);
    virtual void Clear ();
    virtual CXmlAttribute* Clone ();
    //--- service methods
    string GetName () const;
    void SetName (const string aName);
    string GetValue () const;
    void SetValue (const string aValue);    

Translated from Russian by MetaQuotes Software Corp.
Original code:

Candles Smoothed HTF Candles Smoothed HTF

The indicator that displays "averaged" candlesticks of a larger timeframe at a smaller one.

Magnified Market Price Magnified Market Price

The indicator shows the current price in one of the chart corners.

Three-Pole Super Smoother Filter Three-Pole Super Smoother Filter

Three-pole super smoother filter from John Ehlers' book "Cybernetic Analysis for Stocks and Futures: Cutting-Edge DSP Technology to Improve Your Trading" is used in this indicator for moving average calculation.

JFatlSpeed HTF JFatlSpeed HTF

This indicator shows the direction of the acceleration of JFatlSpeed price from a larger timeframe at a smaller one.