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

 
Artyom Trishkin:
The time to open a position, the time to close a position - the candle on which that time is and the time to open that candle.

A big arigato!

I'll get into it!!!

 
Alexey Viktorov:

You can also use the flag.

Declare static bool variable or variable of global level, let it be flag. Order opened - flag = true, a new candle opens - flag = false and add this flag to the condition of order opening.


A big arigato!

I'll get into it!!!

 
Is it possible to set the background colour for an OBJ_LABEL object? Or is it possible to write text on a blank background of some colour?
 
Andrei:
Can I set background colour for OBJ_LABEL object? Or is it possible to write text on a plain background of some colour?

The background foran OBJ_LABEL object is the background of the graphic,

and the text colour can

Changes the value of the specified object property.

boolObjectSet(
stringobject_name,// object name
intindex,// property identifier
double value//value
);


Identifier of the OBJPROP_COLOR property

 
 
Victor Nikolaev:

I won't say anything about women. But the advice was good.

I didn't say it was bad advice. I only continue to say that there are always several options and everyone is free to choose his or her own. And sometimes even change the options depending on the situation.

One discussion today touched on the direction of overriding positions... Many argue that you should ALWAYS search from OrdersTotal()-1 to 0. And I don't agree with this. NOT ALWAYS... If I need to search positions not to close, it does not make any difference which way they should go.

I don't like the "one size fits all" approach. I don't accept one-size-fits-all functions, like pitchfork, rake and scythe all in one...

 

I know it's a dumb question, but I can't find anything anywhere. How do I declare an array with a variable?
For example, I write

int mas [2, 2];

- it's OK.

But as soon as I type in

int n;

int mas [n, 2];

it gives an error: '[' - invalid index value

 
danya-asg:

I know it's a dumb question, but I can't find anything anywhere. How do I declare an array with a variable?
For example, I write

- it's OK.

But as soon as I type in


it gives an error: '[' - invalid index value

You cannot do it that way. Only by changing the first dimension of the array.

int n;
int mas [][2];

ArrayResize(mas, n);
 
alex-202:

Hi! Can you tell me how to return the number of last losing orders, after profitable ones?

Here is my part of the code what is wrong?

Reverse the order of reading History

{ int Loss = 0;
  for(int i=OrdersHistoryTotal()-1; i>=0; i--)
  { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == OrderId )
        if (OrderProfit()<0) { Loss ++; }              
        if(OrderProfit()>0) { break; } // Выход из цикла на первом встретившемся прибыльном
  }
  return(Loss);
}
 
danya-asg:

I know it's a dumb question, but I can't find anything anywhere. How do I declare an array with a variable?
For example, I write

- it's OK.

But as soon as I type in


it gives an error: '[' - invalid index value

int mas [][2]=
   {
   {1,2},
   {1,2},
   {1,2},
   {1,2}
   };
Reason: