How to Distinct Symbols of Open and Pending Orders in MT5

 

Dear Experts,

I want to get distinct  list of symbols which has open or pending orders.

My code is giving me the list of only open positions.

Can you help me with modification so that it would get the symbols of both open and pending orders.


Thank you in Advance!

string SyMass[];
bool Find(string aSymbol)
{
int arr = ArraySize(SyMass);
for(int i = 0; i < arr; i++)
if(SyMass[i] == aSymbol)
return false;
if(ArrayResize(SyMass, arr + 1) != -1)
SyMass[arr] = aSymbol;
return true;
}
bool FillSymbols(void)
{
int TotalPositions=PositionsTotal()-1;
for(int i = TotalPositions; i >= 0; i--)
if(Find(PositionGetSymbol(i)) == false)
{
}
int arr = ArraySize(SyMass);
for(int f = 0; f < arr; f++)
{
Print(SyMass[f]);
}
return(true);
}
 
Dilchan B M:

Dear Experts,

I want to get distinct  list of symbols which has open or pending orders.

My code is giving me the list of only open positions.

Can you help me with modification so that it would get the symbols of both open and pending orders.


Thank you in Advance!

//+------------------------------------------------------------------+
//|                                       Haskayafxstubborn goat.mq4 |
//|                                 Copyright 2019, Haskaya Software |
//|                                   https://www.haskayayazilim.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Haskaya Software"
#property link      "https://www.haskayayazilim.net"
#property version   "1.00"
#property strict

#include <Arrays\ArrayString.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\HistoryOrderInfo.mqh>
#include <Trade\DealInfo.mqh>
CPositionInfo Position;
CHistoryOrderInfo History;
CDealInfo  Deal;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class IntegerSet : public CArrayString
  {
public:
   bool              Add(const string element)
     {
      if(this.SearchLinear(element) < 0)
         return CArrayString::Add(element);
      return false;
     }
  };
void OnTick()
  {

 MarketEmirKontrol();
 ExpertRemove();
 }

void MarketEmirKontrol()
  {
   IntegerSet MarketEmirler;
   // Market Orders
   
   int total=PositionsTotal();   
   for(int i=0; i<total; i++)
     {
         string position_symbol=PositionGetSymbol(i); //
         MarketEmirler.Add(PositionGetSymbol(i));
         
     }
     // Pending Ordes
         int o_total=OrdersTotal();
         for(int j=o_total-1; j>=0; j--)
         {
            ulong o_ticket = OrderGetTicket(j);
            string abs=OrderGetString(ORDER_SYMBOL);
            MarketEmirler.Add(OrderGetString(ORDER_SYMBOL));
         }   
     //SorgulananEmirler=MarketEmirler.SearchLinear(BekleyenEmirler.At(i));
       //Print(SorgulananEmirler," ",BekleyenEmirler.At(i));
   for(int i=MarketEmirler.Total()-1; i>=0; --i)
           {
           Print(i," Symbol  ",MarketEmirler.At(i));
           }

  }
Reason: