How to add option to close every trade at the end of the month or week.

 

Hi everybody,

I have an EA i'm working on it and i would like to add an option to close every trade at the end of the week or at the end of the month.

How can i do it?

I literally have 0 experience on mq4 coding.

Thanks.

 

To post a job here 

Else use iTime() function and CloseAll()

 
Marco vd Heijden:

To post a job here 

Else use iTime() function and CloseAll()

Sorry but i really don't know anything about coding, could you write the full code to paste into the EA code?

Thanks.

 
I could but i am very busy at the moment so you can post a job here 
 

A simple code closing all orders on Friday at 21:00

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ...
   
   if (DayOfWeek() == 5 && TimeHour(TimeCurrent())>=21) CloseAllOrders();
  }
  
//+------------------------------------------------------------------+
//| Close all active orders                                          |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
   int i=OrdersTotal()-1;
   while (i >= 0)
   {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if (!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 10))
         {
            Print("Order Close Error: "+IntegerToString(GetLastError()));
         }
      }
      i--;
   } 
}  
 
Unexpected Reporter:

Sorry but i really don't know anything about coding, could you write the full code to paste into the EA code?

Thanks.

No because you would not know where to insert it.

But your free personal coder has arrived so now @Janusz Trojca is going to help you solve the issues.
 
Marco vd Heijden:

No because you would not know where to insert it.

But your free personal coder has arrived so now @Janusz Trojca is going to help you solve the issues.

I'm nobody's free personal code. I only shared a piece of code that is full on the web. Nothing special. Is this something bad?

 

Nothing bad,on the contrary thank you so much !

Now please help the Unexpected Reporter to a working solution.

 
Marco vd Heijden:

Nothing bad,on the contrary thank you so much !

Now please help the Unexpected Reporter to a working solution.

 

He will be back with more questions for you just wait a bit.

Do you have a headache ? 

 
I know that he could have more questions and this is the forum, but I have no obligation to do full work for someone. I can help with small code example, but I do not have to program full robot for free.