OrderOpenTime() problem regarding getting last order open time

 
rkomm:

hi guys 

I been having a problem regarding OrderOpenTime() function 

this ea runs only on 1 chart 

***

Please insert your code correctly: when editing a post, press the button  Code, then paste the code into the window that appears.

Also remember that all questions about the old terminal must be placed in a special section: MQL4 and MetaTrader 4  .

I will postpone your topic.

 
Vladimir Karputov:

Please insert your code correctly: when editing a post, press the button  , then paste the code into the window that appears.

Also remember that all questions about the old terminal must be placed in a special section: MQL4 and MetaTrader 4  .

I will postpone your topic.

thank you my dear friend 

it is my first topic creation I was not familiar with rules 

of course I will do all you mentioned in 6 hour

thank you again . 

 
rkomm: I been having a problem regarding OrderOpenTime() function
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button).
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

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

 
William Roeder:
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button).
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

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

void OnTick() 

{


if ( High[2]>High[1] )
  {
    if (OrdersTotal() < 1)
   
    {
    OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+50,Bid-50," sell is happening ",0,0,clrRed);
    }
    }

     if ( High[2]>High[1] )
              
{
  if ( OrdersTotal() >=1) 
  { 
for (int cnt=OrdersTotal()-1; cnt>=0 ; cnt--)
{
      if(OrderSelect(cnt,SELECT_BY_TICKET,MODE_TRADES)==true)                          
         {
     
           if(TimeMinute(TimeCurrent()) - TimeMinute(OrderOpenTime())>=3)
               
               {
             
                OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+50,Bid-50," sell is happening ",0,0,clrRed);
                  
                     }
                     }
                     }
                   
}

}
}     
       
 
 



sorry my good friend 

here is all my code 

it opens 1 trade but 

it does not perform main idea which is next trade after 3 minute of  last trade open time  

 
William Roeder:
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button).
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

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

There is no need to be so harsh.

I think that it is a fair assumption that the code was posted, but not in the correct way and that Vladimir deleted the code.

 
rkomm:

here is all my code 

it opens 1 trade but 

it does not perform main idea which is next trade after 3 minute of  last trade open time  

The first thing to say is that the formatting of your code does not make it easy for other people to read.

You should learn to use the styler which is a great little tool.

Tools > Options >Styler

to set up.

This is my preferred set-up


Then Ctrl+comma and your code turns into

void OnTick()

{
   if ( High[2]>High[1] )
     {
      if (OrdersTotal() < 1)
        {
         OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+50,Bid-50," sell is happening ",0,0,clrRed);
        }
     }
   if ( High[2]>High[1] )
     {
      if ( OrdersTotal() >=1)
        {
         for (int cnt=OrdersTotal()-1; cnt>=0 ; cnt--)
           {
            if(OrderSelect(cnt,SELECT_BY_TICKET,MODE_TRADES)==true)
              {
               if(TimeMinute(TimeCurrent()) - TimeMinute(OrderOpenTime())>=3)
                 {
                  OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+50,Bid-50," sell is happening ",0,0,clrRed);
                 }
              }
           }
        }
     }
}

Which, in my opinion, is much easier to read.

I immediately see

         for (int cnt=OrdersTotal()-1; cnt>=0 ; cnt--)
           {
            if(OrderSelect(cnt,SELECT_BY_TICKET,MODE_TRADES)==true)

You cannot select by ticket with an index. It must be

         for (int cnt=OrdersTotal()-1; cnt>=0 ; cnt--)
           {
            if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
              { 
 
Keith Watford:

The first thing to say is that the formatting of your code does not make it easy for other people to read.

You should learn to use the styler which is a great little tool.

Tools > Options >Styler

to set up.

This is my preferred set-up


Then Ctrl+comma and your code turns into

Which, in my opinion, is much easier to read.

I immediately see

You cannot select by ticket with an index. It must be

thank you my dear friend for styling point sure I use it next time

but I  have tried the SELECT_BY_POS too 

it just opens 1 trade and after 3 minute with same opportunity it does not open another trade

 
  1. Must use position, not ticket.
  2. if(TimeMinute(TimeCurrent()) - TimeMinute(OrderOpenTime())>=3)

    This fails when past the top of the hour. No need for TimeMinute:

    if(TimeCurrent() - OrderOpenTime() >= 3*60)
 
William Roeder:
  1. Must use position, not ticket.
  2. This fails when past the top of the hour. No need for TimeMinute:


Thank you my good friend for point 1 and 2 

  

if(TimeCurrent() - OrderOpenTime() >= 3*60)

but solution you posted does not work because the number you get from TimeCurrent () - OrderOpenTime() is somehow a big number like 9425 and it is always

greater than 3*60 

 
rkomm:

but solution you posted does not work because the number you get from TimeCurrent () - OrderOpenTime() is somehow a big number like 9425 and it is always

greater than 3*60 

First loop through the orders and find which one has the latest OrderOpenTime().

That is the only order that you are interested in.

Reason: