For Loop to find order close time for last closed order

 

hi,


I would like to find the order close time for my last closed order. Subsequently, there will be a signal ('More than 15 mins") when it has been more than 15 mins since the order was last closed.

There is no error with my code, but there is no signal after 15 mins.

Here is my code


void OnTick()

{

string signaltime"";

   datetime closetime = OrderCloseTime();

   for(int i=OrdersHistoryTotal()-1;i>=0;i--)

   { 

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

         if(OrderSymbol()==Symbol())

         

            if(TimeCurrent()-closetime>900)

               {   

               signaltime = " 'More than 15 mins ";

               }

         

   }  


It will be great if someone can help!!! 


THANKS!

 
Please edit your post and
use the code button (Alt+S) when pasting code
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. datetime closetime = OrderCloseTime();
    You can not use any Trade Functions until you first select an order.

  3. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum

  4. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum 2012.04.21
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 2020.06.08

 

Hi Keith and William,


Thanks for the prompt reply!

 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You can not use any Trade Functions until you first select an order.

  3. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum

  4. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum 2012.04.21
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 2020.06.08

Thanks William I'll check out the post mentioned!
 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You can not use any Trade Functions until you first select an order.

  3. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum

  4. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum 2012.04.21
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 2020.06.08

Hi William,

Thanks again!

I am new to mql4 and I’ve read the post that you have linked, however I don’t quite understand the logic And the post that you have linked .

Should the logic be in this manner:
1. Sort Order history for closed positions in terms of date
2. Select most recent closed position
3. Extract time from most recent closed position
 
if (OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)) continue;

This doesn't make sense. It should be

if (!OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)) continue;
 
Peijayz: Should the logic be in this manner:
1. Sort Order history for closed positions in terms of date
2. Select most recent closed position
3. Extract time from most recent closed position
  1. No need to sort, you just have to remember the latest.
  2. You can't select the most recent anything. You have to go through history and find it.
  3. Remember it when you find a trade (not a deleted pending, not an accounting entry.)
  4. Test your 15 minutes after the loop, when you have your result.