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

 

GetSystemTimePreciseAsFileTime is very interesting. This kind of function is missing in MQL, or at least rounded to micro/milliseconds. Time in seconds is too crude. In MT itself milliseconds are used everywhere. Now I have to make a big deal by synthesizing the exact time using the same GetMicrosecondCount:

long TimeLocal_mcs() 
{ 
  static long time0_mcs= 0;
  if (time0_mcs==0) { datetime t=TimeLocal();  while(TimeLocal()==t);  time0_mcs= (t+1)*1 e6 - GetMicrosecondCount(); }
  datetime time= TimeLocal();
  long time_mcs= time0_mcs + GetMicrosecondCount();
  long delta= time_mcs - time*(long)1 e6; 
  if (delta<0) { time0_mcs-=delta;  time_mcs-=delta; }  
  return time_mcs;
}
 
Alexey Navoykov:

By the way, GetSystemTimePreciseAsFileTime is very interesting. This kind of function is missing in MQL, well, at least with rounding to micro/milliseconds. Time in seconds is too crude. In MT itself milliseconds are used everywhere. Now I have to do this by synthesizing the exact time using the same GetMicrosecondCount:

Create your own callback with generation in mcs through WinApi functionality

 
Konstantin:

Create your own callback with generation in mcs via WinApi functionality

What's the callback for here?

 
Alexey Navoykov:

What's the callback for?

Well if you want the whole thread then a function-ring is enough, and if you want to work with events then callback

 
Check your work (how to be with the Market - do not know) for the mechanism of invisibility. It is possible to seriously "get"...
 
An old topic, but very simple code for understanding the problem

Forum on trading, automated trading systems and testing trading strategies

How to check that an order is executed after calling PositionOpen

fxsaber, 2018.08.09 20:35

Try this script thereForexTimeFXTM-Demo01 (orFXOpen-MT5)

#include <Trade/Trade.mqh>

void OnStart()
{
  const int PrevTotal = PositionsTotal();
  
  CTrade Trade;  
  
  while (PositionsTotal() == PrevTotal)
    Trade.Buy(1);    
}

Sometimes two new positions will open, not one.


The script tries to open one new position, but sometimes we get two.

 
fxsaber:
Old topic, but quite simple code to understand the problem

The script tries to open one new position, but sometimes we get two.

It's kind of like there was already a solution in QB:

//+------------------------------------------------------------------+
//| Возвращает "неопределённое" состояние торгового окружения        |
//+------------------------------------------------------------------+
bool IsUncertainStateEnv(const string symbol_name,const ulong magic_number)
  {
   if(MQLInfoInteger(MQL_TESTER)) return false;
   int total=OrdersTotal();
   for(int i=total-1; i>WRONG_VALUE; i--)
     {
      if(OrderGetTicket(i)==0) continue;
      if(OrderGetInteger(ORDER_TYPE)>ORDER_TYPE_SELL) continue;
      if(OrderGetInteger(ORDER_MAGIC)!=magic_number) continue;
      if(!OrderGetInteger(ORDER_POSITION_ID) && OrderGetString(ORDER_SYMBOL)==symbol_name)
         return true;
     }
   return false;
  }

//+------------------------------------------------------------------+
//| Заполняет массивы тикетов позиций                                |
//+------------------------------------------------------------------+
bool FillingListTickets(const uint number_of_attempts)
  {
//--- Проверка состояния окружения
   int n=0,attempts=int(number_of_attempts<1 ? 1 : number_of_attempts);
   while(IsUncertainStateEnv(symb,InpMagic) && n<attempts && !IsStopped())
     {
      n++;
      Sleep(sleep);
     }
   if(n>=attempts && IsUncertainStateEnv(symb,InpMagic))
     {
      Print(__FUNCTION__,": Uncertain state of the environment. Please try again.");
      return false;
     }
//---

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- Проверка нулевых цен
   if(!RefreshRates() || Point()==0) return;
//--- Заполнение списков тикетов позиций
   int positions_total=PositionsTotal();
   if(prev_total!=positions_total)
     {
      if(FillingListTickets(num_attempts))
         prev_total=positions_total;
      else return;
     }

 
fxsaber:
Check your work (I don't know about the Marketplace) for the invisibility mechanism. You can seriously "get"...

Followed the link, but did not understand what invisibility mechanism we are talking about.

 
Alexey Navoykov:

Followed the link, but did not understand what mechanism of invisibility we are talking about.

The indicator is in a hidden mode on the chart. It will unload Expert Advisors. I think I understood it through a quick look from the cell phone.

 
Alexey Navoykov:

Followed the link, but did not understand what invisibility mechanism we are talking about.

It cannot be removed.