RAD - Rapid Application Development Library - MetaTrader 4 Library | Forex Indicator Downloads - MT4/MT5 Resources
The library contains a large number of functions that speed up development in MQL4 by avoiding interference with the mechanics and allowing you to focus on logic. For example, to open an order for 0.4 lots, just call the Open Buy(0.4); function. Of course, such functions have multiple parameters, with other parameters set to their default values. It can also be filled if necessary.
The library features RAD_onTick() , RAD_onInit() , RAD_onDeinit() handlers. They must be called in the expert or indicator in the corresponding function and should be placed at the beginning of it. It also has configuration capabilities for default values, for example, setting magic numbers with RAD_setMagic(...), symbols with RAD_setSymbol(...) and slippage with RAD_setSlippage(...) . It also includes extended functionality for working with strings, arrays, and other mathematical operations. This RAD_DEBUGENABLE() is activated to debug the application. Inserting the RAD_DEBUG_ASSERT(...) code section will print the specified line to the console, inserting the RAD_DEBUG_SECTION{....} will run the code in the brackets when debug mode is active and logging is enabled ( RAD_LogEnabled() ). When enabled, it will output to the log file. Descriptions of the remaining numerous functions can be found in the file itself.
The following is a code example of an abstract Expert Advisor:
//+------------------------------------------------------------------+ //|Project name| //| Copyright 2012, Company Name | //| http://www.companyname.net | //+------------------------------------------------------------------+ #Property Copyright "Copyright 2016, MetaQuotes Software Corp." #Property association "https://www.mql5.com" # Property version "1.00" #propertystrict #includeEnter the integer magic = 2143658709 ; Enter the integer fast period = 14 ; Enter the integer slow period = 20 ; Enter the double risk = 10 ; Enter the integer stop loss = 60 ; Enter the integer stop profit = 30 ; //====================================================== Integer initialization () { RAD_onInit(); //Initialize the library RAD_set program name ( "Mashkar Expert" ); //Set the expert name RAD_setLogName(RAD_ProgramName()+ "_logger.log" ); //Specify the file name for recording RAD_setEquityBreakdown( 40 ); //Set the retracement level allowed for equity. Check every time it is checked RAD_setMagic(magic); //Set the standard value of the magic number RAD_DebugEnable(); //Enable debug mode RAD_LogEnable(); //Start recording and return ( initialization successful ); } //====================================================== Blank solution initialization ( constant integer reason) { RAD_onDeinit(); //The handler for this event is empty so far, but let it stay there for future use } //==================================================== Blank check () { RAD_onTick(); //Process library internal affairs //New bar arrives if (isNewBar()) { double fast = imma ( void , 0 , fast period, 0 , mode_EMA , PRICE_CLOSE , 0 ); // fast moving average double slow = imma ( void , 0 , slow period, 0 , mode_EMA , PRICE_CLOSE , 0 ); // slow moving average double a lot = LotOnRisk(risk); RAD_ASSERT( 0 , "Quickly:" +Fast+ "Slowly:" +Slowly+ "A lot:" +A lot); //The opening condition is buy, otherwise it is sell if (fast > slow) { RAD_ASSERT( 1 , "Open buy order" ); If (CountOrders(omBuy|omPoolTrades)== 0 ) //Check whether the buy order has been opened OpenBuy(lot, stop loss, take profit); //Open the buy order } Other { RAD_ASSERT( 2 , "Open sell order" ); if (CountOrders(omSell|omPoolTrades)== 0 )n class="comment">//Check whether the sell order has been opened OpenSell (lot size, stop loss, take profit); //Open a sell order } } } //+----------------------------------------------------------------------------------+
Of course, such an EA will not bring profits, because we all know this MA-based strategy :)
This is just an example of the code. It shows that the library does not require value checks, no need to calculate stops, no need to write 100x nested order checks, all of this has been written for you in the library. Another code example for processing orders:
CountOrders(omBuy | omPoolTrades) //Returns the number of buy orders in the trading pool with any magic number and symbolCountOrders(omSells | omPoolHistory, 123 , "EUR/USD" ) //Returns the number of SELL, SELL_STOP, and SELL_LIMIT type orders in the historical pool with the magic number equal to 123 and the symbol equal to EURUSD
CountOrders(omBuy | omBuyStop | omPoolTrades, 123 ) //Return the magic number equal to 123 and the number of BUY and BUY_STOP orders for any trading variety in the trading pool
Close order (omBuys) //Close all BUY, BUY_STOP, BUY_LIMIT orders with any magic number and symbol and return their quantityClose Order(omAll) //Close all orders of all types available on the account //Check whether the order in the trading pool is of buy or sell type, 123 magic number and EURUSD symbol if (isOrderFilter(bills, omActive | omPoolTrades, 123 , "EUR/USD" )) //Check whether the order in any pool is of buy type, 123 magic number and any symbol if (isOrderFilter(ticket, omBuy | omPoolAll, 123 , invalid ))
The code looks simple while being functional and versatile.
Array expansion work. Now you don't have to rewrite the code to add elements to the array, now it's enough to call something like:
integer a[]; arrayadd(a, 12 ); arrayadd(a, 24 ); arrayadd(a, 55 ); Array addition (a, 75 ); //The array will be displayed as [12,24,55,75]
Removing elements from an array is also simple:
Array Del(a, 2 ); //Delete the third element in the array, the result is [12, 24,75]
Or like this:
Array Del(a, 1 , 3 ); //Delete three elements starting from position 1. The result is [12]
This is achieved using function templates with transfer by value and transfer by link options
If you need to download a page from the Internet, simply call:
string page; integer size; Size = download page ( "http://www.google.com" , pages, 2 , 5 ); //Download the Google page, try 2 times and fail, delay 5 seconds
The same goes for files, except that the second parameter is the file name.
Mathematical instruments have also been expanded. Searching for the maximum value from multiple values no longer looks like a bunch of nested MathMax(MathMax(MathMax...))). It now has up to 5 parameters implemented using function templates and can now be called as:
Double the maximum; max = mathmax ( 12.4 , 55.432 , 128electron - 4 , 8003.44 );
Generate random numbers in the range -34000 to 125000 as follows:
double random; Random = MathRandomDouble( -34000.0 , 125000.0 ); //Generate random numbers from -34000 to 125000 Random = MathDiscrete(random, 100.0 ); //You can add a random number sample of 100 if needed
But then, the code is open. View, add to, suggest ideas about the structure of the library or its functionality, and general comments.
Attachment download
📎 rad_lib.mqh (85.36 KB)
Source: MQL5 #15945
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •