PositionSelect(_Symbol) is a construct for a NETTING trading account.
Use the generic construct:
//+------------------------------------------------------------------+ //| Calculate all positions Buy and Sell | //+------------------------------------------------------------------+ void CalculateAllPositions(int &count_buys,int &count_sells) { count_buys=0; count_sells=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()==InpMagic) { if(m_position.PositionType()==POSITION_TYPE_BUY) count_buys++; if(m_position.PositionType()==POSITION_TYPE_SELL) count_sells++; } //--- return; }
I was not aware of this NETTING trading account. Thanks for showing me a new thing and sharing the detailed code, Vladimir.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I'm using the below code to limit the buy/sell position at a time but I'm not sure why MetaTrader5 could open more than 1. I just can't figure it why. Could someone shed a light here?
Later, we will decide whether to open a position or not base on Buy_opened and Sell_opened. I'm suspecting the methods that used in the above block don't always work right. Any thoughts?