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

 
Vitaly Muzichenko:

What's the harm in such a design?

Or is it better to makedatetime a long type?

I don't see a problem so far.
But there is an obvious craving for accuracy (datetime is larger than time_t, to put it mildly).
and it should rather be long for time comparisons. If the compiler optimizes something, it will throw it away, and a deposit for the future remains :-)
 
Maxim Kuznetsov:
I don't see a problem so far.
But there is an obvious tendency to be more precise (datetime is softly larger than time_t)
and it's more likely that this long should be used to compare times. If compiler optimizes something, it will throw it away and leave a deposit for the future :-)

So you can use it without cheating without consequences?

 
Vitaly Muzichenko:

So you can use it without cheating without consequences?

Well, how could it be without consequences :-)

long x = TimeCurrent(); already gets a "slap on the face" in a good company :-) Not only are the types different in physics, but they are also different in dimension and you convert a larger type to a smaller one.

But yes, all seconds from (datetime)TimeCurrent seem to fit into long

 
Maxim Kuznetsov:

there is a great function StringFind() - search for "#" or "from #".

Found
StringFind(OrderComment(),"to #",0)


and what do we do with it?

InStringSubstr, everything is clear, you get digits immediately - ticket, but here inStringFind , we already know that there is"to #" in the comment

 
PolarSeaman:
Found


and what to do with it?

InStringSubstr everything is clear, we get the numbers immediately - ticket, but here inStringFind what, we already know that there is"to #" in the comment

but we don't know where.) StringFind will tell us if the "to #" we are looking for is at this position or not there at all. Never rely on something that comes from the net and you personally/personally don't control it :-) We're playing money here - this is serious.

 
Maxim Kuznetsov:

but don't know where :-) StringFind will tell you that the "to #" you're looking for is from exactly this position, or it doesn't exist at all. Never rely on something that comes from the net and you personally/personally don't control it :-) We're playing money here - this is serious.

need to highlight the ticket from the comment and throw out the "to #".

the ticket for an open position is compared to the one in the comment for a closed position

why are we even looking for the"to #"?

 

TheStringSubstr function returns the right part of the comment. Why does this function return the profit of an open position and not the profit of a closed position? I'm going throughMODE_HISTORY

double prof_cl_pos(string sy="0", int op=-1, int mn=-1) {
  datetime ta;
  int      i, k=OrdersHistoryTotal();
  double profit_=0;
  string comment="";
  string substr="";

  if (sy=="" || sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              comment=OrderComment();
               substr = StringSubstr(comment, 4, 9);
              if (ticket_op_pos(Symbol(), -1,mn)==substr)
              profit_=OrderProfit();
            }
          }
        }
      }
    }
  }
  return(profit_);
}
 
Vitaly Muzichenko:

What is the harm of such a construction?

Or is it better to makedatetime a long type?

datetime is ulong - that's where you should put it.
 
PolarSeaman:

the ticket should be highlighted from the comment and the "to #" should be discarded.

the ticket for an open position should be compared to the ticket in the comment for a closed position

why are we even looking for the"to #"?

We are looking for it in order to find out "is there even to# or from#" in the comment. If there isn't, then this order is not a part of a closed position and we do not need it.

If the StringFind(OrderComment(), "#to") is greater than or equal to zero, it means that the comment contains the sought sub-string, and only now we can calculate the position of the ticket number in this string.

 
PolarSeaman:

TheStringSubstr function returns the right part of the comment. Why does this function return the profit of an open position and not the profit of a closed position? I am going throughMODE_HISTORY.

And this is the answer to this question.

Forum on trading, automated trading systems and strategy testing

Any questions from newbies on MQL4, help and discussion on algorithms and codes

PolarSeaman, 2018.04.07 00:25

Found
StringFind(OrderComment(),"to #",0)


And what to do with it?

Everything is clear inStringSubstr, you get numbers - ticket, but here inStringFind what, we already know that there is"to #" in the comment


But if you don't, you'll get something completely different.

Reason: