Download MetaTrader 5
To add comments, please log in or register
Do you need a trading robot? Orderit via Freelance service!
Mirko
156
Mirko 2013.02.20 09:42 

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

Simon Gniadkowski
Moderator
17975
Simon Gniadkowski 2013.02.20 09:51  
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 

Alain Verleyen
Moderator
29589
Alain Verleyen 2013.02.21 08:15  
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.
Mirko
156
Mirko 2013.02.21 09:30  

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!

Tjipke de Vries
6287
Tjipke de Vries 2013.02.21 09:42  
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 ??? 

Mirko
156
Mirko 2013.02.21 10:17  
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?
Mirko
156
Mirko 2013.02.21 10:54  

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);
  }
Simon Gniadkowski
Moderator
17975
Simon Gniadkowski 2013.02.21 11:16  
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++)
Mirko
156
Mirko 2013.02.21 11:29  

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);
Simon Gniadkowski
Moderator
17975
Simon Gniadkowski 2013.02.21 11:44  
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 ?
Mirko
156
Mirko 2013.02.21 12:05  
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.

/ /12
To add comments, please log in or register