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

To add comments, please log in or register
Unexpected Reporter
25
Unexpected Reporter  

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.

Marco vd Heijden
Moderator
8154
Marco vd Heijden  

To post a job here 

Else use iTime() function and CloseAll()

Unexpected Reporter
25
Unexpected Reporter  
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.

Marco vd Heijden
Moderator
8154
Marco vd Heijden  
I could but i am very busy at the moment so you can post a job here 
InvestSoft
14805
Janusz Trojca  

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--;
   } 
}  
Marco vd Heijden
Moderator
8154
Marco vd Heijden  
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.
InvestSoft
14805
Janusz Trojca  
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?

Marco vd Heijden
Moderator
8154
Marco vd Heijden  

Nothing bad,on the contrary thank you so much !

Now please help the Unexpected Reporter to a working solution.

InvestSoft
14805
Janusz Trojca  
Marco vd Heijden:

Nothing bad,on the contrary thank you so much !

Now please help the Unexpected Reporter to a working solution.

Marco vd Heijden
Moderator
8154
Marco vd Heijden  

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

Do you have a headache ? 

InvestSoft
14805
Janusz Trojca  
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.
12
To add comments, please log in or register