Errors, bugs, questions - page 1724

 
MK, why don't you add normal functions for binary search to the standard library? ArrayBsearch is only applicable in simple cases where types are simple and you don't need a custom comparator. Templates are there, make an override over c++::std::lower/upper_bound. So far I've had to write it myself, which is not normal (almost completely copied from cppreference).
template<typename A, typename T, typename Compare>
uint lower_bound(const A &ar[], const T &value, Compare &comp){
   long count = ArraySize(ar);
   uint first = 0;
  
   while(count > 0){
      uint it = first;
      uint step = count / 2;
      it += step;
      if(comp.comp(ar[it], value)){
         first = ++it;
         count -= step + 1;
      }
      else
         count = step;
   }
   return first;
}

void OnStart(){
   struct M_point{
      double price;
      datetime time;
   };
   M_point ar[5];
   ar[0].time = 2; ar[1].time = 4; ar[2].time = 6;
   ar[3].time = 8; ar[4].time = 10;
   struct Comp{
      bool comp(const M_point &p, datetime value) {return p.time < value;}
   }cmp;
   datetime value = 6;
   lower_bound(ar, value, cmp);
   return;
}

In the process a couple of questions arose:
1. Why is it impossible to write operator() in Comp (it is prohibited for some reason)?
bool operator()(const M_point &p, datetime value) {return p.time < value;}
2. Why can't we pass prvalue to function which accepts constant reference?
lower_bound(ar, 6, cmp) ); // ошибка
ZS: and also very annoying this warning: "struct has no members, size assigned to 1 byte "
 
coderex:

Everything is fine there, order placement should be controlled through OnTradeTransaction, by the way, if you connect to the exchange directly through Plaza2, the situation is the same - you need to control the arrival of messages about order placement. In MT4, this function is synchronous, but the same option is available in MT5, only in this case, the logic will stop until the function receives no response.

If you need, I can send you the control class, but it is written for market placing, but soon I will finalize it for limiters.

To control the request, you need to remember the fact of its placement. The class will be sent to you.
 
fxsaber:
Very much I ask you to post something to the kodobase! For educational purposes.

Can't for the reason you yourself pointed out https://www.mql5.com/ru/forum/1111/page1743#comment_2877482. Recently I could not localize the error, spent a lot of time to form the source code into servicedesk - in the end nothing came out because of many cross-references (one pulls the other in geometric progression) - I sent .ex5

For educational purposes I can suggest the task: without introducing additional variables simplify h() so that f() is called in any case once

bool f() { return Random(); /*вычисляется ооочень долго, но результат не зависит от числа вызовов*/ } 
void g1() { /*делает что-то полезное*/ }
void g2() { /*делает что-то полезное*/ }
void h() {
#ifndef  MACRO
        if ( f() )
#endif
        {
                if ( f() )
                        g1();
                g2();
        }
}
Ошибки, баги, вопросы
Ошибки, баги, вопросы
  • www.mql5.com
Форум трейдеров MQL5.community
 
A100:

Compilation error

(*) In general, in pattern (1) both A->(2) and const A->(3) can be substituted instead of T.

Why is that? A pattern with const cannot accept non-const - it violates the contract.

 
A100:

For educational purposes, I can suggest the following task: without introducing additional variables, simplify h() so that f() is called once in any case

bool f() { return Random(); /*вычисляется ооочень долго, но результат не зависит от числа вызовов*/ } 
void g1() { /*делает что-то полезное*/ }
void g2() { /*делает что-то полезное*/ }
void h() {
#ifndef  MACRO
        if ( f() )
        {
                g1();
                g2();
        }
#else
        if ( f() )
                g1();
        g2();
#endif
}
 
Stanislav Korotky:

Why is that? A template with const cannot accept non-const - it violates the contract.

Template is not by itself (unlike function) - its task is to perform substitution (by analogy with #define). If there are no contradictions at the end of replacement (and there are none), the template has fulfilled its task. At least I tried to compile it in C++ and the compiler gave no errors or warnings
 
fxsaber:
This is not really a simplification. In the original MACRO+2*f+g1+g2=5 - you have: MACRO+2*f+2*g1+2*g2=7.
[Deleted]  
Sergey Diubakin:

Has anyone experienced a similar problem? Is it a "bug" in the terminal or mine?

What does GetLastError() return ?
[Deleted]  
fxsaber:

MT5-OrderSend is NOT fully synchronised - there is no synchronisation with the trading environment. This means that the history readings do not correspond to the real situation.

No timeout is out of the question. There is no reliable solution to the problem, because you have to deal with synchronization issues at the terminal level, not at the server level.

In fact, MT5 users are facing what MT4 bridge developers are facing.

If an OrderSend is sent, you have to REMEMBER (this is where the potential vulnerability is) that it is done. Then ignore the current history (trading environment) until the corresponding message comes in OnTrade. Once it arrives, REMEMBER to FORGET.

When there is no REMEMBER, you can trust the history as in MT4.

MT4-OrderSend is FULLY synchronised.
I wonder - for what reason is this done ...
I understand if you mess with OrderSendAsync asynchronously, you can handle both OnTrade and OnTradeTransaction. With OrderSend I want to have simple behavior, like in MT4. Once it is called, we obtain in the output already modified open positions and history.
There is a subtle point. If the current state is stored in a global variable and the expectation of state changes takes a relatively long time, and the trader manages to change the EA parameters, the global variables will be reset and the state will be discarded.
 
bool f() { return Random(); /*вычисляется ооочень долго, но результат не зависит от числа вызовов*/ } 
void g1() { /*делает что-то полезное*/ }
void g2() { /*делает что-то полезное*/ }
void h() {
        if ( f() )

        {
                g1();
#ifdef  MACRO
        }
#endif
                 g2();
#ifndef  MACRO
        }
#endif
}