Waiting Time since Last Trade Close

 

Hi guys,

if a trade was closed i want my EA wait for opening a next trade till 5 bars were finished.

How can i do this?

How do i get the time of the close of the last trade and how can i compare it with the bars?


Thanks guys

 
FamWue:

Hi guys,

if a trade was closed i want my EA wait for opening a next trade till 5 bars were finished.

How can i do this?

How do i get the time of the close of the last trade and how can i compare it with the bars?

Read some of the other posts on the Forum . . .

https://www.mql5.com/en/forum/143565 

 
They are not able to do a search and they hope to succeed in creating a winning EA on the forex. I've seen it so often on this forum. It is beyond me.
 

Ok sry guys!

I did search but did'nt find the right solution.

If my EA wants to open a new trade then it show check if the last trade is minimum 5 bars ago!

 
FamWue:

Ok sry guys!

I did search but did'nt find the right solution.

If my EA wants to open a new trade then it show check if the last trade is minimum 5 bars ago!


Ok we open at the running bar a new trade 

what can you tell about the closing time of the last closed trade your EA that it will be allowed for opening new trade ??? 

 
I think i can only search in trade history for the last trade of the EA and call OrderCloseTime(). Put how can i compare this Time (which format is it?) with the current time? and how can i calculated in x bars?
 

I tried to get the Time of the Last Closed Trade, but every time it is 0!


   datetime Last;
   int TotalNumberOfOrders = OrdersHistoryTotal();   //  
   for(int i = 0; i >=TotalNumberOfOrders - 1 ; i++)  //  
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue; // falls Zeile leer
         {
         if(OrderType()==OP_BUY && OrderType()==OP_SELL ) {Last=OrderCloseTime(); Alert(OrderCloseTime());}
         }
      } 
   Alert(TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS),"  Letzter Trade: ",Last);
  }
 
FamWue:

I tried to get the Time of the Last Closed Trade, but every time it is 0!

Your for loop is wrong . . .

for(int i = 0;                 //  1 starts at 0

i >= TotalNumberOfOrders - 1 ;  //  is i >= TotalNumberOfOrders - 1 ? yes if you only have 1 order in your History

i++)
 

Ok i understood.

But even in this code "Last" is zero every time.

   datetime Last;
   int TotalNumberOfOrders = OrdersHistoryTotal();   //  
   for(int i = 0; i <=TotalNumberOfOrders - 1 ; i++)  //  
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue; // falls Zeile leer
         {
         if(OrderType()==OP_BUY && OrderType()==OP_SELL ) {Last=OrderCloseTime(); Alert(OrderCloseTime());}
         }
      } 
   Alert(TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS),"  Letzter Trade: ",Last);
 
FamWue:

Ok i understood.

But even in this code "Last" is zero every time.

How can this be true ?

if( OrderType() == OP_BUY   &&   OrderType() == OP_SELL )  // ??  Buy and a Sell ?
 
RaptorUK:

How can this be true ?

 


Oh my god. So stupid.


Ok. Now i how can i compare the current time to the OrderCloseTime() in case of different Timeframes.

Since the close there should be minimum 5 Bars of the current timeframe.

Reason: