ArraySort() error on multidimensional array - page 2

 
J.P.Satrio #: Why not a good idea?
Alain is pointing towards the required overhead. It is significant and for 1000 objects not worth it. SQlite is in the milliseconds range, between some few and several hundred.

Any native solution will be much faster. Hash map, tree are in the region of a few microseconds.

Arrays are somewhere around a few nanoseconds.
 
Dominik Egert #:
Alain is pointing towards the required overhead. It is significant and for 1000 objects not worth it. SQlite is in the milliseconds range, between some few and several hundred.

Any native solution will be much faster. Hash map, tree are in the region of a few microseconds.

Arrays are somewhere around a few nanoseconds.

I see. @Alain Verleyen Since Dominik pointed out with his very first comment  that the original question is not an error, but a known issue, a limitation, the whole convo got off-topic :)

@Dominik Egert I'd love to use a struct array as it was my plan, since a professional programmer recommended to do so, and I love to experiment with solutions that I am not familiar with (yet) - the bigger the sense of accomplishment gets.

I'm still searching for the proper way to do the task, however, I didn't really get this question of yours:

"The main problem is, when you want to sort an array with structures, which member to use for the sorting?" - As I said, I thought I can sort the array by the ENUM_TIMEFRAMES values, as this is the first dimension. Why isn't it possible? Or is it a bad idea as well?

EDIT: sorting by the timestamp might be a better idea? The goal is to verify wether if an object exists at the examined point in time, for the current timeframe or not. /EDIT

If I want to sort it with a custom sort function, as you suggested, what would be the proper expression to sort it?

Without such knowledge, it seems easier for me to create mqlite requests at this point.

 
J.P.Satrio #:

I see. @Alain Verleyen Since Dominik pointed out with his very first comment  that the original question is not an error, but a known issue, a limitation, the whole convo got off-topic :)

@Dominik Egert I'd love to use a struct array as it was my plan, since a professional programmer recommended to do so, and I love to experiment with solutions that I am not familiar with (yet) - the bigger the sense of accomplishment gets.

I'm still searching for the proper way to do the task, however, I didn't really get this question of yours:

"The main problem is, when you want to sort an array with structures, which member to use for the sorting?" - As I said, I thought I can sort the array by the ENUM_TIMEFRAMES values, as this is the first dimension. Why isn't it possible? Or is it a bad idea as well?

If I want to sort it with a custom sort function, as you suggested, what would be the proper expression to sort it?

Without such knowledge, it seems easier for me to create mqlite requests at this point.

You will have massive issues implementing SQlite, if you don't get the basics...

You need to understand arrays, and structures.

A structure in an array is not a second dimension.

Please get familiar with the concept of structures, and then read about how arrays work.

Then understand the challenges with structures in arrays.
 
J.P.Satrio #:

I see. @Alain Verleyen Since Dominik pointed out with his very first comment  that the original question is not an error, but a known issue, a limitation, the whole convo got off-topic :)

@Dominik Egert I'd love to use a struct array as it was my plan, since a professional programmer recommended to do so, and I love to experiment with solutions that I am not familiar with (yet) - the bigger the sense of accomplishment gets.

I'm still searching for the proper way to do the task, however, I didn't really get this question of yours:

"The main problem is, when you want to sort an array with structures, which member to use for the sorting?" - As I said, I thought I can sort the array by the ENUM_TIMEFRAMES values, as this is the first dimension. Why isn't it possible? Or is it a bad idea as well?

EDIT: sorting by the timestamp might be a better idea? The goal is to verify wether if an object exists at the examined point in time, for the current timeframe or not. /EDIT

If I want to sort it with a custom sort function, as you suggested, what would be the proper expression to sort it?

Without such knowledge, it seems easier for me to create mqlite requests at this point.

If you post code that compiles, with your attempt to use arrays and struct, we will help.
 
Dominik Egert #:
You will have massive issues implementing SQlite, if you don't get the basics...

You need to understand arrays, and structures.

A structure in an array is not a second dimension.

Please get familiar with the concept of structures, and then read about how arrays work.

Then understand the challenges with structures in arrays.

