When does it make sense to keep part of the robot code in an indicator? - page 33

 

A zelo useful discourse...

And knowing the resource and potential of the participants, I provocatively propose to measure the speed and 'unglottability' of the tics in:

1) Sovnig

2) cyclic script running at a frequency of 1 millisecond

3) induced

4) a third-party DDE receiver.

For neophyte adepts - like me, it will also be useful.

;)

 

At the end of the night:

Files:
experts.zip  1 kb
 

I would like to add my own two cents:

The performance of Expert Advisors with the indicator code entirely placed in the Expert Advisor is often about three times faster than that of their counterparts that call custom indicators. This is true for the variants with very heavy indicator calculations. If these calculations are very light, there will be no difference. The EMA indicator has too primitive calculation to use it for such measurements. In some of my recent articles on this site I even presented a variant of the Expert Advisor with a very heavy indicator calculation of the JMA. The variant without indicator calls is three times faster.

I personally have no desire to prove anything to anyone; I just draw my own conclusions, which I have seen with my own eyes and not once; though, of course, I do not do this kind of things forever, and it may well be that the last builds of MT4 made this picture look somehow different. And even in MT5 at first it was absolutely the same. But I don't keep track of such details and therefore I cannot assert that it is the same now.

 

GODZILLA:

In some of my recent articles on this site I even posted a variant of the Expert Advisor with a very heavy indicator calculation of JMA. The variant with code without indicator calls works three times faster.

Here? The conclusion is simple, there are 3 possibilities:

1. the code without indicator calls is written incorrectly, which is unlikely.

2. the indicator is written ineffectively.

3. The figures shown do not reflect the reality.

 
GODZILLA:

I would like to add my own two cents:

The performance of Expert Advisors with the indicator code entirely placed in the Expert Advisor is often about three times faster than that of their counterparts that call custom indicators. This is true for the variants with very heavy indicator calculations. If these calculations are very light, there will be no difference. The EMA indicator has too primitive calculation to use it for such measurements. In some of my recent articles on this site I even presented a variant of the Expert Advisor with a very heavy indicator calculation of the JMA. The variant without indicator calls is three times faster.

I personally have no desire to prove anything to anyone; I just draw my own conclusions, which I have seen with my own eyes and not once; though, of course, I do not do this kind of things forever, and it may well be that the last builds of MT4 made this picture look somehow different. And even in MT5 at first it was absolutely the same. But I don't keep track of such details and therefore I cannot assert that it is the same now.


Don't be ridiculous. You just haven't learned how to write indicators yet.

After such heresy:

//---- ЭМУЛЯЦИЯ ИНДИКАТОРНЫХ БУФЕРОВ
  int NewSize = iBars(symbol, timeframe);
  //----  Проверка на смену нулевого бара
  if(ArraySize(Ind_Buffer0) < NewSize)
    {
      //---- Установить прямое направление индексирования в массиве 
      ArraySetAsSeries(Ind_Buffer0, false);
      ArraySetAsSeries(Ind_Buffer1, false);
      ArraySetAsSeries(Ind_Buffer2, false);
      //---- Изменить размер эмулируемых индикаторных буферов 
      ArrayResize(Ind_Buffer0, NewSize); 
      ArrayResize(Ind_Buffer1, NewSize); 
      ArrayResize(Ind_Buffer2, NewSize); 
      //---- Установить обратное направление индексирования в массиве 
      ArraySetAsSeries(Ind_Buffer0, true);
      ArraySetAsSeries(Ind_Buffer1, true);
      ArraySetAsSeries(Ind_Buffer2, true); 
    } 
//----

you could have refrained from your opinion in this thread altogether.

 

Debunking fallacy #1: you can do without IndicatorCounted()

An indicator with it:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

extern double Alpha = 0.9;

double EMA[];

int init()
{
   SetIndexBuffer(0, EMA);
   return(0);
}

int start()
{
   int toCount = MathMin(Bars - 1, Bars - IndicatorCounted());
   if (toCount == Bars - 1) EMA[Bars - 1] = Open[Bars - 1];
   for(int i = toCount - 1; i >= 0; i--)
   {
      EMA[i] = (1 - Alpha)*Open[i] + Alpha*EMA[i + 1];
   }
   return(0);
}

Without it, on the principle of hrenfx

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow

extern double Alpha = 0.9;

double EMABuffer[];

double GetPrice( int Shift )
{
  return(Open[Shift]);
}

double EMA;

int init()
{
   EMA = GetPrice(Bars - 1);

   SetIndexBuffer(0, EMABuffer);
   return(0);
}

double GetEMA()
{
   static int PrevTime = 0;

   if (PrevTime == Time[0])
      return(EMA);

   int i = iBarShift(Symbol(), Period(), PrevTime) - 1;

   PrevTime = Time[0];
   while (i >= 0)
   {
      EMA = EMA * Alpha + (1 - Alpha) * GetPrice(i);
      EMABuffer[i] = EMA;
      i--;
   }
   return(EMA);
}

void start()
{
  GetEMA();
}

Then we apply the indices to the chart and emulate the loss of connection while the automaton is running. Result:


 

Yeah, I researched the topic a bit too. Of course, it's really bullshit to mess around with the platform developers' bullshit, but whatever.

You've converted my EA into an indicator. Like you, I was sure 24 hours ago that indicator of Expert Advisor and indicator of simple EA must show the same results, because both of them are triggered on tick. But they are triggered differently. The first tick after the appearance of the connection is not the same for the EA as for the indicator drawn from the EA. You can check it yourself.

The above screenshot shows that the EA (not the indicator from the EA) is compared to iCustom after the connection break. The communication breakdown goes without any problems there.

 

I assume that on the first tick after a connection break, the indicator does not trigger immediately. To be more exact, the indicator waits for IndicatorCounted() function to be executed. But this function can be executed (depending on the connection) up to several seconds. I.e., here is the scheme:

  1. First tick after a connection failure.
  2. Indicator has started.
  3. IndicatorCounted() is executed (it seems that right after the indicator is started, even if IndicatorCounted() is not present in the indicator body) for some time.
  4. After receiving the result, the trading environment is updated.
  5. And the indicator starts to execute its code as if it was started not at the first tick, but at the last tick before the IndicatorCounted() result.

P.S. Testing on build 226.

 
It turns out that for the absolute reliability of "all in one" EAs we should make a start call of the Empty indicator and RefreshRates() at the very beginning of the function. This will guarantee the loading of history (after the break) and the execution of the EA on the first tick, corresponding to the already loaded history.
 
hrenfx:
It turns out that for the absolute reliability of "all in one" EAs we should make a start call of the Empty indicator and RefreshRates() at the very beginning of the function. This will guarantee the loading of history (after the break) and the execution of the EA on the first tick, corresponding to the already loaded history.


And can you post the research and checks on this guess?

hmmm... If so, and it gives a guarantee of loading, then it's a very good option.

I saw a ForexTools thread where there was no solution to the problem of swapping history at the moment of starting the terminal and the Expert Advisor.