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
Views:
54
Rating:
(1)
Published:
\MQL5\Include\
JAson.mqh (30.59 KB) view
fast_json.mqh (39.86 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

High-Performance JSON (v3.5.0)

A JSON library designed for LLMs, Autonomous Trading and Ultra-Low Latency.

The Problem

When integrating AI models (GPT-4o, Claude 3.5, DeepSeek) into MetaTrader 5, the community's standard libraries failed on two critical points: Memory Allocation and Serialisation Latency. The excessive use of recursion and temporary strings turned the processing of AI responses (Function Calling) into bottlenecks that froze the terminal. The "pain" of losing ticks while the Garbage Collector cleared strings was what motivated this architecture.

fast_json architecture

Rewritten from scratch with an obsessive focus on performance:

  1. Zero-Allocation Architecture: Parsing via Tape (contiguous buffer long[] ) and Direct Serialisation in buffer uchar[] . We eliminate intermediaries: the payload goes from the socket straight to the data structure without creating thousands of objects.
  2. Hybrid Numeric Parsing: In v3.4.0, we introduced integer accumulation via long (native ALU) and static Exp10 lookup tables for maximum precision in floating-points.
  3. Iterative State Machine: Goodbye recursion. A linear parser prevents Stack Overflow even in deeply nested JSONs.
  4. SWAR Scanning: SIMD reading (8 bytes per cycle) to skip whitespace and long strings.

Performance

Tests carried out on standard hardware (x64) with a complex payload of 50,000 nodes:

Operation (fast_json) Legacy Lib (JAson) Advantage
Parse 137 ms 1540 ms 11.2x faster
Serialisation 264 ms 568 ms 2.1x faster
Total (Roundtrip) 401 ms 2129 ms 5.3x faster

> Results verifiable via TestJsonBenchmark.mq5 script included in the package.

Benchmark



Key Features

  • HFT resilience: Deterministic memory allocation. Garbage Collector does not intervene during parse.
  • O(1) Introspection: Check HasKey() keys or Size() arrays instantly, without linear scanning.
  • Type Safety: Strict type access ( GetInt , GetDouble , GetString ). No magic variants that cause silent bugs.
  • Accurate Error Reporting: In case of failure, returns exact Row and Column.

Usage Example: Reading OpenAI Response

#include <fast_json.mqh>

void OnStart() {
    string payload = GetOpenAIResponse(); // JSON massivo
    
    CJson json;
    if(json.Parse(payload)) {
        // Acesso direto performance-critical (Zero-Copy)
        string content = json["choices"][0]["message"]["content"].ToString();
        
        // Exemplo: Extraindo uso de tokens
        if(json.HasKey("usage")) {
            long tokens = json["usage"]["total_tokens"].ToInt();
            Print("Consumo: ", tokens);
        }
    } else {
        // Debug preciso
        int l, c;
        json.GetErrorPos(l, c);
        PrintFormat("Erro JSON na Linha %d, Coluna %d", l, c);
    }
}

Example: Building Request (Optimised Builder)

CJsonBuilder b;
b.Obj()
    .Key("model").Val("gpt-4-turbo")
    .Key("messages").Arr()
        .Obj()
            .Key("role").Val("user")
            .Key("content").Val("Analyze EURUSD H1 trend")
        .EndObj()
    .EndArr()
    .Key("temperature").Val(0.7)
.EndObj();

string body = b.Serialization(); // Serialização ultra-rápida

Developed by Jonathan Pereira as the core infrastructure of the AI-Toolkit framework.

Translated from Portuguese by MetaQuotes Ltd.
Original code: https://www.mql5.com/pt/code/68596

VR Rsi Robot is a multi-timeframe trading strategy VR Rsi Robot is a multi-timeframe trading strategy

Just two timeframes — H1 and D1 — work synchronously to filter out the noise and capture only strong RSI reversals from overbought and oversold zones. No random entries, only a clear confirmation of the direction from the "big brother."

ExMachina SupplyDemand Indicator ExMachina SupplyDemand Indicator

ExMachina Supply & Demand Zones is a professional indicator that automatically detects supply and demand zones on any chart using impulse-based detection with ATR filtering. Version 2.0 introduces multi-candle impulse detection, full range measurement, zone merging, touch tracking, proximity alerts, and an ExMachina dark theme that transforms your chart into a professional trading workspace.

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.