Useful features from KimIV - page 76

 
bool TimeTrade()
{
//----
   datetime current=TimeCurrent();
   if (((TimeHour( current) >= OpenHour || TimeHour( current) < CloseHour) && CloseHour< OpenHour) ||
      (TimeHour( current) >= OpenHour && TimeHour( current) < CloseHour && CloseHour> OpenHour)) 
      return(true);
   else
      return(false);
}
This will do....
 
kharko >> :

This variant will fit....

Put OpenHour and CloseHour in parameters and those who want to have several intervals will be satisfied:

Make TimeTrade(OpenHour1, CloseHour1), TimeTrade(OpenHour2, CloseHour2), ......

and will combine them as they want.

 
bool TimeTrade(int OpenHour,int CloseHour)
{
//----
   datetime current=TimeCurrent();
   if (((TimeHour( current) >= OpenHour || TimeHour( current) < CloseHour) && CloseHour< OpenHour) ||
      (TimeHour( current) >= OpenHour && TimeHour( current) < CloseHour && CloseHour> OpenHour)) 
      return(true);
   else
      return(false);
}
No problem...
 

posted once before

//-----------------------------------------------------------------------------+
// Функция контроля времени торговли                                           |
//-----------------------------------------------------------------------------+
bool TradeTime(int StartTradeHour,int EndTradeHour){
if(! TradeOfTime){
if(DayOfWeek()==6||DayOfWeek()==0){
gTimeEngl="Start trade in  01:00 am";
gTimeRus="Начало торговли в понедельник в 01:00";
return(false);}
return(true);}
if(DayOfWeek()==6||DayOfWeek()==0){
gTimeEngl="Start trade in  01:00 am";
gTimeRus="Начало торговли в понедельник в 01:00";
return(false);}
if( StartTradeHour< EndTradeHour){
  if(TimeHour(TimeCurrent())>= StartTradeHour&&TimeHour(TimeCurrent())< EndTradeHour
    ||( CountOpOrd("0")>0)){
    gTimeEngl=StringConcatenate("By the end of trading session :",DoubleToStr(( EndTradeHour-TimeHour(TimeCurrent())),0)," hours");
    gTimeRus=StringConcatenate("До конца торговой сессии :",DoubleToStr(( EndTradeHour-TimeHour(TimeCurrent())),0)," часов");
    return(true);}}
if( StartTradeHour> EndTradeHour){
  if(TimeHour(TimeCurrent())>= StartTradeHour||TimeHour(TimeCurrent())< EndTradeHour
    ||( CountOpOrd("0")>0)){
    gTimeEngl=StringConcatenate("By the end of trading session :",DoubleToStr(( EndTradeHour-TimeHour(TimeCurrent())),0)," hours");
    gTimeRus=StringConcatenate("До конца торговой сессии :",DoubleToStr(( EndTradeHour-TimeHour(TimeCurrent())),0)," часов");
    return(true);}}    
gTimeEngl=StringConcatenate("resting to : ", StartTradeHour,": 00");   
gTimeRus=StringConcatenate("отдыхаем до : ", StartTradeHour,": 00");  
return(false);
}
 

also

//-----------------------------------------------------------------------------+
// Определяет дату конца торговли                                              |
//-----------------------------------------------------------------------------+
bool EndTradeForDateTime(string EndTradeData){//"Enterting Date of End trading in eeee.mm.dd";
if( EndTradeData==""){
gInf1rus="Дата конца торговли не определена ";
gInf1engl="Date of the end of trading is not defined ";
gColor1=LimeGreen;
return(false);
}
int EndData=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
int DataEnd=StrToTime( EndTradeData);
if( EndData>= DataEnd){
gInf1rus="Торговля остановленна "+ EndTradeData;
gInf1engl="Trading stopped "+ EndTradeData;
gColor1=Red;
return(true);
}
gInf1rus="Торговля будет остановленна "+ EndTradeData;
gInf1engl="Trading will be stopped "+ EndTradeData;
gColor1=LimeGreen;
return(false);
}
and we'll call it a day.
 
xrust >> :
..and that's the end of it.

"Don't rush to bury us, we've still got things to do here..." :))

 
bool IsTradeTime()
{
if(Hour()> Hour_Stop_Trade  && Hour()< Hour_Start_Trade)
	return(false);
 if(Hour()== Hour_Stop_Trade && Minute()>= Minute_Stop_Trade)
	return(false);  
 if(Hour()== Hour_Start_Trade && Minute()< Minute_Start_Trade)
	return(false);
return(true);
}
If you also need minutes for a more precise time interval, for example for a night scalper.
 
khorosh >>:
Если нужны ещё и минуты для более точного определения временного интервала, например для ночного скальпера.

Of course you need at least dozens of minutes.

You also need days of the week and the ability to set individual times for each day of the week and

Selecting/forbidding a certain day.

Practice shows that the patterns work differently on different days of the week.

 
Good afternoon, KimIV. I need your advice, or rather help. Found in the database e-Smart_Tralling.mq4, author unknown...but as clarified in the branch the author took in basis - trailing advisor-assistant I.Kim aka KimIV. I tried to change in the code of this EA: 1.to close not all profitable trades, for example, when executing an order, if I put a target and my take profit, advisor does not close this deal; 2. to make it work with all currency pairs and with stoploss. I have not yet had much programming experience, maybe you can suggest me what to change. I am very thankful in advance.
 

A simple formula for the automatic generation of a magik for EAs working simultaneously on different instruments in the same account came to mind.

int Magic= GetMagic( ExpertName+Symbol(),Period());
//-----------------------------------------+

//+----------------------------------------------------------------------------+
//|  Автор    :  KimIV style,  http://www.kimiv.ru                             |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.04.2009                                                     |
//|  Описание : Возвращает сумму символьных кодов всех символов входной строки |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    simbolstring - строка для расчета                                       |
//|    multiplier   - дополнительный множитель                                 |
//+----------------------------------------------------------------------------+

int GetMagic(string simbolstring, int multiplier){
   int res=0;
   int len=StringLen( simbolstring);
   for(int i=0; i< len; i++)
       res+=StringGetChar( simbolstring, i);      
   return( res* multiplier);
}