The problem is that it keeps returning value "0" even when the 5 pairs are opened.
To be honest with you, I cannot even be bothered to read your code.
Why?
Because you do not use meaningful names for the variables.
Get into the habit of using variable names to describe what they are storing. Especially if you want others to help you.
Thanks Keith,
Your observation is noted. I was just trying to make it simple. I thought my explanation would suffice.
Thanks Keith,
Your observation is noted. I was just trying to make it simple. I thought my explanation would suffice.
It doesn't make it simple....
if(NumberOfTrades<MaxTrades) { //open the order }
is much easier to understand than
if(N<M) { //open the order }
as you don't have to check back through the code to find out what values N and M hold.
Thanks Keith,
Your observation is noted. I was just trying to make it simple. I thought my explanation would suffice.
It's not simple, it's spaghetti code. You need to create a collection of unique elements, and in programming the normal way to achieve this is by using a set. Unfortunately, MQL doesn't have a "set" collection for strings but you can easily subclass CArrayString and make your own.
...actually I've done it for you...
#include <Arrays\ArrayString.mqh> class StringSet : public CArrayString { public: bool Add(const string element){ if(this.SearchLinear(element) < 0) return CArrayString::Add(element); return false; } }; void OnStart() { StringSet unique_symbols; for(int i=OrdersTotal()-1; i>=0; --i) if(OrderSelect(i, SELECT_BY_POS) && OrderType() < 2) unique_symbols.Add(OrderSymbol()); Print("Symbols total = ", unique_symbols.Total()); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The problem is that it keeps returning value "0" even when the 5 pairs are opened.