Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1220

 
HistorySelect(xxx,TimeCurrent()+1)

One second is often the loss of the last trade/order on the real. For example, on many breeches an order goes to execution for TTL time, which can be five seconds. If it isn't executed in five seconds, the order is a redirect. Or it is executed, but in three seconds.

In the case, if there were no ticks from the acceptance to the execution, such call HistorySelect will not receive information about it.


Perhaps, the TimeCurrent should be equal to MathMax(LastOrder_time, MarketWatch_Time). Then the HistorySelect will be correct. But TimeCurrent may be too expensive.


By the way, such a scheme of working HistorySelect will skip some of the history of trades.

void OnStart()
{
  static MqlTick PrevTick = {0};
  
  MqlTick Tick;
  
  if (SymbolInfoTick(_Symbol, Tick))
  {
    if (HistorySelect(PrevTick.time, INT_MAX))
      // Учитываем новые ордера/сделки в Истории торгов

    PrevTick = Tick;  
  }
}

Although, at first glance, everything is clear.


Writing a cheap DealsTotal() is not easy in MT5. It's not elementary (and free) OrdersHistoryTotal() in MT4.

 

thoughts aloud, no claim to relevance or competence:


fxsaber:

If there were no ticks from the acceptance to the execution, such a call to HistorySelect will not get information about it.

You won't solve this problem, the model of server - terminal - MQL interaction was originally designed

I haven't reached the point of checking in MT5, but in MT4 I know for sure that there are situations, when there are price changes on our symbol in the market watching window, but there may be no ticks or less than there are in ЕА


ok, never mind, so it works, you just need to choose in the TS decision, what happens to the order in the absence of information from the server from the moment you send the order - ie, the order will be set or rejected a priori, and received the answer to confirm this preliminary decision or cancel - ie, work with unconfirmed information or still wait for the answer from the server - this offer MQ and you probably will not suit


fxsaber:

It is not easy to use cheap DealsTotal() in MT5. It's not the elementary (and free) OrdersHistoryTotal() in MT4.

not write ;)

or rather, most likely you will, and you'll spend EA resources to maintain the algorithm, I think you need to find out how SQLite works, MQ performance tests declared, work with large tables and samples is just the purpose of the database - the EA code will be minimalistic, all the work the database will do, all the work comes down to filling data when placing an order and updating when the server responds (synchronization, of course, when you run EA, the database in memory)

 
Igor Makanu:

but you won't ;)

or rather, most likely you will write and will spend EA resources to maintain the algorithm, I think you need to figure out how SQLite works, MQ performance tests stated, work with large tables and samples is exactly the purpose of the database - EA code will be minimalistic, all the work the database will do you, all work will be reduced to filling data when placing an order and update when responding from the server (synchronization, of course at startup EA, the database in memory)

It was originally written and posted. It is unlikely to get any faster.

 
fxsaber:

It was originally written and posted. It is unlikely to get any faster.

I must have seen the task incorrectly.

I thought that I needed to update the list of orders from two pointsOnTradeTransaction() and OnTick() , therefore I suggested to do it in the database

 
void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result)
  {
   if(trans.type==TRADE_TRANSACTION_DEAL_ADD)
     {
      if(!HistoryDealSelect(trans.deal))
         return;
      bool time_to_sum_up=false;
      if(HistoryDealGetInteger(trans.deal,DEAL_ENTRY)==DEAL_ENTRY_OUT)
        {
         time_to_sum_up=true;
        }
      if(!time_to_sum_up)
         return;
      HistorySelect(0,TimeCurrent());
      int deals=HistoryDealsTotal();
      for(int i=deals-1; i>=0; i--)
        {
         if(HistoryDealGetTicket(i)==trans.deal)
           {
            Print("Found!");
            return;
           }
        }
      Print("Not Found!");
     }
   return;
  
This code is a simplified snippet of my EA.
Assume that, in a few cases, the result of running this code is to return "Not Found."
I don't quite understand why.
Why can't it find itself in the events it triggers?
The transaction event sent by the server to the terminal has arrived, but the server cannot simultaneously synchronize the correct time to the terminal?
My understanding is that a second's increase in the value of TimeCurrent() is more than enough.
I must be missing somethingimportant, right?
I would be very grateful if you could point out any errors in my understanding.
Объем импорта г/г - экономический индекс Японии
Объем импорта г/г - экономический индекс Японии
  • www.mql5.com
Объем импорта г/г (Imports y/y) отражает изменение объема импорта товаров и услуг в отчетном месяце по сравнению с тем же месяцем прошлого года. Показатели импорта используются для оценки внешней торговой активности Японии и спроса на импортируемые товары внутри страны. Из-за последствий "финансового кризиса" США Япония также столкнулась с...
 
Can you create a method to open Market Deep of some symbol in mql5 please? this is important when working with multiple symbols.
 
Dmitri Custurov:

Here is my code. In the initialization it creates one record in the table. In the OnTick body it should immediately return an error, because I try to add a record with the same PRIMARY KEY, and after that the base closes immediately. But at the same time I should see at least that first record when I open it, but when I run it in the tester it's not there. And even the table is not created. If I just open it in the terminal, everything is normal. The first record is there.

With the location of the database you do not messed up hopefully?

 
Aleksey Mavrin:

You're not confused about the location of the base, are you?

No, I'm not. Everything is in Files. I think that in tester mode, the database is created in memory and destroyed after the test.

 
Igor Makanu:

thoughts aloud, no claim to relevance or competence:

...

or rather, most likely you will write and will spend EA resources to maintain the algorithm, I think you need to find out how SQLite works, MQ performance tests stated, work with large tables and samples is precisely the purpose of the database - EA code will be minimalistic, all the work the database will do you, all work is reduced to filling data when placing an order and update when responding from the server (synchronization, of course, when running EA, the database in memory)

And what database will do all your work? Can you tell me?

 

On one terminal only placing orders, on the other (with the same broker and account) controlling execution. communication either through the database or through PUB/SUB ZMQ. Of course the database is not SQLite. The most suitable for these purposes is Redis, of course my personal opinion.

Good luck