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

 
Sergey Golubev:

Many years ago, there was an EA in the English part of the thread (I'm sorry, it takes too long to find it now) which when trading (and analysing the market) generated and updated a text file, which was read at certain intervals by another EA working in the same Metatrader, but on a different pair (or the same, but on a different chart). And both traded, communicating with each other with this file.

I have done so for scalper-master to communicate with scalper-slave on other terminals. But it only transfers control commands from a trader so there is no need to manually click the same buttons on all terminals. But nothing prevents to transmit data.

If you can communicate via memory mapping, then goodbye market

 

I work a lot with custom characters. Almost always need to kill a custom one, but have to do it manually. I decided to automate it.

And it turned out to be just the script for Services. Maybe it's not exactly a standard approach to Services, but I wanted a script which isn't tied to charts. And here's why

// Удаляет символ активного графика из Обзора рынка (кастомный - удаляет полностью).

#property service

// Находит чарт в фокусе.
long GetFocusChart()
{
  long Chart = ChartFirst();

  for (; Chart != -1; Chart = ChartNext(Chart))
    if (ChartGetInteger(Chart, CHART_BRING_TO_TOP))
      break;

   return(Chart);
}
   
// Удаляет чарты символа.
int DeleteCharts( const string Symb )
{
  int Res = 0;
  
  for (long Chart = ChartFirst(); Chart != -1; Chart = ChartNext(Chart))
    if (ChartSymbol(Chart) == Symb)
      Res += ChartClose(Chart);
  
  return(Res);
}

// Удаляет символ из Обзора рынка (кастомный - удаляет полностью).
bool DeleteSymbol( const string Symb )
{
  DeleteCharts(Symb);

  return(SymbolSelect(Symb, false) && (!SymbolInfoInteger(Symb, SYMBOL_CUSTOM) || CustomSymbolDelete(Symb)));
}

void OnStart()
{
  const long Chart = GetFocusChart();
  
  if (Chart != -1)
    DeleteSymbol(ChartSymbol(Chart));
}

Was thinking of putting a hotkey on that script/service and nailing a symbol through it when I see a chart of an unwanted symbol. Would be very handy. However, ran into difficulties.

  • There is no way to pin a hotkey to Service.
  • In order to restart the Service, you have to delete it before doing so. This is supposed to be necessary to start Services at the first start of the Terminal. But my case is different.
  • SymbolSelect doesn't work - it can't remove the symbol. Bug, apparently.
As a result, it's a bummer. Is it possible to solve the practical side of Services somehow?


ZZY There is a workaround to remove the active chart symbol.

 
fxsaber:

I work a lot with custom characters. Almost always need to kill a custom one, but have to do it manually. I decided to automate it.

And it turned out to be just the script for Services. Maybe it's not exactly a standard approach to Services, but I wanted a script which isn't tied to charts. And here's why

Was thinking of putting a hotkey on that script/service and nailing a symbol through it when I see a chart of an unwanted symbol. Would be very handy. However, ran into difficulties.

  • It is impossible to pin a hotkey to Service.
  • In order to restart the Service, you have to delete it before doing so. This is supposed to be necessary to start Services at the first start of the Terminal. But my case is different.
  • SymbolSelect doesn't work - it can't remove the symbol. Bug, apparently.
As a result, it's a bummer. Is it possible to solve the practical side of Services somehow?


ZZY There's a workaround for removing the active chart symbol.

Can't put a hotkey on Services, because OnChartEvent() function doesn't work there; but I guess you know that. So, Expert Advisor should work with hotkeys and pass the commands to the Service through resources. Try to manage the service with resources.

SZY. Of course, in this case, we will loose the meaning of Service. You can close charts from Expert Advisor by pressing hotkeys...

SZY. The only point is not to produce additional functionality in Expert Advisors. We can dump the general functionality of various EAs into Service and call it through a resource. Give us a command for what to do.

 
Реter Konow:

Can't put a hotkey on Service because OnChartEvent() doesn't work there


 
fxsaber:


Thank you. Then what's the problem?

You want the Service itself (running non-stop) to respond to keystrokes.

 
Реter Konow:

Thank you. Then what's the problem?

You want the Service itself (running non-stop) to respond to keystrokes.

No. You want the Service to be able to work in Script mode without being bound to a chart.

 
fxsaber:

No. You need the Service to be able to work in Script mode without being bound to a chart.

Does it work any other way?

 
Реter Konow:

Does it work any other way?

Yes.

 
fxsaber:

Yes.

So he can run any chart? Easily.

 
The service operates with data (quotes) with the possibility to correct them, but it does not allow managing anything, in particular, the windows of the terminal, which is what is needed. Hence the obvious conclusion: if it is necessary to close one or another window, the service generates an obviously impossible quote for this window, and the script attached to this window closes it when this quote is received.