As I said before, I am not a professional coder. I used to code basic MQL4 and MQL5 programs for myself for a few years now. I used arrays to access indicators, mostly, I know it is a sort of container to store data of same type effectively. I know it may have multiple dimensions, and now I know that I said something stupid about a structure and the dimensions of the array. This is the first time I use a struct. As I gain experience in coding, more and more complex tasks I can solve. I saw lists in R studio, and now I think that a struct works quite the same (or pretty similar in my understanding) way, but I haven't used it before in MQL. This might be the concept you mentioned? What do you mean how arrays work? The commands you mean, or the memory addressing, or what? What else do I need? The thing is, there is no language independent "general" coding school (online). I've enrolled to a MQL4 course on Udemy, did the same thing for a python course, also on Udemy, but these provide only to commands to work with these objects with some test tasks.

I was trying to figure out how can I put struct data into an array by myself, as the documentation says it IS possible, it also tells that doing so creates an array with one dimension, with every element being a "list" of the struct, but does not provide info on how to sort it or how to do any basic operations with it. I tried as I thought it might work, but I failed, since it does not work as it should be, or as a less experienced coder would expect, so I stuck there, and there is no documentation, no relevant pages exist on the web (at least I haven't find any). How could I proceed then if I can't research the topic?

I posted the question here because I thought some experts might point out what the solution might be, what I'm doing wrong, you tried, but I didn't get it. I didn't see a proper expression how can one compare eg. a string with another, or a date with another, with simple arithmetic operations, that's why I had no idea how to create a sorting function what you suggested in one of your early comments.

Sorry for blabbering. I'm just a bit desperate now, because I'm being refused for being unexperienced, and getting further away from the solution, after this much talk. That's why I said I'll stick to the sqlite approach, I could create working queries, inserts and replace requests, since it is well documented.

 
Alain Verleyen #:
If you post code that compiles, with your attempt to use arrays and struct, we will help.

I don't have any. That's why I posted my question here, in hope of getting some sort of guidance or help without having the solution already :) I have code that compiles for sqlte approach.

 
Alain Verleyen #:
If you post code that compiles, with your attempt to use arrays and struct, we will help.

When I tried to use arrays and struct, I got a complier error, posted in the beginning. But as Dominik pointed out it was not an error, and I couldn't figure out how to sort it with the suggested ways.

 
J.P.Satrio #:

I don't have any. That's why I posted my question here, in hope of getting some sort of guidance or help without having the solution already :) I have code that compiles for sqlte approach.

Then go with sqlite, and keep us posted.
 
J.P.Satrio #:

As I said before, I am not a professional coder. I used to code basic MQL4 and MQL5 programs for myself for a few years now. I used arrays to access indicators, mostly, I know it is a sort of container to store data of same type effectively. I know it may have multiple dimensions, and now I know that I said something stupid about a structure and the dimensions of the array. This is the first time I use a struct. As I gain experience in coding, more and more complex tasks I can solve. I saw lists in R studio, and now I think that a struct works quite the same (or pretty similar in my understanding) way, but I haven't used it before in MQL. This might be the concept you mentioned? What do you mean how arrays work? The commands you mean, or the memory addressing, or what? What else do I need? The thing is, there is no language independent "general" coding school (online). I've enrolled to a MQL4 course on Udemy, did the same thing for a python course, also on Udemy, but these provide only to commands to work with these objects with some test tasks.

I was trying to figure out how can I put struct data into an array by myself, as the documentation says it IS possible, it also tells that doing so creates an array with one dimension, with every element being a "list" of the struct, but does not provide info on how to sort it or how to do any basic operations with it. I tried as I thought it might work, but I failed, since it does not work as it should be, or as a less experienced coder would expect, so I stuck there, and there is no documentation, no relevant pages exist on the web (at least I haven't find any). How could I proceed then if I can't research the topic?

I posted the question here because I thought some experts might point out what the solution might be, what I'm doing wrong, you tried, but I didn't get it. I didn't see a proper expression how can one compare eg. a string with another, or a date with another, with simple arithmetic operations, that's why I had no idea how to create a sorting function what you suggested in one of your early comments.

Sorry for blabbering. I'm just a bit desperate now, because I'm being refused for being unexperienced, and getting further away from the solution, after this much talk. That's why I said I'll stick to the sqlite approach, I could create working queries, inserts and replace requests, since it is well documented.

OK. First, I did not mean to offend you. That is not the purpose of a forum.

Sometimes it is hard to make the transition between documentation and actual code. So let me try to give you some insights:

A struct or class is basically a custom definition of a variable.

A variable of primitive type is like int, datetime, double, long.These primitive types are known by the compiler and the CPU, so they can use these values directly. Do operations on them.

On the other hand, a complex type, like a struct or a class or union, is a sort of container for different primitive types. So there are several values in such. Since you can define them as you like, you also need to define how an operator is to be applied to such a container.

Example, if you define a struct, like you did, you have 3 values in there, now when you want to compare two of your structs, it is unclear to the compiler and CPU how the inner values of your struct are supposed to relate to each other. That's why you need to define this.

When you create an array made of your structs, only the outer representation of that struct is visible to any function you use on the array, but not the inner values, you have defined to be part of your struct.

Hence, a function that needs to compare these values in the array, like ArraySort, cannot operate on the elements of the array, because it has no idea about your structs. It will only see the outer representation of your custom definition.

The compiler is willing to help you to some degree, and will try to provide some basic operators for your struct definition. But he can only do that, if your struct has only certain members. As soon as there is a member inside your struct which definition is unclear, like a string, it cannot help you any more. This is the case as soon as one of the members is of variable size. Like an array, a string, a struct inside of a struct, for example.

I will post some code later to show you what I mean exactly.

In the meantime, try to find on this forum some threads about "MQL5 the basics" or "MQL5 how to get started"

And here are some links to the documentation:





 
Dominik Egert #:
OK. First, I did not mean to offend you. That is not the purpose of a forum.

Sometimes it is hard to make the transition between documentation and actual code. So let me try to give you some insights:

A struct or class is basically a custom definition of a variable.

A variable of primitive type is like int, datetime, double, long.These primitive types are known by the compiler and the CPU, so they can use these values directly. Do operations on them.

On the other hand, a complex type, like a struct or a class or union, is a sort of container for different primitive types. So there are several values in such. Since you can define them as you like, you also need to define how an operator is to be applied to such a container.

Example, if you define a struct, like you did, you have 3 values in there, now when you want to compare two of your structs, it is unclear to the compiler and CPU how the inner values of your struct are supposed to relate to each other. That's why you need to define this.

When you create an array made of your structs, only the outer representation of that struct is visible to any function you use on the array, but not the inner values, you have defined to be part of your struct.

Hence, a function that needs to compare these values in the array, like ArraySort, cannot operate on the elements of the array, because it has no idea about your structs. It will only see the outer representation of your custom definition.

The compiler is willing to help you to some degree, and will try to provide some basic operators for your struct definition. But he can only do that, if your struct has only certain members. As soon as there is a member inside your struct which definition is unclear, like a string, it cannot help you any more. This is the case as soon as one of the members is of variable size. Like an array, a string, a struct inside of a struct, for example.

I will post some code later to show you what I mean exactly.

In the meantime, try to find on this forum some threads about "MQL5 the basics" or "MQL5 how to get started"

And here are some links to the documentation:





Thank you very much for the detailed explanation. I also checked the 3 links you provided - for the first one, I knew most of it, therefore I did not check back there to realize a structure is considered a variable but as a complex one, but I did check its docs page, to get familiar with the syntax and such, when I was studying its properties. The second one was more or less known for me, but the third one, was quite a deep dive,  its more of a complex topic for me at this time.

Last night I was added the complete funcionality with the database approach. I'm currently adding a feature to add masses os records to test performance drop.

I'll review the suggested pages in the near future, if/when I'll decide to change the code to the array approach, if the change is justified by a significant drop in performance, however, I know that would be the best practice, or a more elegant way to solve this problem.

Thank you very much for your guidance. I'll come back to you soon with the outcome.