Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 556

 
I have this one working, no malfunctions.
//---закрыть все позиции в пятницу в 19-40 по серверному времени 
   if(DayOfWeek()==5 && Hour()==19 && Minute()>40){
      //Дать сигнал на закрытие всех позиций    
       
   } 
 
belck:

Greetings!

I am trying to make my EA close trades on Friday half an hour before the session closes.

I tried the tutorial, but it did not work.

i can ask if anyone has a ready code.

I have the closing code. i need it to be able to close a session 30 minutes beforehand.


This may be more universal to any broker. Too bad there is no difference in broker quotes from UTC yet

void OnStart()
  {
//---
   int hrd=-3; // разница времени в часах котировок брокера с Гринвичем
   datetime tc=TimeCurrent();
   if(f_ts(tc,hrd)>0) Print("CloseAll()");
  }
//+------------------------------------------------------------------+


int f_ts(datetime ti, int hrd)
{
   if(TimeDayOfWeek(ti)!=5) return(-1); // если не пятница  выходим
   datetime t0d,te;
   int dtd=1440*60, res=-1;
   t0d=ti/dtd*dtd;        // начало торгового дня
   te=t0d+dtd-30*60+hrd*3600;     // 30 мин до конца сессии
   if (ti>te)  res=1;
   else        res=0;
   return(res);
 
granit77:
I have this one working, no malfunctions.

tried it this way, tested it through a tester, then the function didn't work.
 

Well this should not work in the tester.

if(DayOfWeek()==5 && Hour()==19 && Minute()>40)

The functions are based on current time, and what I wrote above will work because TimeCurrent() and TimeDayOfWeek() work correctly. You only need to add function for switching to summer and winter time, i.e. parameter hrd. Switching usually takes place according to American DST time (first Sunday of November second Sunday of March), but some brokers do not make the switch, so you should use your

 
belck:

Greetings!

I am trying to make my EA close trades on Friday half an hour before the close of the session.

I tried the tutorial, but it did not work.

i can ask if anyone has a ready code.

I have the closing code. I need it to signal the closing of the session 30 minutes before.

r772ra:

Maybe like this.

Not like this at all.

We need to define the session closing time datenime SessionClose = . If not session close, but trade close, then SessionClose = StrToTime("23:30");

Define day of the week TimeDayOfWeek()

If Friday, check TimeCurrent() >= SessionClose

 
AlexeyVik:

This is not the case at all.

We need to define session closing time datenime SessionClose = .... If not session close, but trade close, then SessionClose = StrToTime("23:30");

Define day of the week TimeDayOfWeek()

If Friday, check TimeCurrent() >= SessionClose


can you describe the code in more detail?
 
AlexeyVik:

This is not the case at all.

We need to define session closing time datenime SessionClose = .... If it's not session closing, but trading, then SessionClose = StrToTime("23:30");


session closing time SessionClose = ... and bidding ... will not work in the tester no matter how you define it :) Check from the beginning of March to today
 
belck:

can you describe the code in more detail?

Yes, I can. But it goes against my principles.


GSB:
session closing time datenime SessionClose = ... and bidding ... will not work in the tester no matter how you define it :) Check from the beginning of March to this day

What's that got to do with the tester? Although it worked in the tester until the latest updates. I won't argue now, haven't tested it and won't be forced to turn on the tester any time soon.
 
AlexeyVik:

I can. But it is against my principles.


What does the tester have to do with it? Although it did work in the tester until the latest updates. I won't argue now, I haven't tested it and won't be forced to turn on the tester any time soon.

No objections to the principles, but the man wants to run the EA in the tester, so your options are not suitable for him.

Use my version, it will work in the real and in the tester, but until they made a feature to automatically account for the transition to winter summer time, define the transition time for this year like

string data_1="2014.03.09"; string data_2="2013.11.03";
if(TimeCurrent() < StrToTime(data_1) && TimeCurrent() > StrToTime(data_2) ) hrd=-2; else hrd=-3;
From March 2013 to November 2014 will work and test correctly. Set the shift according to your broker
 
GSB:

I have no objections to the principles, but the man wants to run the Expert Advisor in the tester, so your options do not suit him.

Use my variant, it will work both in real and in the tester, but until they have made a function to automatically account for daylight saving time, define the transition time for this year like

From March 2013 to November 2014 will work and tested correctly. Set the shift according to your broker


I will not look where it is written that the time is generated in the tester, you know it yourself. But in the help it specifically says that

 var2=StrToTime("17:35");      // возврат текущей даты с указанным временем

Whereas it does not say anything specific about StringToTime().

The only thing to take into account is time on the tester (of the DC server). And accordingly when testing you should have a history of the same type of account on which this owl will work.