sToken - MetaTrader 5 library | Trading script download - MT4/MT5 resources - MetaTrader 5 resources


The script contains a class that can be used to solve mathematical and logical expressions defined as strings.
The script has two classes: cTokenBase and cToken (a member of CTokenBase). The cTokenBase class must be configured before use (see below).
The following MQL5 mathematical functions are supported: abs , arcos , arcsine , arctangent , ceiling , ince , exp , ground , log , log10 , max , min , mod , pow, rand , circular , sin , square root , tan .
Logical and mathematical operations: /, %, *, +, -, >, <, >=, <=, ==, !=, &&, ||.
Expressions can contain numbers, including doubles, user variables, and user arrays. If you will be using the user's variables and arrays, you will need to add functions that return the values of these variables and arrays. Functions should be added to the cTokenBase class.
User variables and arrays are named with letters (case is not important), and array elements are defined as follows: e[0], e[1], f[0], f[1].


How to configure the cTokenBase class
blankUserVariable () { User variable = "a; b; c; d" ; // User variable list User array = "e; f" ; // User array list }
2. You need to add the corresponding function call in the UserFunc(string FuncName) function:
String user function ( string function name) { if (function name == "a" ) return (a()); If (function name == "b" ) return (b()); If (function name == "c" ) return (c()); If (function name == "d" ) return (d()); alert ( "function is" + function name + "variable is not defined" ); return ( "0" ); }
3. Add functions for all user variables:
One string () { return ( "1" ); } String b() { return ( "2" ); } String c() { return ( "3" ); } String d() { return ( "4" ); }
4. Add a call to the corresponding function (depending on ArrName) in the UserArray(string ArrName,int aIndex) function. The index of the array element is specified in the aIndex variable.
StringUsersArray ( StringDestinationName , Integer Index) { if (address name == "e" ) return (e(aIndex)); if (address name == "f" ) return (f(aIndex)); alert ( "function is" +reachname+ "array is not defined" ); return ( "0" ); }
5. Add functions to each array:
String e ( integer exponent) { String v[]={ “1” , “2” , “3” , “4” , “5” , “6” , “7” , “8” , “9” }; return (v[index]); } string f ( integer exponent) { String v[]={ “10” , “20” , “30” , “40” , “50” , “60” , “70” , “80” , “90” }; return (v[index]); }
Class usage
1. Declare an external input variable for the expression:
Enter string expression = "Enter expression here" ;
2. Delete the cToken class variable at the global level:
cToken token;
3. Initialize the class using an expression.
token.Init(expression);
4. Call the SolveExpression() method
Double value=token.SolveExpression(); This class can be used to solve multiple expressions using just a few instances of the cToken class:
cToken token 1; cToken token 2; cToken token 3; cToken token 4;
In this case all class instances will use the same user variables and arrays (declared in the cTokenBase class)
You can add your features.
Add new functions to cToken class
Attachment download
📎 token.mq5 (22.71 KB)
Source: MQL5 #303
sToken - MetaTrader 5 library | Trading script download - MT4/MT5 resource usage and screening suggestions
sToken - MetaTrader 5 library | Trading script download - MT4/MT5 resources are trading script related resources. Before downloading or referencing, it is recommended to confirm the platform version, transaction type, time period, whether DLL is required, whether source code is included, parameter description and historical update records.
Both automated trading tools and foreign exchange indicators should first undergo backtesting, simulated account observation, and small capital verification. Pay special attention to spreads, slippages, maximum drawdowns, position opening frequency, stop loss methods, trading periods and broker rules, and avoid direct real-time execution based only on titles or short-term profit descriptions.
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •