Questions on OOP in MQL5 - page 29

 
Dmitry Fedoseev:

Yes, here's another question that keeps coming up and has no clear answer. When you need to inherit your own class - what's better to do, inherit it or write a new extended version of your class.

It all depends on the general idea of what you want in the end, imho

if you plan to use the class somewhere else, you need to make it complete without inheritance

in my example, the CError class can get GetLastError(), unset with a description and return the value (int) of the error. I plan to use it everywhere, anyway, it only has a constructor that defines the language in a static variable and the case that returns the error text

But there is another useful method - bool ServerDisable(); - it defines server availability (multiplatform MT4/МТ5 code), very good function, it seems to be needed somewhere else in the code, but I thought, that I will use it for trade operations all the same - I put it in COrder class

.....

and if I want to use it for trailing? .... - plenty of space for imagination, but in the end it will be used as an object in COrder - where else could it be used?


imho, everything looks cumbersome, it's easier to include the service function library with the linker, and the compiler won't include the unused parts into the executable by itself

the whole class would be quite compact in procedural style, i showed an example for a function to open an order that can store in static constants the order volumehttps://www.mql5.com/ru/forum/85652/page17#comment_12805083

 
Dmitry Fedoseev:

Is it really important to stay within limits? If it's important to stay within limits, you can write functions too.

I was answering in the context of your message that if you don't use classes, you'll have to bother with inconvenient call signatures. I showed that you don't have to bother.

 
Alexey Navoykov:
What prevents me from sending the name of the symbol to the constructor, making the class flexible and versatile? You don't consider the possibility of portfolio trading as a matter of principle?

considering everything,

But so far I have stuck with research - now I'm almost ready to research 1000 and 1 ways of MM and all sorts of tricks with order systems )))

But I still think it would not be too flexible in the end, I have already written 2 times above that a procedural style + small classes with well-tuned functions of order handling would be better.

i will switch to testing my ideas for now and then i will see what i edit often in the code and what i leave untouched

 
Igor Makanu:

.....

What if I want to use it for trailing? .... There is more room for imagination, but in the end it will still be used as an object in the COrder - where else could it be used?


Trailing bars are separate because they have nothing to do with the main logic. They may or may not exist at all.

***

Trailing bars and other similar maintenance functions should be made as descendants of one class, and their instances should be created in an array. If a function is enabled, an instance is added to the array and executed. If all of the functions are disabled, the array is empty and unnecessary ifs are not executed. You can insert at least 100 trailing bars into the EA, and it will not affect the speed of its execution.

 
Alexey Navoykov:
That's not the way to do it. You have to at least call both Bid() and Ask(). Your code looks like just a variable, making it appear that its value remains unchanged, when in reality it is not.

alas, it has always been done this way, in MT4 it is still Bid and Ask and no whims of the Creator to ruin this simple use and getting current prices ;)

fxsaber:

I have the following scheme where I haven't experienced any problems.

  1. I write TC only for Tester. No logs, error handlers and other stuff. The code is very concise, understandable and amenable to changes, if done through OOP (but not crucial). I have already posted the example in KB. The bonus is the fast optimization.
  2. The main thing is that it should be available for the tester and in independent blocks. The generation of trading signals - one block. Signal trading - another block.
  3. The transfer to the real account is always done in several one and the same moves. The TS is placed in a virtual environment without any code changes. Several TS may be placed in one environment or each TS in its own environment, then the OOP becomes especially convenient. Then we take a copier (the Market is full of them, so people are good at copier-logic), which simply copies deals/orders from the virtual environment to the real one.
  4. With this scheme, writing TS is quick and easy. Transferring to real (which is rare really) is always done in a uniform, quick and clear way.

are we talking about this code?https://www.mql5.com/ru/code/22770

really like the implementation. really good for tester and optimizer, i will probably use it as a base, the code is short and readable, to be honest i am surprised to read your code, you have much more sophisticated style of writing, i usually plug and play, i know i can not understand the logic

 
Igor Makanu:

alas, it has always been like that, in MT4 it remains Bid and Ask and no creator's whims destroy this simple use and getting current prices ;)

But their values are invariable within the current event processing (unless you call RefreshRates forcibly of course). So they are variables, not functions. And your functions look like variables

 

Give FPs a real task of managing and processing arrays of hundreds of megabytes or gigabytes of data and all their fairytale message model(data is immutable) will go to hell.

These are theorists, just in time to break out of real-world tasks and broadcast in their fictional universe :) telecom stories are dumbass data passes.

In fact, the only chance to fight complexity is to pack it into objects.
 
Alexey Navoykov:

But their values remain unchanged within the current event processing (unless you call RefreshRates forcibly). So, they are variables, not functions. And your functions look like variables

I don't even know how to explain the problem discussed in your example, I'll try to explain it humanly - for me, as a person who had the first Pentium-90 PC, it pains to see that in order to get a convenient use, an extra function call, which implies putting values of registers on stack, will be added... and ...here we go.

I know that now everything is cached repeatedly at the processor level, and I suspect that compiler developers will make the "function call from function call" more efficient

then your example should look like this:

#define  Ask(dummy) SymbolInfoDouble(_Symbol,SYMBOL_ASK)
#define  Bid(dummy) SymbolInfoDouble(_Symbol,SYMBOL_BID)

void OnStart()
  {
   Print("Ask = ",Ask());
   Print("Bid = ",Bid());
  }

Or like this:

#define  Ask(symbol_) SymbolInfoDouble(symbol_,SYMBOL_ASK)
#define  Bid(symbol_) SymbolInfoDouble(symbol_,SYMBOL_BID)

void OnStart()
  {
   Print("Ask = ",Ask(_Symbol));
   Print("Bid = ",Bid(_Symbol));
  }
 
Dmitry Fedoseev:

Vasiliy, this article would be very useful for you - not to torture yourself by squeezing out OOP for the sake of OOP.

I have an idea of functional framework for MT. There will be almost no OOP there. Only functions, "monads" and other pseudo FP functionality. I'm writing everything in quotes, since it's impossible to make full-fledged FP in MQL.

 
Dmitry Fedoseev:

Comments are unnecessary.

you do not like each other so much, or maybe it's the opposite of 2 gays looking for a way out for yourselves)

i liked your articles by the way, the expert's are lame, weak, but i like him just as much,

and I'm not gay.