Robot catalog

The fundamentals of the ASCII table implementation in MQL4

Wednesday, 14 February 2018 01:00
The fundamentals of the ASCII table implementation in MQL4

ASCII or American Standard Code for Information Interchange is a symbol table that contains codes for each letter of the alphabet, decimal digits, punctuation marks and control characters. It was created in 1963 to standardize the encoding of the main characters used to extract textual information on the computer and other communication devices.

The ASCII column is used in various programming languages, but it is not yet implemented in MQL4. However, there is a way out. You can write a similar library for MetaTrader 4 using string variables.

What are string variables?

String variables or variables of the String type are a kind of data that represents an arbitrary sequence of characters (a string). Simply, there are simple words and sentences, but for the computer they are nothing more than a set of characters. That is a reason why the string variables are enclosed in quotation marks. In this case, it is not necessary to use only letters or numbers. If you want to add a special character to the string, just put "\" before it.

In the computer memory, string characters are stored in an array in a certain sequence. The numbering of lines starts from zero, and the symbol NULL is putted at the end of each of them. In the ASCII table, this symbol corresponds to the number "0". The number of characters per line is limited. In MQL4, the string size can be up to 255 characters. Each line of code containing string variables is identified by the keyword "string".

pict 1

In order to implement the ASCII table in MQL4, you need to determine which string variables we will use. In this case, we have three ones:

pict 2

  • s1 - the string whose value will be processed;
  • s2 - the line in which the result of calculations will be displayed;
  • symbol - a string for temporary storage of characters.

Functions for working with string variables

Special MQL4 functions are used to allow you to implement the capabilities of the ASCII table in MetaTrader 4, which makes possible to work with string variables.

  • StringConcatenate () - creates a string from the available parameters, and then returns it.
  • StringUpperCase () and StringLowerCase () - convert strings to uppercase or lowercase.
  • StringSetChar () and StringGetChar () - prints the character corresponding to the code at the specified position of the string.
  • StringLen () - specifies the number of characters in a string.
  • StringSubstr () - extracts a substring and prints a copy of it if possible. Otherwise displays an empty string.
  • StringIsDigit () - identifies the contents of the string. If the string contains only digits, the function returns true, otherwise false.
  • StringIsAlpha () - acts similarly to StringIsDigit (), only the verification object is not numbers, but letters.
  • StringCompare () - compares two different strings, not case sensitive.

While applying some of these functions, we get a script that first outputs a string with incoming parameters, and then its processed copy, where each character separates the space.

pict 3

In this case, we used the loop: for (int x = 0; x <leight; x ++), during which we will perform the character-by-character processing of each row starting with zero.

Code determining script for each ASCII character will look like this:

pict 4

String functions are widely used to build a library and implement the capabilities of the ASCII table. For example, you can develop a reporting system for a sales advisor or systematize the results of trading for a certain period with the help of this tool. The ASCII table aren’t useful directly for trading, but scripts based on it are often used as an auxiliary tool for analysis.

Rate this article:
5 of 5 based on 1 rates
Ami	Phelps
Ami Phelps

Business analyst. I cooperate with private investors and write analytical rewievs. My specialization is indices chart with the basic technical tools

Share