How do I access the 0th dimension of an array? - page 3

 
Fernando Carreiro #:

Yes, they are the same underlying data-type, but they are not of the same "meaning". They are two different types even if implemented the same way.

I doubt the OP is trying to store "magic numbers" and "ticket numbers" all in the same bag without being able to differentiated between the two types.

The OP is most probably trying to classify the orders by their magic number, and identifying them by their ticket number. That requires either separate arrays, or an array of a structure.

Since the OP has not explained their intent, this may even turn out to be an X/Y problem, and the ideal solution may not even need 2D or 3D arrays.

In the end it may just need a 1D array of a structure. However, it will be good for the OP to first learn how arrays work.

I fully agree....

A hashmap could be the right approach, or a red-black tree maybe.

EDIT: incredible how much energy we spent on explaining this. - Doesn't happen often that I actually give up...
 
Dominik Egert #: A hashmap could be the right approach, or a red-black tree maybe.

That is much too complex for the OP at this stage. 😅

 
Fernando Carreiro #:

That is much to complex for the OP at this stage. 😅

For sure...
 
Dominik Egert #:
People have really put in some energy to help you, I would say it is now up to you to understand what was given to you.

I agree with that statement and I appreciate it. Thank you all.

I think I understand it now. I even have written code that will compile without errors and it also seems to work.

I find MQL4 very frustrating. In my own world, I would do:

foreach order @AllOrders {
        set MyOrders order.ticket order.magic
}

if [array exists @MyOrders] {
        if [element exists 111111] {
                Print 1
        } else {Print 0}
}

or...

foreach order @MyOrders {
        if order.ticket == 111111 {
                return indexof order.magic
                break
        }
return -1
}

Or something like that.

The lack of foreach and simple lists in MQL4 forces me to build some hideous Rube Goldberg machines.

Thank you.

 
whoowl #:

I agree with that statement and I appreciate it. Thank you all.

I think I understand it now. I even have written code that will compile without errors and it also seems to work.

I find MQL4 very frustrating. In my own world, I would do:

Or something like that.

The lack of foreach and simple lists in MQL4 forces me to build some hideous Rube Goldberg machines.

Thank you.


We actually enjoy helping people.

Maybe you want to take a look at the standard library of MQL. You will find lots of little helpers which give you such convenience, maybe not exactly as flexible as python, but a lot better than writing everything yourself.


Take a precise look at the examples given, they help to understand the usage.

EDIT: sorry, the link is for MQL5. I actually would suggest, you switch to MQL5 and MetaTrader 5.

MT4 is a dead horse. Don't invest your time into it.
 

Fernando Carreiro #:


Since the OP has not explained their intent, this may even turn out to be an X/Y problem, and the ideal solution may not even need 2D or 3D arrays.



I exposed part of my intent. Let me put it another way:

Groups of orders share the same magic number.
I need to identify all of these groups.
I need to iterate over all orders and collect all their magic numbers.
Since those are groups, all magic numbers will be found more than once. I need to weed out those repetitions.
Once I have a clean list of all unique magic numbers, I want to iterate over all the orders that carry each magic number. i.e. iterate over each group.
I intend to apply multiple actions on each group. Which order is newest, which is oldest, which is profiting, which is losing, which is the most profitable etc.
For that I need a list. A list of lists actually.
MQL4 doesn't have lists, only arrays. And they are not very friendly.
Rube Goldberg machine ensues.

 
whoowl #:


I exposed part of my intent. Let me put it another way:

Groups of orders share the same magic number.
I need to identify all of these groups.
I need to iterate over all orders and collect all their magic numbers.
Since those are groups, all magic numbers will be found more than once. I need to weed out those repetitions.
Once I have a clean list of all unique magic numbers, I want to iterate over all the orders that carry each magic number. i.e. iterate over each group.
I intend to apply multiple actions on each group. Which order is newest, which is oldest, which is profiting, which is losing, which is the most profitable etc.
For that I need a list. A list of lists actually.
MQL4 doesn't have lists, only arrays. And they are not very friendly.
Rube Goldberg machine ensues.


See the EDIT of my last post...

Here you can find what you are looking for:

 
MQL5 is the worst programming nightmare I have ever encountered.
I ported some of my EAs to it and I never hated anything more in my whole life. Absolutely insane.
I will not migrate and neither will a very large number of people.
But thank you for the attention.
 
whoowl #MQL5 is the worst programming nightmare I have ever encountered. I ported some of my EAs to it and I never hated anything more in my whole life. Absolutely insane. I will not migrate and neither will a very large number of people. But thank you for the attention.

You are on the wrong track. Sooner or later you WILL need to migrate to MQL5. It is not a question of "if" but "when" (and it may be sooner than you think)

If you keep denying it, when the day comes, then you will have to rush to be able to switch over. If you do it NOW, you will still be able to take slowly.

When I did it, I also thought the MT5 trade system was a nightmare, but once I accepted that I needed to learn it, I slowly began to understand it and conquer it.

Now, I love it and consider MT4/MQL4 a pain and a drag, not to mention all the other advantages and opportunities that MT5/MQL5 offers.

I've stopped writing MQL4 EAs completely and I see no reason at all to go back. I don't regret taking the plunge, not one bit.

 
Fernando Carreiro #:

You are on the wrong track. Sooner or later you WILL need to migrate to MQL5. It is not a question of "if" but "when" (and it may be sooner than you think)

If you keep denying it, when the day comes, then you will have to rush to be able to switch over. If you do it NOW, you will still be able to take slowly.

When I did it, I also thought the MT5 trade system was a nightmare, but once I accepted that I needed to learn it, I slowly began to understand it and conquer it.

Now, I love it and consider MT4/MQL4 a pain and a drag, not to mention all the other advantages and opportunities that MT5/MQL5 offers.

I've stopped writing MQL4 EAs completely and I see no reason at all to go back. I don't regret taking the plunge, not one bit.

Yes, I understand. 25 lines of code instead of 4 to place an order is a very empowering thing.
That's 6 times as many advantages and opportunities.
How can anyone not love such an overflow of joy.
Reason: