Tanvir Ahmed: I need to count total running currency pairs using a loop
- Start with an empty array of symbols.
- For each order, find the symbol in your array of symbols. If you don't find it, it's a new symbol, add it to the array.
- After the loop, the answer is the size of the array.
whroeder1:
- Start with an empty array of symbols.
- For each order, find the symbol in your array of symbols. If you don't find it, it's a new symbol, add it to the array.
- After the loop, the answer is the size of the array.
Can you show me an example please?
We're not going to code it for you. We are willing to help you when you show us your attempt
(using CODE button) and state
the nature of your problem.
No free help
urgent help.
No free help
urgent help.
whroeder1:
Show us your attempt (using CODE button) and state the nature of your problem.
No free help
urgent help.
Show us your attempt (using CODE button) and state the nature of your problem.
No free help
urgent help.
int running_symbol_total = 0; if(OrdersTotal() > 0) { for(int i = 0; i <= OrdersTotal()-1; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true) { if(OrderSymbol() != NULL && OrderMagicNumber() == magic_number) { running_symbol_total = ++running_symbol_total; } } } } Alert(running_symbol_total);
But this results me equal of OrdersTotal();
Tanvir Ahmed:
But this results me equal of OrdersTotal();
if you want to get the open Positions,then use PositionsTotal,Order and position are different.
Bilal Said: if you want to get the open Positions,then use PositionsTotal,Order and position are different.
There is no such positions total in MT4.
Tanvir Ahmed: But this results me equal of OrdersTotal();
if(OrdersTotal() > 0){ for(int i = 0; i <= OrdersTotal()-1; i++)
The if is redundant. If total is zero the for loop does nothing.Simplify your condition: i <= n-1 is the same as i < n.
running_symbol_total = ++running_symbol_total;
V = V is redundant. Simplify your code: ++running_symbol_total;- Of course your code just equals OrdersTotal. I gave you the answer at #1. Where is your code that does that.
The easiest way is to use a set collection....
#include <Arrays\ArrayString.mqh> class StringSet : public CArrayString { public: bool Add(const string element) { if(SearchLinear(element) < 0) return CArrayString::Add(element); return false; } string ToString() { Sort(); string res = "["; for(int i=0;i<Total();i++) res+= this[i]+(i==Total()-1?"":", "); return res + "]"; } }; void OnStart() { StringSet sym_cnt; for(int i=OrdersTotal()-1;i>=0;i--) if(OrderSelect(i,SELECT_BY_POS) && sym_cnt.Add(OrderSymbol())) printf("Adding original symbol %s to set",OrderSymbol()); printf("There are %d unique symbols in the set %s", sym_cnt.Total(), sym_cnt.ToString()); }
nicholishen:
The easiest way is to use a set collection....
Faster
int GetSymbols( string &Symbols[] ) { int Res = 0; for (int i = ArrayResize(Symbols, OrdersTotal()) - 1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS)) Symbols[Res++] = OrderSymbol(); return(ArrayResize(Symbols, Res)); } // Возвращает количество уникальных элементов в массиве template <typename T> int GetUniqueElements( const T &Array[] ) { int Res = 0; const int Size = ArraySize(Array); if (Size) { Res = 1; T Max = Array[Size - 1]; T Min = Max; for (int i = Size - 2; i >= 0; i--) if (Array[i] > Max) { Max = Array[i]; Res++; } else if (Array[i] < Min) { Min = Array[i]; Res++; } } return(Res); } int GetAmountSymbols() { string Symbols[]; GetSymbols(Symbols); return(GetUniqueElements(Symbols)); } void OnStart() { Print(GetAmountSymbols()); }
fxsaber:
Faster
negligible
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!
Can anyone help me to code, how to count total number of running currency pair(s) with active order(s).
In the picture, there are 4 active orders running with 3 different currency pairs.
Here,
I don't need to count total orders using OrdersTotal() function.
Also I don't need to identify currency pair name using OrderSymbol() function.
But I need to count total running currency pairs using a loop, just like --
How do I code that?
Thank you in advance.