Discussion of article "Library for easy and quick development of MetaTrader programs (part X): Compatibility with MQL4 - Events of opening a position and activating pending orders" - page 2

 
fxsaber:

I also want to be able to run your library in Virtual. For this purpose I need to have access to MT4-style part of the library.

I managed to run it

#define  TESTER_CUSTOM // Running the Expert Advisor in the User Tester
#include <fxsaber\Tester\Tester.mqh> // https://www.mql5.com/en/code/24848

#include <IgorM\TradePanel_C#\TradePanel_C#.mqh> // https://www.mql5.com/en/code/24829

#include "TestDoEasyPart10.mq5" // https://www.mql5.com/en/articles/6767

I.e. the whole event model of the library works in virtual environment as well.

 
fxsaber:

I have sent a variant of your library, which works in MT5 via your MT4-style-logic.

The point is that cross-platform libraries have a much higher probability of working in MQL4-style part of the library than in MQL5-style. Therefore, when using cross-platform libraries, I prefer to use their MQL4-style logic in MT5. It is much more reliable in MT5.


I think that in MT5 your MQL5-style logic will take a long time to detect bugs, while MQL4-style will have bugs, but only a minimum number and not critical ones.

In this library there is no division of logic into MQL5 and MQL4. It works with the actual state and actual changes in the state of the trading environment. Purely MQL5-OnTradeXXX functions are not used - everything is taken from the state of the trading environment. That is, it is not an event-based model. That's why I say - the logic is the same, the implementations are slightly different due to the difference in the necessary functions for working with the environment.

In your library, everything is subordinated to porting MQL5-style to MQL4-style, while here - in this library - it is rather the opposite - MQL5-style (as more flexible) is ported to MQL4. Thus, the library provides a little more for MQL4 than the standard MQL4 features - for example, it has a similar PositionID for MQL4, here you can find out during the work (not when calculating history) from which order the position was generated. Unfortunately, there are no deals for MQL4 - there is no such data. Well, or I didn't think much about it....

Based on all of the above, I repeat - there is no division into two styles - it is the same for both platforms. Therefore, I do not understand your desire to convert twice to MQL4 what has already been converted.

 
Artyom Trishkin:

Based on all of the above, I repeat - there is no division into two styles - it is the same for both platforms. Therefore, I do not understand your desire to convert twice to MQL4 what has already been converted.

The misunderstanding is only in terminology. Your library for MT4 is a wrapper, which is written in MQL4. This is MT4-style. This is the part I needed. Actually, I have done it.

 
fxsaber:

The misunderstanding is only in terminology. Your MT4 library is a wrapper written in MQL4. This is MT4-style. This is the part I needed. Actually, I have done it.

Good
 

Hello Artem. I'm having trouble working with this library. I'm trying to use it in MQL4.

Yesterday I connected it to my EA in the tester and even received messages about opening or closing positions. But today I transferred what I had for the tester to a new EA, without buttons to open positions and I am trying to get a message about opening or closing positions, but I don't get it. And according to my plans I should get a ticket of position, price and time. I could not get this even in the tester.

#property strict

#include <DoEasy\Engine.mqh>
CEngine        engine;

/*******************Expert initialization function*******************/
int OnInit()
{
   EventSetMillisecondTimer(100);
   return(INIT_SUCCEEDED);
}/*******************************************************************/

/************************Expert tick function************************/
void OnTick()
{
//--- Initialisation of the last trade event
   static ENUM_TRADE_EVENT last_event=WRONG_VALUE;
//--- If working in the tester
   if(MQLInfoInteger(MQL_TESTER))
     {
      engine.OnTimer();
      //PressButtonsControl();
     }
//--- If the last trade event has changed
   if(engine.LastTradeEvent()!=last_event)
     {
      last_event=engine.LastTradeEvent();
      Comment("last_event: ",EnumToString(last_event));
      Print(__FUNCTION__, " last_event: ",EnumToString(last_event));
      engine.ResetLastTradeEvent();
      //Print("last_event: ",EnumToString(last_event));
     }

}/*******************************************************************/

/***************************Timer function***************************/
void OnTimer()
{
//--- Initialisation of the last trade event
   static ENUM_TRADE_EVENT last_event=WRONG_VALUE;
//--- If working in the tester
   if(MQLInfoInteger(MQL_TESTER))
     {
      engine.OnTimer();
      //PressButtonsControl();
     }
//--- If the last trade event has changed
   if(engine.LastTradeEvent()!=last_event)
     {
      last_event=engine.LastTradeEvent();
      Comment("last_event: ",EnumToString(last_event));
      Print(__FUNCTION__, " last_event: ",EnumToString(last_event));
      engine.ResetLastTradeEvent();
      //Print("last_event: ",EnumToString(last_event));
     }
}/*******************************************************************/

void OnDeinit(const int reason)
{
 EventKillTimer();
 Comment("");
}/*******************************************************************/
Files:
00.mq4  5 kb
 

And the most baffling thing is, I've now put my probe with buttons on the chart..... No messages come through. Put it back in the tester, everything works.


ps; I figured it out. It is necessary to enable OnChartEvent with custom event.

 
Alexey Viktorov:
And the most baffling thing is, I've now put my button probe on the chart..... No messages come through. I put it back in the tester, everything works.
Remove all references to the timer from the EA - the library creates its own timer for it and works in it. Everything is done for simplicity and convenience.
 
Artyom Trishkin:
Remove all references to the timer from the EA - the library creates its own timer for it and works in it. Everything is done for simplicity and convenience.

Removed the timer, inserted OnChartEvent in this form. Button control is probably not needed, and the user event I think is created somewhere in the wilds of the library. But I didn't get the result.

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   //if(MQLInfoInteger(MQL_TESTER))
   // return;
   //if(id==CHARTEVENT_OBJECT_CLICK && StringFind(sparam, "BUTT_")>0)
   // {
   // PressButtonEvents(sparam);
   // }
   if(id>=CHARTEVENT_CUSTOM)
     {
      ushort event=ushort(id-CHARTEVENT_CUSTOM);
      Print(DFUN,"id=",id,", event=",EnumToString((ENUM_TRADE_EVENT)event),", lparam=",lparam,", dparam=",DoubleToString(dparam,Digits()),", sparam=",sparam);
     } 
  }
 
Alexey Viktorov:

I removed the timer and inserted OnChartEvent in this form. Button control is probably not needed, and the custom event I think is created somewhere in the wilds of the library. But I didn't get the result.

I will make an example later.
 

Artem, please tell me what role the highlighted code section plays

#property strict

#include <DoEasy\Engine.mqh>
CEngine        engine;

/*******************Expert initialization function*******************/
int OnInit()
{
   //EventSetMillisecondTimer(100);
   return(INIT_SUCCEEDED);
}/*******************************************************************/

/************************Expert tick function************************/
void OnTick()
{
//--- Initialisation of the last trade event
   static ENUM_TRADE_EVENT last_event=WRONG_VALUE;
//--- If working in the tester
   if(MQLInfoInteger(MQL_TESTER))
     {
      engine.OnTimer();
     }
//--- If the last trade event has changed
   if(engine.LastTradeEvent()!=last_event)
     {
      last_event=engine.LastTradeEvent();
      Comment("last_event: ",EnumToString(last_event));
      Print(__FUNCTION__, " last_event: ",EnumToString(last_event));
      //engine.ResetLastTradeEvent();
      //Print("last_event: ",EnumToString(last_event));
     }

}/*******************************************************************/

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id>=CHARTEVENT_CUSTOM)
     {
      ushort event=ushort(id-CHARTEVENT_CUSTOM);
      Print(DFUN,"id=",id,", event=",EnumToString((ENUM_TRADE_EVENT)event),", lparam=",lparam,", dparam=",DoubleToString(dparam,Digits()),", sparam=",sparam);
     } 
  }

/***************************Timer function***************************/
void OnTimer()
{
//--- Initialisation of the last trade event
   static ENUM_TRADE_EVENT last_event=WRONG_VALUE;
//--- If working in the tester
   if(!MQLInfoInteger(MQL_TESTER))
     {
      engine.OnTimer();
     }
}/*******************************************************************/

void OnDeinit(const int reason)
{
 //EventKillTimer();
 Comment("");
}/*******************************************************************/

How can this code be executed if the timer is not enabled?

But if this code section is deleted, the event messages are not printed. But everything works with it.

And I would like to get a ticket, prices and possibly some other properties of positions and orders together with the event message.