Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

MQTTFive — MQTT 5.0 Client Library - library for MetaTrader 5

Sergey Chekh
Sergey Chekh
👋 Hi there! I write robots, systems, and other stuff in Python and MQL5.
📊 My workday is a marathon of creating neural networks and algorithmic trading robots, which I make trade through MetaTrader. I teach them to play the market just like I taught my dog to balance a treat on his nose.
| English Русский 中文 Español Deutsch 日本語 Português 한국어 Français Italiano Türkçe
Views:
45
Rating:
(1)
Published:
\MQL5\Include\MQTTFive\
MQTTTypes.mqh (10.13 KB) view
MQTTCodec.mqh (15.02 KB) view
MQTTClient.mqh (20.94 KB) view
MQTTBuffer.mqh (4.94 KB) view
\MQL5\Scripts\
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

MQTTFive — an MQTT 5.0 client for MQL5

A library (#include) for connecting MetaTrader 5 expert advisors and scripts to MQTT brokers (Mosquitto, EMQX, HiveMQ). It allows you to publish prices and signals, receive commands from external systems and monitor the status of expert advisors.

No DLLs — pure MQL5, with its own socket API. MQTT v5.0 protocol.

Features

  • QoS 0, 1, 2 with automatic retry of undelivered messages
  • CONNECT/CONNACK properties: session duration, maximum number of packets accepted, maximum number of topic aliases.
  • Delayed publication queues
  • Topic aliases – reduces traffic on duplicate topics.
  • Flow control – quota management for the maximum volume of data received.
  • Subscription options: no_local, retain_as_published, retain_handling
  • TLS/SSL, binary payload, UTF-8


arch

Installation

  1. Copy the 5 files from the archive into the MQL5/Include/MQTTFive/ folder
  2. In the code: #include <MQTTFive/MQTTClient.mqh>

Example – publishing a price

#include <MQTTFive/MQTTClient.mqh>

void OnStart ()
  {
   MQTTClient client;
   MQTTConnectParams params;
   params.Init();
   params.client_id = "price_pub" ;

   if (client.Connect( "127.0.0.1" , 1883 , params))
     {
       double bid = SymbolInfoDouble ( _Symbol , SYMBOL_BID );
      client.Publish( "mt5/price/" + _Symbol , DoubleToString (bid, _Digits ), 0 );
      client.Disconnect();
     }
  }

Example – Subscribing to signals

MQTTClient *mqtt;

void OnSignal( string &topic, uchar &payload[], uint payload_len)
  {
   string msg = CharArrayToString (payload, 0 , ( int )payload_len, CP_UTF8 );
   Print ( "Signal: " , topic, " = " , msg);
  }

void OnStart ()
  {
   mqtt = new MQTTClient();
   mqtt.SetCallback(OnSignal);
   MQTTConnectParams params;
   params.Init();
   params.client_id = "signal_sub" ;
   mqtt.Connect( "127.0.0.1" , 1883 , params);
   mqtt.Subscribe( "trade/signal/#" , 1 );
   while (! IsStopped ())
     {
      mqtt.Loop();
       Sleep ( 100 );
     }
   mqtt.Disconnect();
   delete mqtt;
  }



Main methods

Connect(host, port, params, useTLS) Connecting to the broker
Disconnect() Properly terminating the session
ForceDisconnect() Terminate the TCP connection (triggers Will)
Publish(topic, payload, qos, retain) Publish a message
Subscribe(topic, qos) Subscribe to this topic
Unsubscribe(topic) Unsubscribe
Loop() Packet processing, connection maintenance, retries
SetCallback(func) Callback function for incoming messages

Requirements

  • MetaTrader 5 (build 3390+)
  • MQTT 5.0 broker (Mosquitto >= 5.0, EMQX, HiveMQ)

Documentation: github.com/chekh/MQTTFive

Licence: MIT

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/73373

Consecutive Bars (with history) indicator for MT5 Consecutive Bars (with history) indicator for MT5

An oscillator that shows 2 line studies: 1 for consecutive up bars, and 1 for consecutive down bars.

Multi-Timeframe Candle Map Multi-Timeframe Candle Map

An educational MT5 panel that maps the live price vertically inside four developing candles and summarizes location alignment, dispersion, candle direction and time remaining.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.