Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1580

 
Papa Hoth #:

Thank you!

 
Papa Hoth #:
ObjectsDeleteAll(0,"",0,-1);//---------------------------------------->🔄 ChartRedraw();

Thanks, that's exactly the way the construct worked.

 
Zuko Lee #:

thank you very much :*

Look in PM, I sent the file yesterday.

 
Vitaly Muzichenko #:

Thanks, that's exactly how the design worked.

Why not delete by "autotrade" prefix ?

 
Artyom Trishkin #:

Why not delete by the prefix "autotrade" ?

Tried that, but it didn't delete it

ObjectsDeleteAll(0,"autotrade");

I should have added 0.

ObjectsDeleteAll(0,"autotrade",0);
 

Question: how to fill an array up to 100 elements nicely?

 double R=0.01;
 double Mas[100]={0};
  for(int i = 0; i < 100; i++) {
    if(i<10) Mas[i]=R;
    else if(i<18) Mas[i]+=R;
    else if(i<27) Mas[i]+=R*2;
    else if(i<35) Mas[i]+=R*3;
    else if(i<42) Mas[i]+=R*4;
    else if(i<48) Mas[i]+=R*5;
    else if(i<55) Mas[i]+=R*6;
    else if(i<60) Mas[i]+=R*7;
    else if(i<64) Mas[i]+=R*8;
    else if(i<67) Mas[i]+=R*9;
    else if(i<69) Mas[i]+=R*10;
    else if(i<71) Mas[i]+=R*11;
    else if(i<100) Mas[i]+=R*12;
  }
  Print(Mas[60]); // 0.08
 

It's like this.

The upper numbers are the number of times, but it can vary

double R=0.01;
double Mas[100];
  for(int i = 0; i < 100; i++) {
    if(i<10) Mas[i]=R;
    else if(i<19) Mas[i]=R*2;
    else if(i<27) Mas[i]=R*3;
    else if(i<34) Mas[i]=R*4;
    else if(i<40) Mas[i]=R*5;
    else if(i<45) Mas[i]=R*6;
    else if(i<49) Mas[i]=R*7;
    else if(i<52) Mas[i]=R*8;
    else if(i<54) Mas[i]=R*9;
    else if(i<55) Mas[i]=R*10;
    else if(i<100)Mas[i]=R*11;
  }


 
Vitaly Muzichenko fill an array up to 100 elements nicely?
Explicitly assign values to the array elements in a string. Then multiply in a loop if you need to change the lot. The cheapest, but longest. If you do it once, it probably makes no difference).
 
Valeriy Yastremskiy #:
Explicitly assign values to array elements in a line. Then multiply in a loop if you need to change the lot. The cheapest, but longest. If you do it once, it makes no difference I guess :)

It is necessary to write each element?

Somehow, it's possible to do it in loops. Yes, it's a one-time thing in OnInit()

 
Vitaly Muzichenko fill an array up to 100 elements nicely?

Since the indices on which the value of an element changes do not have a simple dependency (like each next 7 more than the previous one), we need to have them in the code. The multiplier that R is multiplied by is an arithmetic progression in increments of 1. So you can implement that code roughly like this:

double R = 0.01;
double Mas[100];
double bounds[] = {18, 27, 35, 42, 48, 55, 60, 64, 67, 69, 71, 100};

for(int i = 0, b = 0, f = 1; i < ArraySize(Mas); i++) {
   if(i == bounds[b]) {
      f++;
      b++;
   }
   Mas[i] = R * f;
}

ArrayPrint(Mas);

Note that for i < 10 and i < 18 the multiplier does not change, so the number 10 is not included in the bounds array of index bounds.

If the multipliers can change differently, they can be organised as an array too:

double R = 0.01;
double Mas[100];
double bounds[]  = {10, 18, 27, 35, 42, 48, 55, 60, 64, 67, 69, 71, 100};
double factors[] = { 1,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  12};

for(int i = 0, b = 0; i < ArraySize(Mas); i++) {
   if(i == bounds[b]) b++;
   Mas[i] = R * factors[b];
}

ArrayPrint(Mas);

One more thing like this. An array initialisation string of this form:

double Mas[100] = {0};

is guaranteed to initialise only the first element of the array with zero. Try executing this code:

double R = 0.01;
double Mas[10] = {R};

ArrayPrint(Mas);

and you will see in the output:

(EURUSD,H1) |   0.01000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000

For full initialisation, you must either list all 100 values for an array of 100 elements in brackets, or use the ArrayInitialize() function, for example.

But in your task, you don't need to initialise the array because you don't modify the existing initial values, but assign new ones each time.