Is the linear deceleration a programming error or a feature of MT4? - page 4

 

the construction below alone is worth it.


    bool Ok=true;
     for(i=OrdersTotal()-1;i>=0;i--){//проверяем наличие ордеров
      if(OrderSelect(i,SELECT_BY_POS)){
       if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic){
        if(OrderType()==OP_SELLSTOP||OrderType()==OP_SELLLIMIT){
         Ok=false;
        }}}}

a little bit more

    bool Ok=true;
    for(i=OrdersTotal()-1;i>=0;i--){//проверяем наличие ордеров
      if(OrderSelect(i,SELECT_BY_POS)){
        if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic){
          if(OrderType()==OP_SELLSTOP||OrderType()==OP_SELLLIMIT){
            Ok=false;
          }
        }
      }
    }

and we already know what is executed in what sequence. This is just formatting. But you can also break down the code into logically consistent operations and separate them into separate functions. Thus relieving the main algorithm from piles of jumbled code.

 
micle:

The problem is duplication of code, excessive number of conditional statements. In fact, the code consists of 99% of lines somehow including the conditional If operator; I'm sure if you look into it, the number of comparisons could be reduced 10 times. Not only does this slow down execution, but this code is also hard to read. A person who makes additions to it has at least 2 main tasks:

1 - not to break it

2 - Add necessary functionality.

Unreadable code anyway causes additional duplication of all sorts of checks and comparisons - and this again is additional expense. Looking through the code, I personally remember myself about 25 years ago, when I just started programming, and I learned it from the manual to Atari 800XL PC without any teacher, just because it was interesting.

Of course, it is interesting, what "if" we are talking about, there is probably my TOR - where I write "if so, then so", and the programmer interprets it in the code, and there is "if" related to direct work with orders, and there are a lot of operations with orders...

Of course, I thought it was about some sort of loop, the execution of which leads to multiple checks of order conditions. And it turns out that the situation can only be corrected by rewriting the code from scratch?

 
micle:

the construction below alone is worth it.

a little bit more

and we already know what is executed in what sequence. This is just formatting. But you can also break down the code into logically consistent operations and separate them into separate functions. Thus, it will relieve the main algorithm from piles of jumbled code.

But doesn't it affect the performance in any way?

 
micle:

Trouble with duplicate code

Duplication has nothing to do with it and nothing to do with ifs. The real slowdown comes from working with warrants.
 
micle:

the construction below alone is worth it.


a little bit more

and we already know what is executed in what sequence. This is just formatting. But you can also break down the code into logically consistent operations and separate them into separate functions. Thus relieving the main algorithm from piles of jumbled code.

Very strong arguments, your code, where can I see an experienced programmer?
 

rev 1.1

To set a stop loss and filtering of pending orders we use two options of using a mirror MA.
maMirror - calculated using the standard iMA function, works once per bar, the data is taken from the bar open prices
Calculation algorithm:

For sell:
initial calculation point maMirror=iMA+pipsXHmaM(o/b)
subsequent calculation point maMirror=maMirror(1)-(iMA(0)+pipsXHmaM(o/b)-iMA(1)+pipsXHmaM(o/b))
the calculation is completed after the calculation end point.

For purchase:
initial calculation point maMirror=iMA-pipsXHmaL
subsequent calculation points maMirror=maMirror(1)-(iMA(0)-pipsXLmaM-iMA(1)-pipsXLmaM)
calculation is terminated after the calculation end point.


To simplify the ToR it is necessary to put two blocks of calculation, which will be independent of each other in operation and variables, and set by the user
maMBlock=0 - do not use blocks (standard stop loss is used)
maMBlock=1 - use block #1 only.
maMBlock=2 - use block #2 only (standard stop loss is used)
maMBlock=3 - use both blocks

Block #1
Calculating stop loss. Stop loss is recalculated and the order is updated at every bar by the value of maMirror.
1 The variable StartPoint is used to determine the starting point for calculation, if StartPoint=1 (calculation is performed after maT is touched), if StartPoint=2 (calculation is performed after the order is opened).
1.1 If StartPointO=1 then the calculation is completed after maT is touched;
1.2.If StartPointO=2, settlement finishes after the order is closed;
1.3 If stop loss cannot be set by maMirror, the order is closed.
1.4. Levl_Zerro=0 (not used), Levl_Zerro!=0 (stop loss is updated to the maximum specified value counting from the opening price, a negative value means that the stop loss is converted to a positive value)

Block 2
Calculation of filtering for pending orders
0.1 To buy an order, the order is placed if maMirror>open price of the pending order
0.2 To sell, the orders are placed if maMirror<open price of the pending order
1 The StartPoint variable is used to determine the starting point for the calculation if StartPoint=1 (calculation is performed after maT is touched), if StartPoint=2 (calculation is performed after the order is opened).
1.1 If StartPointB=1, the calculation is completed after maT is touched;
1.2 If StartPointB=2 (settlement finishes after the order closes);
2. If maMirrorDell=0 (not used) maMirrorDell=1 (all open orders are deleted if the conditions from point 0 do not match)

User variables
maMirrorO (settings by iMA)
maMirrorB (iMA settings)
StartPointO
StartPointB
pipsXHmaMo
pipsXLmaMo
pipsXHmaMb
pipsXLmaMb
maMBlock

maMirrorDell

Help estimate assignment, customer wants a new job, don't know how much to estimate) As I'm not a programmer, I'm an aerospace academy engineer)

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
The first and perhaps foremost problem is that the code is unreadable and unstructured. You may have quite a clear ToR. If you understand the ToR and write the code in the right direction, it (as a rule) gives a significant gain in speed of execution, but it also costs other money.
 
-Aleks-:

Does it affect performance in any way?

In this particular example, it has no effect. I don't want to deal with such formatting in the entire EA script, nor do I want to reformat it completely
 
zfs:
Very strong arguments, your code, where can I see an experienced programmer?
My code is not in the public domain. Commercial developments work on and around highly loaded web servers. In particular, my code calculates traffic jams on roads in "several" cities as part of the DorogaTV project
 
TheXpert:
Duplication has nothing to do with it, neither do ifs. The real slowdown is given by working with orders.

Working with orders in TK code, or maybe TK itself, or MT4 working with orders in general?

Reason: