Services. Are they up and running yet? - page 21

 

Renat, will it be possible to implement custom glass in the service?
The documentation says that the OnBookEvent handleris called in indicators and experts.
What about services? How to run the stacks in the service?
I would like to be able to run my custom stacks, in the service.
According to your words, services don't support any handlers other than OnStart, and it becomes a problem.
The matter is that services are much faster than the system OnTimer inindicators andExpert Advisors.
And it's better to use services to build custom stacks.

p.s.
I´ve read this article and am surprised, that some skilled programmers can´t use services.
Services are cool, they can implement a lot of things, up to asynchronous execution of the entire project, sharing the logic of the tasks between services.
But it would be more logical to add to the language Thread(params) function, which would realize paralleling of threads for the arguments passed to the function.
Well, if there will be threads, then processes go along with them, in the form of the Process(params) function.

One of the important advantages, service is processed faster than system time, i.e. it's processed in just 1ms, or maybe even less.
Because I forced a Sleep(1) limit in the While() loop.
The system OnTimer() with EventSetMillisecondTimer(1) event is processed in Expert Advisors and indicators for ~ 20ms.
This is not a bad gain in terms of processing performance.
Unfortunately, the Expert Advisor handlers are not supported in the service, it severely limits the possible solutions.
Long time ago users asked to implement start of Expert Advisors without schedules, services would just solve this problem.
Judging by the "Automated trading" button in the menu of the service, the possibility of trading is available.
But you cannot build a full-fledged trading solution with OnStart handler alone.

 
fxsaber:

Very handy indeed.

Rebooted the computer and forgot about RAMDrive. Run MT5 and it immediately reports a problem.

Isn't it easier to use RamDisk with automount + junction + dynamic allocation?
When starting the PC, it automatically mounts and links everything, and if there is not enough space on the drive, it will automatically add it from the RAM.

 
Sergey Dzyublik:

Isn't it easier to use RamDisk with automount + junction + dynamic allocation?
At startup the PC automatically mounts and links everything, and if there is not enough space on the disk, it will automatically add it from the RAM.

Not always needed, that's why I didn't create it at startup.

 

The Terminal likes to change the properties of the custom symbols when it is rebooted. For example, its currencies.

This is where Services can come to the rescue. When launched, they correct the Tester's unauthorised behaviour.

 
Can you tell me how a comment can be displayed on an active chart from the service program?
In fact, can any other chart be output?

//+------------------------------------------------------------------+
//| Service program start function                                   |
//+------------------------------------------------------------------+

int OnStart()
{
   Comment("text");

   return(0);
}
 

Answering myself ))

int OnStart()
{
   ChartCommentSet("Hello Service", ChartFirst());
   
   
   return(0);
}

//+------------------------------------------------------------------+ 
//| Функция устанавливает текст комментария в левом верхнем углу     | 
//| графика.                                                         | 
//+------------------------------------------------------------------+ 
bool ChartCommentSet(const string str, const long chart_ID=0) 
{ 
   //сбросим значение ошибки 
   ResetLastError(); 
   
   //установим значение свойства 
   if(!ChartSetString(chart_ID, CHART_COMMENT, str)) 
   { 
      //выведем сообщение об ошибке в журнал "Эксперты" 
      Print(__FUNCTION__+", Error Code = ", GetLastError()); 
      return(false); 
   } 
   
   //успешное выполнение 
   return(true); 
}
 
How to run a service from an EA ?
 
Roman:

Answering myself ))

yes - everything writes in the top left corner

//+------------------------------------------------------------------+
//| Service program start function                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ChartCommentSet("Hello Service", ChartFirst());


   return;
  }
//+------------------------------------------------------------------+
//| Функция устанавливает текст комментария в левом верхнем углу     |
//| графика.                                                         |
//+------------------------------------------------------------------+
bool ChartCommentSet(const string str, const long chart_ID=0)
  {
//сбросим значение ошибки
   ResetLastError();

//установим значение свойства
   if(!ChartSetString(chart_ID, CHART_COMMENT, str))
     {
      //выведем сообщение об ошибке в журнал "Эксперты"
      Print(__FUNCTION__+", Error Code = ", GetLastError());
      return(false);
     }

//успешное выполнение
   return(true);
  }
//+------------------------------------------------------------------+

Photo by

 
fxsaber:

The Terminal likes to change the properties of the custom symbols when it is rebooted. For example, its currencies.

This is where Services can come to the rescue. They correct unauthorized behaviour of the Tester on startup.

Forum on trading, automated trading systems and testing of trading strategies

Custom symbols. Errors, bugs, questions, suggestions.

fxsaber, 2019.09.15 22:30

Solving the problem of automatic change of custom symbol currencies after Terminal reloading.

// Сервис корректирует валюты всех кастомных символов.
#property service

bool CorrectCurrency( const string Symb, const string Currency )
{  
  return(SymbolInfoInteger(Symb, SYMBOL_CUSTOM) && 
         CustomSymbolSetString(Symb, SYMBOL_CURRENCY_BASE, Currency) &&
         CustomSymbolSetString(Symb, SYMBOL_CURRENCY_MARGIN, Currency) &&
         CustomSymbolSetString(Symb, SYMBOL_CURRENCY_PROFIT, Currency));
}

void CorrectSymbols( void )
{
  const string Currency = AccountInfoString(ACCOUNT_CURRENCY);
  
  for (int i = SymbolsTotal(false) - 1; i >= 0; i--)
    CorrectCurrency(SymbolName(i, false), Currency);
    
  return;
}

void OnStart()
{
  CorrectSymbols();
}
 

Add to services the possibility to launch auto-optimization of Expert Advisors.

And various functionalities, e.g. to be able to know that the optimization/run is completed.

Reason: