what is code for closing all trade at specific time.

 

what is code for closing all trade at specific time.

for example start time trade at 7 and and end time 23 and close all trade as well.

what will be the code for that.

 

Hey,

You can do something like :

void CloseTrades(int type)
  {
   for(int i = OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS))
         continue;
      if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic &&
         (type==-1 || OrderType()==type))
        {
         bool close = OrderClose(OrderTicket(),OrderLots(),(type==0)?Bid:Ask,10);
        }
     }
  }

if(Hour()==23)        // This is to serve as an example
 {CloseTrades(-1);}
 
Abdul Salam :

what is code for closing all trade at specific time.

for example start time trade at 7 and and end time 23 and close all trade as well.

what will be the code for that.

Example in code: Close on time :

The idea of a utility adviser

The EA closes positions and removes pending orders at a certain time. The principle of work: to close and remove is given ten minutes from the start of Close Time . If it succeeds in completing the task earlier than ten minutes, then the adviser will stop searching for the task earlier that day. The Close Time variable, although it is set in full format, uses only hours :: minutes - do not pay attention to the year and month.

A search is performed within this gap. You can control exactly what to close - only on the current character or all characters ( Close All Symbols parameter), consider only a specific Magic ( Close All Magics -> false and set Magic Number ) or ignore Magic ( Close All Magics -> true ). Separately, you can enable closing positions ( Close Positions -> true ) and delete pending orders ( Delete Pending Orders -> true ).

In principle, these are all settings

Please note: in this code, the closing procedure is simplified - there is no check for Stops Level.


 
Stanislav Ivanov: You can do something like :
bool close = OrderClose(OrderTicket(),OrderLots(),(type==0)?Bid:Ask,10);

Simplified

bool close = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10);
 
William Roeder:

Simplified

i see

 
Stanislav Ivanov:

i see

ok thanks for coding

Reason: