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

 
PolarSeaman:

Sorry, I don't understand why you can't.

you can, but it won't exactly be a timer

if (IsTesting()) OnTimer();
 
PolarSeaman:

there you go... What if the tick didn't come? You need to "start" without a tick.

the first tick is for synchronization, and if the start tick did not come, the market is closed, there is nothing to do there

 

Good evening!

Again I have to ask for help:

One order has to be opened in a certain time range, if an order has already been opened in the last 30 minutes with this magik, then no order has to be opened. Writing like this:

if (TimeCurrent()>StrToTime("00:01") && TimeCurrent()<StrToTime("00:30"))
{

//1я часть
for (int i = OrdersTotal() - 1; i >= 0; i--)
 {
  if (!OrderSelect(i, SELECT_BY_POS))
     continue;
  if (OrderSymbol() != Symbol())
     continue;
  if (OrderMagicNumber() != MagicNumber1)
     continue;
  if (TimeDayOfWeek(OrderOpenTime()) != TimeDayOfWeek (TimeCurrent()))
     continue;   
  ++nCnt1;
  {
   if (nCnt1>0)
      return;
  }
 }
//2ая часть
for (int i = OrdersTotal() - 1; i >= 0; i--)
 {
  if (!OrderSelect(i, SELECT_BY_POS,MODE_HISTORY))
     continue;
  if (OrderSymbol() != Symbol())
     continue;
  if (OrderMagicNumber() != MagicNumber1)
     continue;
  if ( TimeToStr(TimeCurrent()-OrderOpenTime(),TIME_MINUTES) <= TimeToStr(D'00:30',TIME_MINUTES))
     continue;
  ++nCnt1;
  {
   if (nCnt1>0)
      return;
  }
 }

//Открытие ордера
}

If you leave only the first part, the problem is that if a stop/take position closes in that half hour, another one opens. So I added the 2nd part to get into the order history and if there was already an order in the last 30 minutes with this mag, then don't open it. But something is wrong with the second part - it still opens.

Please advise!

 

you have to count in seconds.

if ( TimeCurrent()-OrderOpenTime() <= 30*60 )
 
Taras Slobodyanik:

You have to count in seconds.

Unfortunately it didn't work.

Tried this again, also no:

  if ( TimeToStr(TimeCurrent()-OrderOpenTime(),TIME_SECONDS) <= TimeToStr(30*60,TIME_SECONDS))
 
YanSay:

Unfortunately, it didn't work.

I tried this again, but it didn't work either:

Why are you comparing all the lines? Taras said correctly - count in seconds. His version did not work, because you still haven't got to the account history:

//2ая часть
for (int i = OrdersTotal() - 1; i >= 0; i--)

This is a cycle of working orders. If we look at the history, the loop will be as follows:

//2ая часть
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)

Then we should take the order close time instead of its open time in the loop.

 
Ihor Herasko:

Why are you comparing all the lines? Taras was right when he said count in seconds. His version did not fit, because you never got to the account history:

This is a cycle of working orders. If we look at the history, the loop will be as follows:

Then in the loop, we should take the close time of the order and not its open time.


if (TimeCurrent()>StrToTime("00:01") && TimeCurrent()<StrToTime("00:30"))
{

//1я часть
for (int i = OrdersTotal() - 1; i >= 0; i--)
 {
  if (!OrderSelect(i, SELECT_BY_POS))
     continue;
  if (OrderSymbol() != Symbol())
     continue;
  if (OrderMagicNumber() != MagicNumber1)
     continue;
  if (TimeDayOfWeek(OrderOpenTime()) != TimeDayOfWeek (TimeCurrent()))
     continue;   
  ++nCnt1;
  {
   if (nCnt1>0)
      return;
  }
 }
//2ая часть
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
 {
  if (!OrderSelect(i, SELECT_BY_POS))
     continue;
  if (OrderSymbol() != Symbol())
     continue;
  if (OrderMagicNumber() != MagicNumber1)
     continue;
  if ( TimeCurrent() -OrderCloseTime() <= 30*60 )
     continue;
  ++nCnt1;
  {
   if (nCnt1>0)
      return;
  }
 }

//Открытие ордера
}

If I understood correctly, you meant TimeToStr, i.e., you have translated it into text?

Corrected it, but still:

Tester

Sorry, if I am completely stupid.

 
YanSay:

If I understand correctly, you mean TimeToStr - i.e. translated into text?

Corrected, but still:

I'm sorry if I'm completely stupid.

Say your condition out loud and you'll see what's going on.)

if ( TimeCurrent() -OrderCloseTime() <= 30*60 )
 

If one of the previous indicator buffer values is assigned an empty value, will it be deleted from the chart?

or will there be an empty value in the buffer and the drawing will remain on the chart?

 
YanSay:

If I understand correctly, you mean TimeToStr - i.e. translated into text?

Yes. There is no point in converting time to a string, because time is a number of seconds. This number is much easier and faster to work with than strings.

Corrected, but still:

Sorry if I'm completely stupid.

You've corrected one thing and spoiled another.)

In the second part instead of:

if (!OrderSelect(i, SELECT_BY_POS))
     continue;

bring it back:

if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
     continue;

You had this line correct in your previous attempt.

Reason: