Use trading classes -
#include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> #include <Trade\SymbolInfo.mqh> //--- CPositionInfo m_position; // trade position object CTrade m_trade; // trading object CSymbolInfo m_symbol; // symbol info object
this way you will not make mistakes.
//+------------------------------------------------------------------+ //| 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; }
Vladimir Karputov:
Use trading classes -
this way you will not make mistakes.
Hi there, is not an order count fail, I've just seen that it is opening and closing orders from another symbols in some test (EURUSD does not give this problem). But for example GBPUSD is opening and closing EURUSD and EURGBP orders and don't actually know why.
void OnTick(){ CTrade trade; double MyBuffers[]; ArraySetAsSeries(MyBuffer1,true); ArraySetAsSeries(MyBuffer2,true); ArraySetAsSeries(MyBuffer3,true); for(int s=0;s<SymbolsTotal(true);s++){ string SName=SymbolName(s,true);
I'm posting this new problem into a new topic.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hello, I have this internal loop which is working fine on unique symbol strategy, but it's giving lots of operations in some currency pairs when working multisymbol:
The logic behind to open a buy or sell position is the following:
Here the test drive signal: ***