How To Distinct OrderSymbol() In MQL4

Milan Zivanovic
137
Milan Zivanovic  

How to distinct  OrderSymbol()  in MQL4?

I have data:

Symbol | Type | Size

GBPUSD | Buy | 1.5

GBPUSD | Buy | 0.5

EURUSD | Sell | 1

USDJPY | Buy | 2

I want the result:

GBPUSD

EURUSD

USDJY

found one way on the internet but am i interested in any other idea?

Thanks

Soconia UG
225
Werner Klehr  

Hi Milan,

what do you think of this solution:

        string str_1 = "GBPUSD | Buy | 1.5 ";
        string str_2[];
        string str_3;

        StringSplit(str_1, '|', str_2);
        str_3 = StringTrimRight(str_2[0]);


Best regards,

Milan Zivanovic
137
Milan Zivanovic  
Werner Klehr:

Hi Milan,

what do you think of this solution:


Best regards,

Hi Werner,


my example is not a string, it is OrderSymbol() function.

It is necessary to get a unique symbol from that function that returns the symbols.

Milan Zivanovic
137
Milan Zivanovic  

these are current open trades.

I need to get unique symbols as the end result.

like this:

EURUSD

GBPUSD

USDCHF

William Roeder
25060
William Roeder  
Milan Zivanovic: my example is not a string, it is OrderSymbol() function.
  1. The question makes no sense. You select an order, and you get the symbol of that order with that function.
  2. You can not use any Trade Functions until you first select an order.

Milan Zivanovic
137
Milan Zivanovic  
William Roeder:
  1. The question makes no sense. You select an order, and you get the symbol of that order with that function.
  2. You can not use any Trade Functions until you first select an order.

Of course I selected the order first.

   int total = ObjectsTotal();
   for (int i = 0; i < total; i++)
   {
      if (!OrderSelect(i, SELECT_BY_POS)) continue;

      string cp = OrderSymbol();
   }

This is how I get double symbols because there are several open orders with the same symbol.

My question is how to distinct them? Like group by...

Laszlo Tormasi
7134
Laszlo Tormasi  
Milan Zivanovic:

Of course I selected the order first.

This is how I get double symbols because there are several open orders with the same symbol.

My question is how to distinct them? Like group by...

There's no easy way to do that like in SQL.

Add the symbols to a string array and before each add check if the symbol is already in the array. 

Mehmet Bastem
2551
Mehmet Bastem  
Milan Zivanovic:

How to distinct  OrderSymbol()  in MQL4?

I have data:

Symbol | Type | Size

GBPUSD | Buy | 1.5

GBPUSD | Buy | 0.5

EURUSD | Sell | 1

USDJPY | Buy | 2

I want the result:

GBPUSD

EURUSD

USDJY

found one way on the internet but am i interested in any other idea?

Thanks


This can be done simply as follows. Picture of before and in order is attached.

qq eee

//+------------------------------------------------------------------+
//|                                       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>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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;
   
   for(int i=OrdersTotal()-1; i>=0; --i)
     {
      if(OrderSelect(i, SELECT_BY_POS))
        {
         
            MarketEmirler.Add(OrderSymbol());
         
        }
     }
   for(int i=MarketEmirler.Total()-1; i>=0; --i)
     {
        Print(MarketEmirler.At(i));
       //SorgulananEmirler=MarketEmirler.SearchLinear(BekleyenEmirler.At(i));
       //Print(SorgulananEmirler," ",BekleyenEmirler.At(i));
           }

  }
Milan Zivanovic
137
Milan Zivanovic  
Mehmet Bastem:


This can be done simply as follows. Picture of before and in order is attached.


Yes, this is the solution I was looking for.


Thank you Mehmet.