Less code, more action... writing an EA - page 5

 
Vladimir Simakov:

What do you want to get out of it? To be honest, I don't understand. At first I thought a la framework was intended, but no, no wrapper classes for indicators, orders, standard algorithms of decision making, nothing. Although much more readable is this construct: fast.Get(2)>=slow.Get(1); (it's just for the sake of example), but the declaration:

CMA fast=new CMA(NULL,0,12,...);

CMA slow=new CMA(NULL,0,100,...);

Now we can discuss it, while you, IMHO, are trampling on the spot.

for example, instead of fast.Get(2)>=slow.Get(1); it's quite legal and working code:

table[FAST_MA][1] >=table[SLOW_MA][2]

it works like a spreadsheet, with excel. It is summarized in a table, not by individual handles, because the data (formulas) can be interdependent.

It could be done (just haven't done it in a specific library yet):

fast=table[FAST_MA]; slow=table[SLOW_MA];

and then fast[2]>slow[1] is even easier to read

and all internal calculations will be performed "on demand".

 
Maxim Kuznetsov:

also for example, instead of fast.Get(2)>=slow.Get(1); quite legal and working code:

table[FAST_MA][1] >=table[SLOW_MA][2]

it works like with a spreadsheet, with Excel. It is summarized in a table, not by individual handles, because the data (formulas) can be interdependent.

It can be done (just haven't done it in a specific library yet):

fast=table[FAST_MA]; slow=table[SLOW_MA];

and then fast[2]>slow[1] reads even easier

and all internal calculations will be done "on demand"

It's kind of a crutch. To the wipe buffers, which the terminal will create anyway, we also add arrays of doubles. I understand that you will reserve memory for them to the full depth of history (for M1 USHORT_MAX, if I remember correctly *8 bytes) or do you plan to use expensive ArrayResize regularly in the process?
 
Vasiliy Sokolov:

I agree, it is very difficult to read your code, even if you know the language.

In fact, this rule works for any third-party code. The only question is which code is not hard but easier to read.

And here it is easier to read and edit almost always MQL4 code. The developers guessed it once.

 
fxsaber:

In fact, this rule works for any third-party code. The only question is which code is not difficult but easier to read.

And it is easier to read and edit almost always MQL4 code. The developers guessed it once.

But let me ask you a question. What was the guess? Standard C/C++, except for specific queries related to trading and charts, can be considered as "windows.h" in C++.

So, respect to developers for not reinventing the wheel, although forbidding links is an unequivocal minus, when I fell in C/C++ after mql, I could not rejoice. That's why, if a miracle happens, maybe you should consider, as an alternative, like C# usafe, especially for people like me, like if you want to hit the wall, kill yourself, we warned you.

 
Vladimir Simakov:

Let me ask you a question. What is the guess?

Kodobase is full of MT5 EAs which are remakes of MT4 EAs. Compare the code of the original and the remake.


Obviously, figuring out the logic of the MT4 original is much easier. But it is even easier when there is a need to correct something in TS. It is not for nothing that MQL4 is a standard for discussion of trading algorithms on forums all over the world. No other language, but MQL4. And it has played a great role in the popularity of MT4, not the other way around.


And if we talk about MT5 conversions, they are crooked - they do not always work. A simple example. You send a request to close a position but receive a trade order instead of closing it. There are a lot of tricks that have to be solved in order to go to the real account. With MT4 it's simple and reliable.

Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
fxsaber:

The kodobase is full of MT5 EAs which are remakes of MT4 EAs. Compare the code of the original and the remake.


Obviously it's much easier to understand the logic of the MT4 original. But it is even easier when there is a need to correct something in TS. It is not for nothing that MQL4 is a standard for discussion of trading algorithms on forums all over the world. No other language, but MQL4. And it has played a great role in the popularity of MT4, not the other way around.


And if we talk about MT5 conversions, they are crooked - they do not always work. A simple example. You send a request to close a position but receive a trade order instead of closing it. There are a lot of tricks that have to be dealt with in order to go to the real account. With MT4 it's simple and reliable.

So it's crazy to work with orders/positions by analogy. In mql4 I have one wrapper class for that, in mql5 I have two different ones, because in mt4 it is one entity, and in mt5 there are two different ones, now the plan is to implement a wrapper class on them and forget about working with orders, like I have for half a year on mql4.
 
And yes, mt5 was created to work on the exchange, and there is a different principle of working with orders/positions, so learn the math and do not whine, everything works fine and smoothly there, but the trading mechanics of the exchange and forex have to learn first and take into account their differences. All that is needed to do this, the developers have given and described in the docks, and then it's up to you.
 
Vladimir Simakov:
So it's a nonsense to work with orders/positions by analogy. I have one wrapper class for it in mql4 and two different ones in mql5 because it is one entity in mt4 and two different ones in mt5. Now I plan to implement a wrapper class for them and forget about working with orders like I have for half a year in mql4.
Vladimir Simakov:
This is why we should learn the same thing in maths and not bitching, everything goes well and works fine there, but first we have to learn trading mechanics of exchange and Forex and consider their differences. All that is needed to do this, the developers have given and described in the docks, and then it's up to you.

Try to broaden your horizons as what you have written is really whining.

 
Vladimir Simakov:
It seems to be a crutch. Besides wipe buffers, which the terminal will create anyway, we also add arrays double. I understand that you are going to reserve memory for them to the full depth of history (for M1 USHORT_MAX, if I remember correctly *8 bytes) or do you plan to use expensive ArrayResize regularly in the process of operation?

I allocate memory to them, of course. To a depth no greater than that needed for calculations and debugging. In the given fragment it is 30, which is more than enough. If somewhere it will be necessary to calculate for example standard deviation of depth 50, then the cache should be increased. And it is only for the sake of speeding up calculations.

 
fxsaber:

Try to broaden your horizons as what you have written is really whining.

I'm fine, but this is how the connection between position and order is implemented in mql5 (as part of the last work it was, in principle, in this form it will already be included in the library for hedge accounts).

CHedge::CheckOrder(void){
   if (!CheckPointer(cOrder)) return;
   switch(cOrder.Control()){
      case ORDER_FULL:        cPosition=NewPosition(cOrder);
      case ORDER_REMOVE:
      case ORDER_ERROR:       delete cOrder;}}
Reason: