MT4 EA that closes a trade (open or pending) after a certain period of time

 

Hi everyone!

 I am very new to this forum and writing EAs.  I want to know how to close an order after a certain period of time.  For example, I have placed an order at 12PM, I want it to close after 4 hours at 4PM.  Even if it is a pending order that I placed at 12, I want to close/expire after 4 hours at 4 PM regardless of whether or not it was activated.  Does a code like this exist?  Can somebody attach it or explain how to do it?  Any help would be much appreciated!

 

Thank you!! 

 
  1. If your broker allowed an expiration time, then set it 4 hours after current and it will delete itself.
  2. Otherwise remember when you placed it and delete it (if not open)
Reason: