Features of the mql5 language, subtleties and tricks - page 294

 
fxsaber #:

  1. An indication of an error.
  2. Example of use.

Readers are kindly requested to comment.

After considering your suggestion about usage scenarios, I modified the function as follows 

void PrintDeal(ulong deal_ticket, bool already_selected = false)
  {
   if(already_selected || HistoryDealSelect(deal_ticket))
     {
      PROPERTIES2(HistoryDealGetInteger, deal_ticket, ENUM_DEAL_PROPERTY_INTEGER);
      PROPERTIES2(HistoryDealGetDouble, deal_ticket, ENUM_DEAL_PROPERTY_DOUBLE);
      PROPERTIES2(HistoryDealGetString, deal_ticket, ENUM_DEAL_PROPERTY_STRING);
     }
  }

Then in the aforementioned loop you could use PrintDeal(Ticket, true)


Edit:

I am suggesting to add a new function to the above collection: PrintObject(string obj_name) 
 
fxsaber #:

An example of viciousness.

Shake but do not mix.

You mixed it.

That's not a goodexample.

But it's a good example of how to learn that you can't do that.)

 
We are trying to refine the cocktail 🍸 
 
amrali #:

Then you can use PrintDeal(Ticket, true) in the above loop

Why not?

Forum on trading, automated trading systems and testing trading strategies

Peculiarities of mql5 language, subtleties and techniques of work

fxsaber, 2025.02.13 14:35

if (HistoryDealGetInteger(Ticket, DEAL_TICKET) != Ticket)
  HistoryDealSelect(Ticket);
 
Aleksandr Slavskii #:

you can't do that.)

Didn't even realise this suggestion was controversial.

Forum on trading, automated trading systems and testing trading strategies

Peculiarities of mql5 language, subtleties and techniques of work

fxsaber, 2025.02.13 10:23 AM

Placing a trade in the available history table and printing out the properties of the trade are functionalities that do not overlap.

To line is just to line, without any checks and preparations.


By the way, I don't understand why you need to create a function for printing, when the inline function is much more useful....

For example, in MT4 I don't understand OrderPrint when OrderToString is logical. I.e. instead of one step two steps are imposed.
 

Updated functions (useful for code debugging):

Helper macros:

//+------------------------------------------------------------------+
//| Helper macros to print a lot of information from the terminal.   |
//+------------------------------------------------------------------+
#define Param(p1)     p1,
#define Params(p1,p2) p1,p2,

#define PROPERTIES(function, params, enumtype) \
   for(int i=-2; i<USHORT_MAX+1000; ++i) \
     { \
      enumtype prop_id = (enumtype)i; \
      if(StringFind(EnumToString(prop_id),"::")<0) \
         Print(EnumToString(prop_id),"=",function(params##prop_id)); \
     }

Account and terminal info:

//+------------------------------------------------------------------+
//| Prints the account specification to the Experts tab.             |
//+------------------------------------------------------------------+
void PrintAccount()
  {
   if(AccountInfoInteger(ACCOUNT_LOGIN))
     {
      PROPERTIES(AccountInfoInteger,"",ENUM_ACCOUNT_INFO_INTEGER);
      PROPERTIES(AccountInfoDouble,"",ENUM_ACCOUNT_INFO_DOUBLE);
      PROPERTIES(AccountInfoString,"",ENUM_ACCOUNT_INFO_STRING);
     }
  }
//+------------------------------------------------------------------+
//| Prints the terminal properties to the Experts tab.               |
//+------------------------------------------------------------------+
void PrintTerminal()
  {
   if(TerminalInfoString(TERMINAL_COMPANY)!="")
     {
      PROPERTIES(TerminalInfoInteger,"",ENUM_TERMINAL_INFO_INTEGER);
      PROPERTIES(TerminalInfoDouble,"",ENUM_TERMINAL_INFO_DOUBLE);
      PROPERTIES(TerminalInfoString,"",ENUM_TERMINAL_INFO_STRING);
     }
  }

Charts and graphical objects:

//+------------------------------------------------------------------+
//| Prints the chart properties to the Experts tab.                  |
//+------------------------------------------------------------------+
void PrintChart(const long chart_id)  // 0 means the current chart
  {
   if(ChartSymbol(chart_id)!="")
     {
      PROPERTIES(ChartGetInteger,Param(chart_id),ENUM_CHART_PROPERTY_INTEGER);
      PROPERTIES(ChartGetDouble,Param(chart_id),ENUM_CHART_PROPERTY_DOUBLE);
      PROPERTIES(ChartGetString,Param(chart_id),ENUM_CHART_PROPERTY_STRING);
     }
  }
//+------------------------------------------------------------------+
//| Prints the graphic object properties to the Experts tab.         |
//+------------------------------------------------------------------+
void PrintObject(const long chart_id, const string name)  // 0 means the current chart
  {
   if(ObjectFind(chart_id,name)>=0)
     {
      PROPERTIES(ObjectGetInteger,Params(chart_id,name),ENUM_OBJECT_PROPERTY_INTEGER);
      PROPERTIES(ObjectGetDouble,Params(chart_id,name),ENUM_OBJECT_PROPERTY_DOUBLE);
      PROPERTIES(ObjectGetString,Params(chart_id,name),ENUM_OBJECT_PROPERTY_STRING);
     }
  }

Symbol info:

//+------------------------------------------------------------------+
//| Prints the symbol specification to the Experts tab.              |
//+------------------------------------------------------------------+
void PrintSymbol(const string symbol)
  {
   Print(Symbol(),", ",SymbolInfoString(Symbol(),SYMBOL_DESCRIPTION));
   if(SymbolSelect(symbol,true))
     {
      PROPERTIES(SymbolInfoInteger,Param(symbol),ENUM_SYMBOL_INFO_INTEGER);
      PROPERTIES(SymbolInfoDouble,Param(symbol),ENUM_SYMBOL_INFO_DOUBLE);
      PROPERTIES(SymbolInfoString,Param(symbol),ENUM_SYMBOL_INFO_STRING);
     }
  }

Open positions and orders:

//+------------------------------------------------------------------+
//| Prints the position properties to the Experts tab.               |
//+------------------------------------------------------------------+
void PrintPosition(const ulong pos_ticket)
  {
   if((PositionGetInteger(POSITION_TICKET) == pos_ticket && pos_ticket != 0)
    || PositionSelectByTicket(pos_ticket))
     {
      PROPERTIES(PositionGetInteger,"",ENUM_POSITION_PROPERTY_INTEGER);
      PROPERTIES(PositionGetDouble,"",ENUM_POSITION_PROPERTY_DOUBLE);
      PROPERTIES(PositionGetString,"",ENUM_POSITION_PROPERTY_STRING);
     }
  }
//+------------------------------------------------------------------+
//| Prints the order properties to the Experts tab.                  |
//+------------------------------------------------------------------+
void PrintOrder(const ulong order_ticket)
  {
   if((OrderGetInteger(ORDER_TICKET) == order_ticket && order_ticket != 0)
    || OrderSelect(order_ticket))
     {
      PROPERTIES(OrderGetInteger,"",ENUM_ORDER_PROPERTY_INTEGER);
      PROPERTIES(OrderGetDouble,"",ENUM_ORDER_PROPERTY_DOUBLE);
      PROPERTIES(OrderGetString,"",ENUM_ORDER_PROPERTY_STRING);
     }
  }

History deals and orders:

//+------------------------------------------------------------------+
//| Prints the history deal properties to the Experts tab.           |
//+------------------------------------------------------------------+
void PrintDeal(const ulong deal_ticket)
  {
   if((HistoryDealGetInteger(deal_ticket,DEAL_TICKET) == deal_ticket && deal_ticket != 0)
    || HistoryDealSelect(deal_ticket))
     {
      PROPERTIES(HistoryDealGetInteger,Param(deal_ticket),ENUM_DEAL_PROPERTY_INTEGER);
      PROPERTIES(HistoryDealGetDouble,Param(deal_ticket),ENUM_DEAL_PROPERTY_DOUBLE);
      PROPERTIES(HistoryDealGetString,Param(deal_ticket),ENUM_DEAL_PROPERTY_STRING);
     }
  }
//+------------------------------------------------------------------+
//| Prints the history order properties to the Experts tab.          |
//+------------------------------------------------------------------+
void PrintHistoryOrder(const ulong order_ticket)
  {
   if((HistoryOrderGetInteger(order_ticket,ORDER_TICKET) == order_ticket && order_ticket != 0)
    || HistoryOrderSelect(order_ticket))
     {
      PROPERTIES(HistoryOrderGetInteger,Param(order_ticket),ENUM_ORDER_PROPERTY_INTEGER);
      PROPERTIES(HistoryOrderGetDouble,Param(order_ticket),ENUM_ORDER_PROPERTY_DOUBLE);
      PROPERTIES(HistoryOrderGetString,Param(order_ticket),ENUM_ORDER_PROPERTY_STRING);
     }
  }

Print enumerations:

//+------------------------------------------------------------------+
//| Print enumeration.                                               |
//+------------------------------------------------------------------+
//| Examples:                                                        |
//|                                                                  |
//|   PrintEnum<ENUM_TIMEFRAMES>();                                  |
//|   PrintEnum<ENUM_ACCOUNT_INFO_DOUBLE>();                         |
//|   PrintEnum<ENUM_FP_CLASS>();      // lowest enum value          |
//|   PrintEnum<ENUM_CHART_EVENT>();   // highest enum value         |
//+------------------------------------------------------------------+
template <typename T>
void PrintEnum(T dummy = -1)
  {
   Print(typename(T));
   Print("  {");
   for(int i = -2; i < USHORT_MAX + 1000; i++)
      if(StringFind(EnumToString((T)i),"::")<0)
         printf("   %s = %d,",EnumToString((T)i),i);
   Print("  };");
  }

Print struct variable:

//+------------------------------------------------------------------+
//| Print sructure variable.                                         |
//+------------------------------------------------------------------+
template <typename T>
void PrintStruct(T& struct_var)
  {
   T arr[1]; // one-element array
   arr[0] = struct_var;
   ArrayPrint(arr);
  }


Test script:

void OnStart()
  {
   PrintAccount();
   PrintTerminal();
   PrintChart(0);
   PrintObject(0,"MyBitmap");
   PrintSymbol(_Symbol);
   PrintPosition(925571424);
   PrintDeal(609261076);
   PrintHistoryOrder(925571424);

   PrintEnum<ENUM_TIMEFRAMES>();

   MqlDateTime dt;
   TimeToStruct(TimeCurrent(), dt);
   PrintStruct(dt);
  }


Test script 2:

void OnStart()
  {
   if(HistorySelect(0, TimeCurrent()))
     {
      int max = fmin(HistoryDealsTotal(), 3);  // limit to 3 deals
      for(int i = 0; i < max; ++i)
        {
         // print the history deal properties to the Experts tab
         PrintDeal(HistoryDealGetTicket(i));

         Print("--------");
        }
     }
  }
Files:
 
The whole mess because of this.

Forum on trading, automated trading systems and testing of trading strategies

Peculiarities of mql5 language, subtleties and techniques of work

fxsaber, 2025.02.12 22:40

If, suddenly, MQ decide in the trading platform (this year 18 years since the beginning of development) still give access to commissions, the script will immediately show it...

Decided to see if there is a commission or not.

 

a corrected typo:

//+------------------------------------------------------------------+
//| Prints the symbol specification to the Experts tab.              |
//+------------------------------------------------------------------+
void PrintSymbol(const string symbol)
  {
   Print(symbol,", ",SymbolInfoString(symbol,SYMBOL_DESCRIPTION));
   if(SymbolSelect(symbol,true))
     {
      PROPERTIES(SymbolInfoInteger,Param(symbol),ENUM_SYMBOL_INFO_INTEGER);
      PROPERTIES(SymbolInfoDouble,Param(symbol),ENUM_SYMBOL_INFO_DOUBLE);
      PROPERTIES(SymbolInfoString,Param(symbol),ENUM_SYMBOL_INFO_STRING);
     }
  }
Files:
 
amrali #:

a corrected typo:

Print massive information (PrintXYZ) from the terminal - library for MetaTrader 5

The output of this script can be sent to a remote-support person or to a freelance developper to aid detecting and fixing problems on your terminal.

https://www.mql5.com/en/code/56055

Print massive information (PrintXYZ) from the terminal
Print massive information (PrintXYZ) from the terminal
  • www.mql5.com
PrintXYZ() library to print massive information from the terminal.
 
amrali #:

Print massive information (PrintXYZ) from the terminal - library for MetaTrader 5

The output of this script can be sent to a remote-support person or to a freelance developper to aid detecting and fixing problems on your terminal.

https://www.mql5.com/en/code/56055

Auto-Complete in MetaEditor:

By including 'PrintXYZ' library in your projects, these functions will become available in MetaEditor's auto-complete box wherever, you type 'Print'. You can quickly compile the project file to print the results of MQL5 functions to the 'Experts' tab, and then you can decide which combination of MQL function / enum value will suit your requirements the best.