How do I open a market order correctly? - page 7

 
prostotrader:

By the way, it's strange that you call Sleep() from an indicator, because it is prohibited:

The Sleep() function cannot be called from custom indicators, as indicators are executed in the interface thread and must not slow it down. The function has built-in check for status of the expert's stop flag every 0.1 seconds.


 
Alexey Kozitsyn:

By the way, it is strange that you call Sleep() from the indicator, as it is forbidden:


I don't know what Sleep() is at all
 
prostotrader:

Alexei!

Quite a liquid instrument :)

2016.12.14 22:01:41.431 Trades  'xxxxx': cancel order #49931802 sell limit 1.00 GOLD-9.17 at 1190.2 placed for execution in 64926.078 ms

It's not about instrument (liquidity), it's about delay, which can occur in ANY instrument.

I've been actively trading with EAs for almost 4 years now.

I don't have any pauses in any of my EAs (except pausing to wait for data to be downloaded from server in INDICATORS),

If you do pause, it's a sure sign that your EA's algorithm isn't working properly :(

I've been trading for a long time too, and I only use EAs. But mostly on MT4. I've been trading on MT5 only with Expert Advisors using Limits and there were no issues. I'm against additional pauses in EAs too, especially if it's a scalper or pipsitter, it's easy to miss an entry.
 
prostotrader:
I don't know what Sleep() is at all
Then it's strange that you and I are discussing pauses now...
 
Alexey Kozitsyn:
Then it's strange that you and I are discussing pauses now...
Not in the sense of what Sleep() does, but in the sense of its application in my code.
 
prostotrader:
Not in the sense of what Sleep() does, but in the sense of using it in my code.
How do you implement a pause in your indicator?
 
Alexey Kozitsyn:
How do you implement a pause in your indicator?
//+------------------------------------------------------------------+
// Custom indicator Check timer function                             |
//+------------------------------------------------------------------+
bool CheckTimer(const uint start_value, const uint per_value)
{
  uint end_value = GetTickCount();
  
  if(end_value < start_value)
  {
    if((start_value - end_value) >= per_value) return(true);
  }
  else
  {
    if((end_value - start_value) >= per_value) return(true);
  }
  return(false);
}
//+------------------------------------------------------------------+
//| Custom indicator Get server data function                        |
//+------------------------------------------------------------------+
int LoadServerData(const string a_symbol, ENUM_TIMEFRAMES period)
{
  int fail_cnt = 0;
//---
  while((fail_cnt < 5) && !IsStopped())
  {  
    long first_date = long(SeriesInfoInteger(a_symbol, PERIOD_M1, SERIES_SERVER_FIRSTDATE));
//---
    if(first_date > 0)
    {
      if(SymbolIsSynchronized(a_symbol))
      {
  //      Print( "LoadServerData: Первая дата на сервере есть. Пробуем получить локальные данные..." );
        return(GetLocalData(a_symbol, period));
      }  
    }
    else
    {
      uint start_tick = GetTickCount();
//---        
      while(!CheckTimer(start_tick, 10))
      {
        fail_cnt--;
        fail_cnt++;
      }
    }    
    fail_cnt++;
  }
// Print( "LoadServerData: Первой даты на сервере нет!" );
  return(0);  
}

This is an old example.

As GetTickCount error is rather high (up to 16 ms), now I use GetMicrosecondCount().

 
Gennady Mazur:
In principle I do so, but in Forts the order is often accepted successfully...but on the next tick there is no position yet...
This is where the additional opening may slip .... partially solve the problem this way, if the order is accepted, I increase the int variable, and after the increase the conditions for opening are slightly different, so there is no new opening, but.... if the order is not accepted the variable is not increased, but here is the tricky part... I misjudged the state and additional orders started to appear.
You have already answered your own question. We need to follow the order.
 
prostotrader:

Alexei!

Quite a liquid instrument :)

2016.12.14 22:01:41.431 Trades  'xxxxx': cancel order #49931802 sell limit 1.00 GOLD-9.17 at 1190.2 placed for execution in 64926.078 ms

It's not about instrument (liquidity), it's about delay, which can occur in ANY instrument.

I've been actively trading with EAs for almost 4 years now.

I don't have any pauses in any of my EAs (except pausing to wait for data to be downloaded from server in INDICATORS),

If you do pause, it's a sure sign that your EA's algorithm isn't working properly :(

So what if you don't have one? Maybe the algorithm there is such that it is not required.
 
Gennady Mazur:
I too have been trading for quite a long time and only with the help of EAs. But mostly on MT4. I've been trading on MT5 only with Expert Advisors using Limits and there were no issues. If I'm a scalper or a pipsder, I do not like pauses in Expert Advisors, moreover I just miss an entry.
This is not the case when you need a pause.
Reason: