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

 
Well, yes, that's obvious, but it's no good. It's not good to put input parameters into a class.
 
Вадим Мотеюнас:

Hello, could you please tell me why in this cycle my limit orders are only deleted if after placing a limit order another limit order has not been placed on the next bar, i.e. a limit order is only deleted if it is placed and then followed by two bars with no limit orders

Which order did you choose here?

for(i=0;i<=OrderTicket();i++)
 
Nikolay Gaylis:

And what order did you choose here?

I got the error, instead of OrderTicket() I also substituted a variable ticket to which OrderSend was assigned, it still does not delete anything, but how do I set up the loop to go through the limit orders and delete those that remained on the 2nd bar?

 
Вадим Мотеюнас:

I see the error, I also substituted a variable for OrderTicket() with ticket OrderSend, it still does not delete anything, but how do I configure the loop to go through the limit orders and delete those that remained on the 2nd bar?

This is optimal, at least this is how I learned mql

You find an EA in kodobase that approximately meets your requirements, look at the code and if the code is large and not clear, look for the next one.

After you have found a more understandable code, you start to study and edit it, so you quickly get an understanding of how it works

MQL5 Code Base: Советники
MQL5 Code Base: Советники
  • www.mql5.com
В разделе торговых советников вы найдете множество приложений, автоматизирующих вашу аналитику и торговлю. Здесь вы найдете самые разные приложения, обладающие различными торговыми алгоритмами и предоставляющими различную степень автоматизации. Имеются как простенькие эксперты, так и сложные торговые роботы, способные полностью автоматизировать...
 
Juer:
Well, yes, it's obvious, but it's not convenient. It's not nice to stick input parameters into a class.

Nevertheless, these values must somehow get there )). After all, most often the work of the class is based on the values the user specifies. But for some reason you don't want to do this. They will not magically appear there.

Usually, the input parameters at the stage of program initialization are transferred to a special structure. Most often these values are preprocessed (at least, checked for correctness). When a new instance of the class is created, a reference to this structure is passed to it. What is the inconvenience here?

 
Ihor Herasko:

Nevertheless, these values must somehow get there )). After all, most often the work of the class is based on the values the user specifies. But for some reason you don't want to do this. They will not magically appear there.

Usually, the input parameters at the stage of program initialization are transferred to a special structure. Most often these values are preprocessed (at least, checked for correctness). When a new instance of the class is created, a reference to this structure is passed to it. What is the inconvenience here?

The inconvenience is only in need to pass these values each time when creating an object. They are identical every time. All right, I will create it through the constructor but it is a private solution. The default constructor might contain these parameters for one EA and they are quite different for another EA.

Perhaps the solution is to make an entirely different class whose methods will return the parameters' values. Then I would only need to initialize this new class once. And in the original class, when creating an object (even in the same constructor), request parameter values from the new class.

 
Juer:

The only inconvenience is the need to pass these values each time an object is created. They are the same every time. All right, I will do it through the constructor, but it is a private solution. One EA's default constructor may have these parameters, while the default constructor for another EA is completely different.

Perhaps the solution is to make an entirely different class whose methods will return the parameters' values. Then I would only need to initialize this new class once. And in the original class, when creating an object (even in the same constructor), request parameter values from the new class.

It seems you heroically solve the invented problem.
 
Artyom Trishkin:
You seem to be heroically solving an invented problem.
I didn't read carefully about the problem, but something struck me that it was the same rake I stepped on and you helped me get it out of the way. Isn't it?
 
Alexey Viktorov:
I didn't read carefully about the problem, but something struck me that it was the same rake I was stepping on and you helped me get it out of the way. Isn't it?
Not exactly. You had no desire to initialize the void.
 
Artyom Trishkin:
Sounds like you're heroically solving an invented problem.

Yes, that's what I suggested above, in fact the same way you did with the structure, only more complicated.

-> And in the source class, when creating an object (even in the same constructor), request parameter values from the new class.

But in general I would have to pass a reference to this auxiliary class to the source class. In short, yes, the same as with the structure.

Create a container class, through which to create all these objects further. Then these parameters can be initialized once in this container class. That's what I think I'll do.