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

 
EVGENII SHELIPOV #:

What this timer is for

Here
Документация по MQL5: Обработка событий / OnTimer
Документация по MQL5: Обработка событий / OnTimer
  • www.mql5.com
OnTimer - Обработка событий - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
MakarFX #:
You could have answered... it wasn't a personal question)

Once I wrote to read the help, the moderators pointed out that you can't do that. And there asked you specifically.

 
Andrey Sokolov #:

Once wrote to read the reference, the moderators pointed out that you can't do that. And it was a personal one there, asking you specifically.

It's a question on a built-in function - that's why the help

It's just that no one has answered before, so I wrote to whoever is answering

 
MakarFX #:

This is a question on a built-in function - so help

It's just that no one has responded before, so I wrote to whoever is answering

If someone in particular is being pointed out, I consider it a personal reference.

Can you give me a hint on that? https://www.mql5.com/ru/forum/160683/page1650#comment_25081067

 
Andrey Sokolov #:

If they point to someone in particular, I consider it a personal appeal.

Any advice on that? https://www.mql5.com/ru/forum/160683/page1650#comment_25081067

Polemic...

The question is not of a personal nature.

 
MakarFX #:
Here

I understand that the timer can be used to adjust the speed of optimisation and testing?

 
EVGENII SHELIPOV #:

As far as I understand it is possible to adjust the speed of optimisation and testing with this timer?

The timer does not work in the tester.

If you need to execute something after a certain time regardless of the ticks, you use the Timer.

 
Could you please tell me what the code should look like under the following condition: itshould check buy entry conditions and open buy if there are no open buy positions or if a buy position is closed.

I took the code from MT, but it doesn't work, it opens buy on every tick, a million buys on three candlesticks

void OnTick(void)
  {
    int cnt, total;
    if(*************) 
      { 
        OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Bid - SL * Point, 0, NULL, 888, 0, Blue); 
      }    
     
    if(*************) 
      { 
        OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Ask + SL * Point, 0, NULL, 888, 0, Red); 
      }    
      

   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol())  
        {
         if(OrderType()==OP_BUY)
           {
            if(*****************)
              {
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
           }
         else
           {
            if(*****************)
              {
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
           }
        }
     } 
  }


I want buy and sell to be independent from each other and open on different signals

 
Ivan Butko every tick, a million buys on three candles

Here is the order search function and if buy search = 0, then open, etc.

 
MakarFX #:

Here is the order search function and if buy search = 0, we open, etc.

Unfortunately, it's hard to understand how to use this code.


Tried to put a flag in 1 when a buy order opens, and a flag in 0 when it closes, and added the latter to the open condition. It didn't work)
It is strange, in fact the rule is broken: open if the flag==0. And it still opened at 1 on the same candle anyway.

Reason: