Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1876

 
Maksim Emeliashin static arrays of names of each possible value and string search in this array.

What's the point of all this? You want to replace numeric values of ENUM_TIMEFRAMES with your own? Or what?

 
Please help, I draw two Gann lines and they intersect at a certain point, I need to know the coordinates of the intersection point of these lines.
Files:
 
12345678902003 #:
Help please, I draw two Gann lines and they intersect at a certain point, I need to know the coordinates of the intersection point of these lines.
Line equation to help
 
Artyom Trishkin #:
The straight line equation is a help

Get the prices from the straight lines on each bar and compare or find the difference, in places where the signs of the crossing differences change) There may be no equalities on the bar, by the way.

 
Valeriy Yastremskiy #:

Get the prices from the straight lines on each bar and compare or find the difference, in places where the signs of the crossing differences change) There may be no equalities on the bar, by the way.

>=, <=
 

Good afternoon, all.

I am rewriting an EA from MQL4 to MQL5. I do not understand how to get the reason for closing a position by SL.

I need it to make a decision on what to do next.

In MT5 terminal, you can select a trade, order or position in history window.

 
Maksim Emeliashin static arrays of names of each possible value and string search in this array.

For MQL this function will not work correctly

template<typename T>
bool StringToEnum(const string i_str, T &o_val)
{
   for(int i = 0; i < 256; i++)
      {
         o_val = (T)i;
         if(StringCompare(EnumToString(o_val), i_str, false) == 0)
            return(true);
      }
   o_val = WRONG_VALUE;
   return(false);
}

https://www.mql5.com/ru/docs/strings/stringcompare

Parameters

string1

[in] The first string.

string2

[in] Second string.

case_sensitive=true

[in] Case sensitive mode. If true, then "A">"a". If false, then "A"="a". The default value is true.

If there will be two constants in enum, for example ENUM1 and enum1, then at i_str:"enum1" function can return the value of constantENUM1. Why StringCompare at all? If it can be done in the following way:

template<typename T>
bool StringToEnum(const string i_str, T &o_val)
{
   for(int i = INT_MIN; i <= INT_MAX && !IsStopped(); i++) // перебор всех возможных значений int
      {
         o_val = (T)i;
         if(i_str == EnumToString(o_val))
            return(true);
      }
   o_val = WRONG_VALUE;
   return(false);
}
 
Amon1953 for closing a position by SL.

I need it to make a decision on what to do next.

In the history window of the MT5 terminal you can select a deal, order or position.

In the trading history you need to look for a trade with DEAL_REASON equal to DEAL_REASON_SL.


Added: It can be simplified - in OnTradeTransaction just catch the transaction TRADE_TRANSACTION_DEAL_ADD and calling to trade history look for DEAL that created this transaction. And then the same recipe: ... DEAL_REASON equals DEAL_REASON_SL

 
Mihail Matkovskij #:

The function will not work correctly for MQL

https://www.mql5.com/ru/docs/strings/stringcompare

If there are two constants in enum, for example ENUM1 and enum1, then with i_str:"enum1" the function may return the value of constantENUM1. Why do we need StringCompare anyway? If it can be done in the following way:

And a faster variant:

template<typename T>
bool StringToEnum(const string i_str, T &o_val, int i_min_enum, int i_max_enum)
{
   for(int i = i_min_enum; i <= i_max_enum && !IsStopped(); i++) 
      {
         o_val = (T)i;
         if(i_str == EnumToString(o_val))
            return(true);
      }
   o_val = WRONG_VALUE;
   return(false);
}

bool StringToEnum(const string i_str, T &o_val) { return StringToEnum(i_str, o_val, INT_MIN, INT_MAX); } // медленный вариант
 
Alexey Viktorov #:

What is all this for? Do you want to replace the numerical values of ENUM_TIMEFRAMES with your own? Or what?

Well, right now I need to write the settings of indicators and EA's parameters in the database. At the same time I would like to have:

1. human-readable records

2. machine-readable records

3. The stability to add new values in custom enum, not necessarily at the end.

There is no problem with record - EnumToString, but developers did not make reverse function, unlike all other types.

Reason: