Download MetaTrader 5

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

2015.10.12 14:47
JSON Serialization and Deserialization (native MQL)

JSON Serialization and Deserialization (native MQL) - library for MetaTrader 5

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

votes: 21
jason.mqh (15.64 KB)view
jason_test.mq5 (2.24 KB)view

Serialization and deserialization of JSON protocol. The code is ported from a high-speed С++ library.

string in, out;
CJAVal js(NULL, jtUNDEF); bool b;

Print("JASon Example Deserialization:");

in="{\"a\":[1,2]}"; out=""; // example of input data
b=js.Deserialize(in); // deserialized
js.Serialize(out); // serialized again
Print(in+" -> "+out); // output for comparison

Print("JASon Example Serialization:");

js["Test"]=1.4; // input data example
out=""; js.Serialize(out); // serialized
Print(out); // output

Practical example: authorization on a website and parsing the response

CJAVal jv;
jv["login"]="Login"; // login
jv["password"]="Pass"; // password

//--- serialize to string  {"login":"Login","password":"Pass"}
char data[]; 
ArrayResize(data, StringToCharArray(jv.Serialize(), data, 0, WHOLE_ARRAY)-1);

//--- send data
char res_data[];
string res_headers=NULL;
int r=WebRequest("POST", "", "Content-Type: text/plain\r\n", 5000, data, res_data, res_headers);

//--- assume the answer {"accessToken":"ABRAKADABRA","session_id":124521}
//--- get AccessToken
string AccessToken=jv["accessToken"].ToStr();

You can show your gratitude by sending examples of implementing MQL for working with web resources. Share you experience with JSON in MQL.

Translated from Russian by MetaQuotes Software Corp.
Original code:

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

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

Average Directional Movement Index (ADX) Average Directional Movement Index (ADX)

The Average Directional Movement Index Indicator (ADX) helps to determine if there is a price trend.

Modify All TP SL Modify All TP SL

The script modifies all orders (market and pending) on the symbol with specified Take Profit and Stop Loss.

iFractals 4all TF iFractals 4all TF

Buy or sell just by looking at the "arrow" as a signal. Very easy and simple.