tell me what is not an expert Advisor that at a certain time will close all transactions and pending orders?????
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
scriptong
So after all already wrote, the code is given. Take it and use it.
aleksandr1989
I don’t know how to write robots
iks_
#property strict
input int hour = 0,
minute = 0;
//+------------------------------------------------------------------+
string str_close = "";
datetime time_close = 0;
//+------------------------------------------------------------------+
void OnInit()
{
if( hour > 0 || minute > 0 )
str_close = " " + IntegerToString(hour<0 ? 0 : hour>23 ? 23 : hour) + ":" + IntegerToString(minute<0 ? 0 : minute>59 ? 59 : minute);
time_close = StringToTime( TimeToString(TimeCurrent(), TIME_DATE) + str_close );
}
void OnTick()
{
if( str_close == "" ) return;
if( time_close > TimeCurrent() ) return;
time_close = StringToTime( TimeToString(TimeCurrent(), TIME_DATE) + str_close ) + 24*60*60;
for(int cnt=OrdersTotal()-1; cnt>=0; cnt--)
{
if( !OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES) ) continue;
switch( OrderType() )
{
case ORDER_TYPE_BUY :
case ORDER_TYPE_SELL:
if( OrderClose( OrderTicket(), OrderLots(),
SymbolInfoDouble(_Symbol, (OrderType() == ORDER_TYPE_BUY ? SYMBOL_BID : SYMBOL_ASK) ),
5) ) break;
break;
case ORDER_TYPE_BUY_LIMIT :
case ORDER_TYPE_BUY_STOP :
case ORDER_TYPE_SELL_LIMIT:
case ORDER_TYPE_SELL_STOP :
if( OrderDelete( OrderTicket() ) ) break;
break;
}
}
}