Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 828

 
Artyom Trishkin:

It's not clear what we need in the end - some odd thoughts.


This is two questions in one post while solving the same problem :-)

1. How to return an object creation error from a function that should return data

2. Is there a way to loop through the positions for a given symbolwithout using PositionsTotal every time?

 
psyman:


This is two questions in one post while solving the same problem :-)

1. How to return an object creation error from a function that should return data

2. Is there a way to loop through the positions for a given symbolwithout using PositionsTotal every time?

1. Why should an object creation function which is just supposed to create an object and return true on success or false on error return something else? It shouldn't. The function must do one thing and return the result of its work. Or, if you want to make a monster, return data via variables by reference.

2. It depends on what type of account you have.

3. Just open the help at last - there are many "wondrous discoveries" there

 
Artyom Trishkin:

1. Why should an object creation function that is just supposed to create an object and return true if it succeeds, or false if it fails, return anything else? It shouldn't. A function should do one thing and return the result of its work. Or, if you want to make a monster, return data via variables by reference.

2. It depends what type of account you have.

3. Just open the help at last - there are a lot of "strange discoveries" there


I see what you mean. Thank you, I will simplify the code.

Account type is hedge.

May be the questions seem simple, but they appear after reading the help, not all details are described there, I have to search for details in articles or here.

 
Roman Shiredchenko:

Comrades - look at the indicator for correctness. There is one formula Value = (Open[0]-SMA(P,n))/SMA(P,n))*100%.

I put it on the chart - it calculates and plots everything. I start to check its value on some bar using the calculator - it doesn't coincide with the one I drew...

Here's an example, I'm calculating Open 1,0178, MA(13) 1,0182 using the formula ((1,0178-1,0182)/1,0182) * 100% - the result on the calculator is -0.0393. And the MT4 chart shows -0.0929. Is it an error in the code or the calculator does not correctly calculate some values there? Please help. I am attaching the indicator.

You have it in Open[0] formula, that's how it should be done.

 
Alekseu Fedotov:

You have Open[0] in your formula, so it is designed that way.

Well, yes. That's how I'm looking at the opening prices... There's an opener and a cloze... confused...
 
Seric29:
How to fill a 4-dimensional array of the format int Mas[1][2][2][2] with values, how to assign a value to each cell of the array, in this case, there is a 2-dimensional array int Arr[1][2]={3,4}; how to fill a 4-dimensional?

Use an array of structures, it is many times easier, clearer and more productive in terms of program execution

struct My_St
{
   datetime tm; 
   int      mg;    
   double   tp;     
   double   sl;     
};
My_St st[];
 

I have several tools, analytically labelled.

I want to change the colour scheme of them.

I don't want to do it by hand, I want to do it in a clever way.

Is there any way I can do it? For example, all the text I have is black and I want white.

Thank you

 
Roman Shiredchenko:
Well, yes. That's how I'm looking at opening prices.... There's an opener and a clause there it looks like... confused...

I don't know, that's the idea.


What was the idea here,

if we take the value of any bar (from History =5000; // the number of bars in the calculated history)

then the open of the same bar, but not zero,

your formula(Open[0]-SMA(P,n))/SMA(P,n))*100%


Roman, good luck

 
Igor Makanu:

Multidimensional arrays are usually filled in loops with the right values - it's harder to make a mistake, for a four-dimensional array it should be something like this, but I could be wrong:

No, you're not wrong. My mistake was writing it like this.

A[1][2][4][2] = {{{1,2}, {0,2}, {1,2}, {1,2}},{{1,2}, {1,2}, {1,2}, {1,2}}}, 

I should have written it like this.

A[1][2][4][2] = {{{{1,2}, {0,2}, {1,2}, {1,2}},{{1,2}, {1,2}, {1,2}, {1,2}}}}, 

There are 4 brackets around the edges and I have 3. It reads like this.

A[1] - означает 1ну строку, один ярус
A[1][2] 2ка в следующих скобочках говорит о том что мы имеем дело с 2мя 3ёх-мерными массивами, другими словами, это как 2 параллельных мира
A[1][2][4][2] - последующие [4][2] описываю 3ёхмерный массив, т.е. каждый из массивов имеет 4 столбца, и в каждом по 2 значения вот пример
{{1,2}, {0,2}, {1,2}, {1,2}} 4 столбца в каждом по значения

In general, thank you, if I live long enough, I'll work with it.

 
Seric29:

When you pass a structure to a function, you have to write a function for each structure, so the function is too static and lacks versatility. But structures have a positive side, you can combine arrays of different types into structures and read it as one wholemultidimensional array, but unfortunately I lost the link to this site where it was shown how to do it. To tell the truth I'm not very good with structures, much less text if the global variable declaration than a point to access the fields of the structure, also I do not understand the classes, I reread the material many times in the last little bit more understood, but explained very complicated and cumbersome, too scientific phrases used in the explanation, so I basically did not understand much of the material, and what exactly dynamic objects can be done to me too.