How to get the total number of positions in this code

 
  • Most EA downloaded from the code base, I can get the total number of positions by encoding;
  • like this
  • void CalculatePositions(int &count_buys,int &count_sells)
      {
       count_buys=0.0;
       count_sells=0.0;
    
       for(int i=PositionsTotal()-1;i>=0;i--)
          if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
             if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
               {
                if(m_position.PositionType()==POSITION_TYPE_BUY)
                   count_buys++;
    
                if(m_position.PositionType()==POSITION_TYPE_SELL)
                   count_sells++;
               }
       return;
      }
    But I can not do this in any EA;
  • like  this EA https://www.mql5.com/zh/code/17065?utm_campaign=codebase.list&utm_medium=special&utm_source=mt5editor
Exp_SilverTrend_Signal_ReOpen
Exp_SilverTrend_Signal_ReOpen
  • votes: 20
  • 2017.02.07
  • Nikolay Kositsin
  • www.mql5.com
仓位缩减的信息存储在交易的注释字符串中, 格式为: 放置 SilverTrend_Signal.ex5 编译文件至 。 编译之后, Exp_SilverTrend_Signal_ReOpen.ex5 交易系统文件将 SilverTrend_Signal.ex5 指标作为 所以, 编译 EA 时不需要它们出现在终端文件夹里即可工作!为此目的, 已将相应的代码添加到 EA 代码中, 以便将这个指标包含在交易系统的可执行文件中。 测试结果 2015 品种 EURUSD H4:
 
Using this function causes errors.
 
fxsaber:
Using this function causes errors.

Wow :O What's the alternative?

 
dmdamiyo:

Wow :O What's the alternative?

If the solution to this problem is discussed, then only in Russian.

 
fxsaber:
Using this function causes errors.

This issue is known for years now. You have to pay attention that MT5/mql5 is asynchronous.

Anyway I doubt it's the OP problem as the EA referenced is working on new bar only, and very unlikely to have this issue.

 
Yong Zhang:

What do you mean by "I can not do this" ?

 
Alain Verleyen:

This issue is known for years now. You have to pay attention that MT5/mql5 is asynchronous.

You do not understand the problem.

 
fxsaber:

You do not understand the problem.

Yeah for sure.

It's amazing how you are arrogant, always thinking you discovered new things, which are well known for years.


I advice you either to explain your points, for everyone to learn something or stop posting in English section.

 
Alain Verleyen:

It's amazing how you are arrogant, always thinking you discovered new things, which are well known for years.

It looks like you are not even aware of the changes with OrderSend-function that occurred in the last year.

 
fxsaber:

It looks like you are not even aware of the changes with OrderSend-function that occurred in the last year.

What changes ?
 
Alain Verleyen:
What changes ?

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Особенности языка mql5, тонкости и приёмы работы

Sergei Vladimirov, 2017.03.06 19:41

Похоже, действительно заработала. Только что прилетело обновление до 1550, проверил - при открытии позиции сразу после OrderSend() всё окружение синхронизировано. 
Reason: