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

 
andrey46:
I do not know why the Expert Advisor in the Strategy Tester works fine, places orders, etc., but in the real account, although the robot is active, orders are not placed

You need to read the magazine, there may be an answer

 

Can you tell me how to get this -

double w = 18.2

get this -

int w = 18
 
TrederMT5:

Can you tell me how to get this -

get this -

int w1;
double w = 18.2;
w1=(int)w;
w=round (w);

An explicit type conversion.

You can also round an integer from a non-integer, but the double will be 18.0

 
scomoroh:

Then I will repeat the question.

The expression

if (izmb>b ||izmb<b || izms>s || izms<s)

is identical to this one:

if (izmb!=b || izms!=s)

And if you want to store something, do it in a global variable.

This is the one that is declared outside the body of the function.

int izmb=0, izms=0;


void OnTick()
   {
   .........
 
Valeriy Yastremskiy:


Thank you
 

Good day to you all!

Question about MQL4. Here is a simple code

double LoY[31][31],LoU,LoU1;
int S,S1,S2;
void OnTick()
{
if (Minute()==20&&Minute()!=S1)
{
ArrayFill(LoY,0,31,0.5555);
S1=Minute();
}
//***************************************************************
if (Minute()!=S)
{
LoY[0][0]=Bid;
ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND);
Print("----LoY[0][1]-- Горизонтально ---  [0}  ",  LoY[0][0],"  [1] ",   LoY[0][1],"  [2] ",   LoY[0][2],"  [3] ",   LoY[0][3],"  [4] ",   LoY[0][4],"  [26] ",   LoY[0][26],"  [27] ",   LoY[0][27],"  [28] ",   LoY[0][28],"  [29] ",   LoY[0][29],"  [30] ",   LoY[0][30]);
Print("----LoY[1][0]-- Вертикалььно ---  [0}  ",  LoY[0][0],"  [1] ",   LoY[1][0],"  [2] ",   LoY[2][0],"  [3] ",   LoY[3][0],"  [4] ",   LoY[4][0],"  [26] ",   LoY[26][0],"  [27] ",   LoY[27][0],"  [28] ",   LoY[28][0],"  [29] ",   LoY[29][0],"  [30] ",   LoY[30][0]);
S=Minute();
}
}

It creates a two-dimensional array and fills it with values. There are two functions in the code that interest me - ArrayFill(LoY,0,31,0.5555); and ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND); According to the Reference Manual, both functions work with two-dimensional arrays.ArrayFill() works strictly on arrays filled horizontally, the Reference book specifies that it fills the array with values strictly from left to right (not top-down or bottom-up). ArraySort() sorts a two-dimensional array by the first dimension. The Reference does not say whether it sorts horizontally filled or vertically filled arrays. Judging by the execution of my code, ArraySort() sorts only vertically filled arrays. It seems these two functions cannot handle one and the same array in one program.

Q. It is important for me, that ArraySort() function would work correctly . So, can ArraySort() be configured to sort horizontally filled arrays, with which ArrayFill() works? Or the sorting function from MQL5, which works in MQL4, can help me instead? Or is there a function that converts a horizontally filled array with all its values to a vertical one, in a nutshell, how to make my program sort an array horizontally

Note. Using a loop instead of ArrayFill() does not work for me.

Thanks for the help.

 
ANDREY:

Good day to you all!

Question about MQL4. Here is a simple code

It creates a two-dimensional array and fills it with values. There are two functions in the code that interest me - ArrayFill(LoY,0,31,0.5555); and ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND); According to the Reference Manual, both functions work with two-dimensional arrays.ArrayFill() works strictly on arrays filled horizontally, the Reference book specifies that it fills the array with values strictly from left to right (not top-down or bottom-up). ArraySort() sorts a two-dimensional array by the first dimension. The Reference does not say whether it sorts horizontally filled or vertically filled arrays. Judging by the execution of my code, ArraySort() sorts only vertically filled arrays. It seems these two functions cannot handle one and the same array in one program.

Q. It is important for me, that ArraySort() function would work correctly . So, can ArraySort() be configured to sort horizontally filled arrays, with which ArrayFill() works? Or the sorting function from MQL5, which works in MQL4, can help me instead? Or is there a function that converts a horizontally filled array with all its values to a vertical one, in a word, how to make my program sort an array horizontally

Note. Using a loop instead of ArrayFill() does not work for me.

Thank you for your help.

Did you notice the

note

ArrayFill

Multidimensional array when processing with ArrayFill() appears as one-dimensional, for example, array[2][4] is processed as array[8], so when working with this array it's acceptable to specify index of initial element equal to 5. So, calling ArrayFill(array, 5, 2, 3.14) for array[2][4] will fill array[1][1] and array[1][2] with 3.14.


This string

ArrayFill(LoY,0,31,0.5555);

will fill the array with exactly one line.

As for verticality/horizontality, this is how you would hold your head looking at the entry. Look at the Excell table and everything will become clear. If column "A" is filled with values, you get a one-dimensional array. How is it arranged? Right... horizontally, because I'm looking at it lying on the sofa.........

 
Alexey Viktorov:

Have you noticed the

note

This line

will fill the array with exactly one line.

As for verticality/horizontality, it's how you would hold your head looking at the entry. Look at the Excell table and everything will become clear. If column "A" is filled with values, you get a one-dimensional array. How is it arranged? Right... horizontally, because I'm looking at it lying on the couch.........

Thanks for the reply. Got everything you wrote. But didn't understand the meaning of what you wrote in terms of my problem.

By horizontal two-dimensional array in my code I mean when there are 2 rows under index 0 or 1 and columns under indexes 0 to 30. The first dimension is denoted as[0][0],[0][1],[0][2], ...[0][30] The second dimension is denoted as[1][0],[1][1],[1][2], ...[1][30]

By vertical two-dimensional array in my code I mean when there are 31 rows indexed 0 to 30 and 2 columns indexed 0 and 1. The first dimension is denoted as[0][0],[1[0],[2][0], ...[30][0] The second dimension is denoted as[0][1],[1][1],[2][1], ...[30][1]

If you execute my code, the array will fill vertically. And the ArraySort() function will sort the array as it should.

QUESTION Why won 't ArrayFill() function work in this case ? After all, I asked it to fill the first dimension of the array (31 items) with the same values 0.5555 on the twentieth minute.
Thanks for your help.

 
MakarFX:

I would try that.

Thank you for your help. I'll give it a try.

 
Aleksei Stepanenko:

the expression

is identical to this one:

And if you want to store something, do it in a global variable.

This is the one that is declared outside the body of the function.

We wanted to check the conditions of search for entering the EA not every tick, but only if another order is opened or closed by another EA or manually (in order to avoid unnecessary load on the processor). This is why we need to check if the number of orders corresponds to each tick.

Can we use a static variable ? Will the program work in such a form?

    double LB=0,LS=0;
    int b=0,s=0;
    static int izmb, izms; // статическая переменная
   
   for (int i=0; i<OrdersTotal(); i++)
   {    
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      { 
         if (OrderSymbol()==Symbol())
         { 
            int tip = OrderType(); 
            if (tip==OP_BUY)             
            {  
               LB  += OrderLots();
               b++; 
            }                                         
            if (tip==OP_SELL)        
            {
               LS  += OrderLots();
               s++;
            } 
         }
     }
     
   }
    if (izmb!=b || izms!=s){ 
    izmb=b;
    izms=s 
           // далее идут условия для открытия ордера.
     }
Reason: