Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 769

 
Leonid123456:
That's exactly what I can't do.
create an integer variable, assign the number of purchases to it and then count the purchases again and compare with the value of that variable is not possible?
 
evillive:
create an integer variable, assign the number of purchases to it, and then once again when I want to count the purchases and compare with the value of that variable, it doesn't work?
Thank you!
 
tuner:

There's nothing wrong with these values, they're all correct, but that's not what we're talking about.

The problem with Friday in particular is not relevant if your local time is X hours longer than your broker's time.

But imagine if on your local computer there is not +1, but -1 hour difference with the broker.

And there is this simple condition:

In this case:

1. the broker will have the first tick of Friday, for example today's tick, which has a time of 2014.11.07 00:00

2. Take the number of seconds elapsed from01.01.1970 00:00 till the tick in question, i.e.2014.11.07 00:00

3. we take the number of seconds elapsed from 01.01. 1970 00:00 till06.11.2014 21:30 (it is yesterday's date, because we take the time of the local PC, which at the moment of the tick is not Friday, but Thursday, which is the 6th day, or to be more precise, 2014.11.06 23:00, the difference of 1 hour)

Voila, the number of seconds in point 2 is greater than in point 3.

IfStringToTime() function takes the date from broker's server, then everything would work as planned, the print would be performed on Friday only after the time exceeds21:30

Yes... I didn't immediately understand the problem. I always have the local one bigger than the server one and didn't run into this problem. The only way out is to take the day into account and not use the shortened time representation.
 
AlexeyVik:
Yes... I didn't understand the problem right away. My local one is always bigger than server one and I haven't encountered such a problem. The only way out is to take the day into account and not use shortened time representation.

Well, yes, as an option to feed the function with the right time, together with the date extracted from TimeCurrent(), in this case the problem should not seem to be

By the way, my local time is always bigger than broker's time, but nevertheless this problem in the above described way appeared last Friday at the same time on two different brokers (one demo, the second real). Why it happened is still a mystery. However, the code has already replaced by another one, so this problem should not happen again

 
tuner:

Well, yes, as an option to feed the function with the right time, together with the date extracted from TimeCurrent(), in this case the problem should not seem to be

By the way, my local time is always bigger than broker's time, but nevertheless this problem in the way described above appeared last Friday at the same time on two different brokers (one demo, the second real). Why it happened is still a mystery. However, the code has already replaced by another one, so this problem should not happen again

Yes there are several variants. For example, you can check Friday night for local time instead of server time. But in that case, if you mess up the computer time, you can get in a lot of trouble.
 
evillive:
create an integer variable, assign the number of purchases to it, and then once again count the purchases and compare with the value of that variable is not possible?

Can you give me an example of the code?

After comparison the variable must be rewritten, otherwise the same code will be executed infinitely. (let's say it was 6 and became 7, I need to write in the variable that it became 7 after the comparison)

 
Leonid123456:

Could you give us an example of the code?

After comparison the variable must be rewritten, otherwise the same code will be executed infinitely. (let's say there were 6 and now there are 7, we should write in the variable that there are 7 after comparison).


Don't bother, here is Kim's function I am using and it works in all builds:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает количество позиций.                                 |
//+----------------------------------------------------------------------------+
int NumberOfPositions(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), kp=0;
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) kp++;
  } } } } }
  return(kp);
}
//+----------------------------------------------------------------------------+

And this is in addition:

  int BuyPos = NumberOfPositions(Symbol(),OP_BUY, Magic);
  int SellPos = NumberOfPositions(Symbol(),OP_SELL,Magic);

All you have to do is check according to your objectives:

if(BuyPos >= n) 
 
borilunad:

Don't bother, here's a Kim function I use and it works in all builds:

And that's in addition:

All you have to do is check according to your objectives:

Thank you very much!
 
borilunad:

Don't bother, here's a Kim function I use and it works in all builds:

And that's in addition:

All you have to do is check according to your objectives:

Plugged it in. It works indefinitely...

Was able to solve the issue using the last method in this article https://www.mql5.com/ru/articles/1399

 
Leonid123456:

Plugged it in. it works endlessly...

Managed to solve the issue using the last method in this article https://www.mql5.com/ru/articles/1399

What do you mean infinitely? Put the condition you want!

if(BuyPos < n) // n = cколько не больше!

AndOrdersTotal()shows the total number. Then use it in the loop for closures and modifications!