Object Simulator - MetaTrader 5 Library | Forex Indicator Downloads - MT4/MT5 Resources - MetaTrader 5 Resources
MetaTrader 4 allows the use of objects from Expert Advisor during testing. The chart containing the objects will open at the end of the test. Arrows make it convenient to observe where the Expert Advisor can perform operations, but this case does not allow this. There are many usage examples.
Compared to the MetaTrader 4 version, we cannot use test objects in MetaTrader 5. This situation is not for me! Okay, let's fix that.
Expert Advisors are now created without using objects in MetaTrader 5. The object simulator allows getting data from objects, but I don't recommend it, since the testing process can sometimes be slow and there are some differences from the official functionality.
Only use the object simulator to display the objects in the post-test diagram.
Add the ObjectEmul_indicator indicator to the tester.tpl tester template.
For those who don't know how to do it:
The "Open Chart" button on the "Settings" tab has been removed in the MetaTrader 5 Strategy Tester. If the Expert Advisor under test does not perform trading operations, the chart will not be automatically displayed. You have to switch to "Backtesting", right click and select "Open Chart".
Add to the main file of the Expert Advisor:
#include CObjectEmul_objs;And change the Object of the standard function to _objs.Objct.
To run help through an object function in the editor, you simply add the letters " e " to "Obj" and press F1.
//+------------------------------------------------------------------+ //| Example of using the object simulator | //+------------------------------------------------------------------+ #includeCObjectEmul _objs; integer zigzag; datetime last column = 0 ; double triangle price[ 3 ]; datetime triangletime[ 3 ]; integer triangle index = 0 ; integer initialize () { ZigZag = custom ( _symbol , _period , "example\\ZigZag" , 5 , 5 , 3 ); math rand ( getNumber of ticks ()); return ( 0 ); } Blank check () { datetimetime []; copyTime ( _symbol , _period , 0 , 15 , time); if (last column == time [ 0 ]) return ; Last bar = time[ 0 ]; Double zgbuffer[]; if ( CopyBuffer (ZigZag, 0 , 0 , 15 ,zgBuffer) == 0 ) { print ( "CopyBuffer(ZigZag) Error" ); return ; } boolean first= true ; for ( integer x = 0 , count = array size (zgbuffer); x < count && triangle index < 3 ; x++) { // Something wrong here, but I like the result :) if (zgbuffer[x]> 0 && first) { first = wrong ; x+= 3 ;} Else if (zgbuffer[x]> 0 && (triangle index == 0 || triangle price [triangle index - 1 ]!=zgbuffer[x])) { trianglePrice[triangleIndex]=zgbuffer[x]; triangleTime[triangleIndex]=time[x]; triangleIndex++; rest ; } Else if (zgbuffer[x]> 0 ) rest ; } if (triangle index < 3 ) return ; String object name = "Object simulation_demo_" + ( string ) ( integer ) last column; ////////////////////////////////////////////////////// //Object simulator // Standard object*() analog if (_objs.ObjctCreate( 0 , object name, OBJ_TRIANGLE , 0 , triangle time [ 0 ], triangle price [ 0 ], triangle time [ 1 ], triangle price [ 1 ])) { _objs.ObjctSetInteger( 0 , object name, OBJPROP_TIME , 2 , triangle time [ 2 ]); _objs.ObjctSetDouble( 0 , object name, OBJPROP_PRICE , 2 , triangle price [ 2 ]); _objs.ObjctSetInteger( 0 , object name, OBJPROP_COLOR , ( mathematical rand ()% 255 )*( mathematical rand ()% 255 )*( mathematical rand ()% 255 )); ">// Index usage example integer index = _objs.ObjctFindIndex( 0 , object name); if (index >- 1 ) _objs.ObjctSetIntegerIndex(index, OBJPROP_FILL , 0 , true ); } Other print ( "Object creation error" ); // Object Simulation ////////////////////////////////////////////////////// Triangle Price[ 0 ]=Triangle Price[ 1 ]; Triangle Time[ 0 ]= Triangle Time[ 1 ]; Triangle Price[ 1 ]= Triangle Price[ 2 ]; Triangle Time[ 1 ]= Triangle Time[ 2 ]; Triangle Index= 2 ; }
variable
All graphics Object*() objects implement , but have Object*() names. But there is nothing like TextSetFont() , TextOutput() and TextGetSize() .
There are also object*index() functions that speed up work:
To avoid overloading ambiguity, I have to choose separate functions for indexing. These functions do not call ObjctFindIndex() to search and you must control the objects to use them !
Object Set Integer ( 0 , "Object Name" ) , OBJPROP_STYLE , Style_DASH ) == ObjctSetIntegerIndex(ObjctFindIndex( 0 , "Object Name" ), OBJPROP_STYLE , Style_DASH );
The LoadFile() function uses these functions, but the Count() function displays the count of all objects.
Of course there are things that should be addressed during implementation, but I need to find any resolution. Of course I will try to update this library and hope to get help from the community.
Attachment download
📎 objectemul_indicator.mq5 (0.92 KB)
📎 objectemul_script.mq5 (0.26 KB)
📎 objectemul_unittest_script.mq5 (11.99 KB)
📎 objectemul.mqh (34.25 KB)
Source: MQL5 #1583
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •