Pause after a traid finishes

 

Hi all

Can some one please help me make my EntrySign3() work. This shows the principle of what I want it to do. I also have this small bit of code at the start of my EA.

input bool UsePauseTime=true;

input ENUM_TIMEFRAMES PauseTF1=PERIOD_M15;

which should allow me to pick which time frame amount i want it to pause by. it's applying this within my EntrySign3() that I can't figure out.

also OrderCloseTime() needs to be the last order that closed on the chart the EA is running on.

My code is obviously not working can any one please help me out?


----------------------------------

bool EntrySign3()
  {
   if (UsePauseTime)
    {
     if(OrderOpenTime()> OrderCloseTime()+PauseTF1())
      {
        return true; 
      }
     return false;
    }
   return true;
  }

-----------------------------------

 
Riggada:

bool EntrySign3()

  {
   if (UsePauseTime)
    {
     if(OrderOpenTime()> OrderCloseTime()+PauseTF1())
      {
        return true; 
      }
     return false;
    }
   return true;
  }

-----------------------------------

You didn't select any order.
before using the OrderOpenTime, OrderCloseTime  etc, you need to select the order you want to check.
to Select an order you need to use OrderSelect() function.

But you also need to find the order you want to select it.

As you want to check the OrderCloseTime, then the order is not an active order and you need to find it in the history

I think this code can help

int Last_Order_Ticket()
  {
   int ticket=-1;
   datetime last_Trade_Time=0;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==_Symbol&&OrderMagicNumber()==Magic)
           {
            if(OrderCloseTime()>last_Trade_Time)
              {
               ticket=OrderTicket();
               last_Trade_Time=OrderCloseTime();
              }
           }
        }
     }
   return ticket;
  }
//+------------------------------------------------------------------+
bool EntrySign3()
  {
   if(UsePauseTime)
     {
      if(OrderSelect(Last_Order_Ticket(),SELECT_BY_TICKET))
        {
         if(OrderOpenTime()> OrderCloseTime()+PauseTF1())
           {
            return true;
           }
        }
      return false;
     }
   return true;
  }


I had some mistakes, then I updated the codes

Documentation on MQL5: Trade Functions / OrderSelect
Documentation on MQL5: Trade Functions / OrderSelect
  • www.mql5.com
Selects an order to work with. Returns true if the function has been successfully completed. Returns false if the function completion has failed. For more information about an error call GetLastError(). Do not confuse current pending orders with positions, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal...
 
Reza nasimi:

You didn't select any order.
before using the OrderOpenTime, OrderCloseTime  etc, you need to select the order you want to check.
to Select an order you need to use OrderSelect() function.

But you also need to find the order you want to select it.

As you want to check the OrderCloseTime, then the order is not an active order and you need to find it in the history

I think this code can help


I had some mistakes, then I updated the codes

Thanks Reza

This has gotten rid of all my errors.

fingers crossed

Thank you so much.

 
Riggada:

Thanks Reza

This has gotten rid of all my errors.

fingers crossed

Thank you so much.

HI every one again.

Would some one be able to help me out with this code.  if there is 0 trades in the history how do I still get it to return true?

kind regards

Richard.

 
Riggada:

HI every one again.

Would some one be able to help me out with this code.  if there is 0 trades in the history how do I still get it to return true?

kind regards

Richard.

bool EntrySign3()
  {if(Last_Order_Ticket()== -1)return true;
   if(UsePauseTime)
     {
      if(OrderSelect(Last_Order_Ticket(),SELECT_BY_TICKET))
        {
         if(OrderOpenTime()> OrderCloseTime()+PauseTF1())
           {
            return true;
           }
        }
      return false;
     }
   return true;
  }

in the first function int Last_Order_Ticket() we firstly made the ticket equal to -1, which can't be a correct ticket number.

If there is no trade in the history, then ticket won't change and will still be the -1

then simply in the second function we check it , if it is -1, then just return true;

Reason: