Errors, bugs, questions - page 590

 
Swan:

For all the bars the indicator is calculated once - i.e. it may be a little slow on startup on agromadic history.

Subsequently a pair of values is recalculated - everything must work :)

Do not forget that programmers are people who like to manually jump through timeframes in their spare time from programming. And every new timeframe is another deinitialization and initialization of the indicator's anatomy, all calculations will be performed again. Therefore, ArrayInitialize() will be triggered every time, when jumping from one TF to another. If the indicator is complex with several buffers that need re-initialization, the delays will accumulate, and I'm even not speaking about memory overflow, which is allocated automatically.

How naive I am! I always find myself confident, that initialization in OnInit() is enough, and I can fritter away with it at this stage, sinking my head into more pressing tasks in OnCalculate(). But no, I don't. By the way, more or less successful writing of complex indicators hasn't give me a clear understanding why ArrayInitialize() must be contained exactly in OnCalculate(), checking it on each tick, instead of the primary and only initialization in OnInit(). Through my experience, I have only found cases when refusing from this variant immediately caused problems, but about this I will discuss later. For now I would like to note that from the point of view of simple and obvious human logic (rather than code logic) ArrayInitialize() in OnCalculate() looks very reprehensible, taking into account that I have never come across cases where

if(prev_calculated<7) // или < чего-то там...
The first time the program would be triggered more than once - at initial startup. That is, new fractals appear and the condition is silent. So what the hell is it doing in OnCalculate()?

I'm even more naive in my belief that

handle=iFractals(_Symbol,_Period);

I'm supposedly obliged to automatically inherit those clean up's arrays and the effect of economical algorithm from original Fractals.mq5, which is there too, but in a slightly different form. But - again and again no!!! I had to think twice and create my own code based on the indicator, whose handle I use. I remember how I analyzed the code of indicators for the first time and was taken aback when comparing Fractals.mq5 and the example of iFractals from the Help, and realized that the second code was larger than the first one (even after abbreviating it very much). I don't know. Throw all my hats at me, but programmers actually expect to plug something in their code in one line referring to an entire library, class or something voluminous there, but here...

Now I'll reveal the essence of the problem I mentioned earlier. I am attaching the code of the iFractals indicator simplified to the upper fractals. In the initial example, the buffer is filled for the entire history. Let us change the situation by copying only a part of the history. Let's comment out the assignment of the copied values for the first calculation, and set our own smaller value:

values_to_copy=100; // то же, что amount
Now let's jump around on timeframes and be horrified by the fractal artifacts that have appeared. I couldn't think of anything better than to copy automatically uninherited block of code clean up arrays from Fractals.mq5 in order to clean up that part of history where fractals are not needed:
   if(bars_calculated<7)
   {
      ArrayInitialize(FractalUpBuffer,EMPTY_VALUE);
      Print("the condition is true; ArraySize(FractalUpBuffer)=",ArraySize(FractalUpBuffer));
   }
Now everything(with a lot of redundancy!!!) is cleaned up perfectly, and at the same time Print() shows when and how many times reinitialization will work plus displays the buffer size. We can see that it's not 100, but much more. If I need to wipe dust off a table, I wipe the dust off the table instead of cleaning the entire flat. Or is the trick to reassure me at all costs that the memory and time overruns are nothing, you can find a way to solve the problem indirectly and ignore the blatant devouring of resources beyond my control?


Swan:

One fx, some size will have to be set... Why make a curved loop with different bounds, when you can make a direct loop with the same bounds)

Otherwise, the indicator will be based on crutches.

Honestly, I didn't want to be a burden, but I understood in advance that sympathizers would dig through the whole code. It is like in the anecdote about Chapay and Petka, when Vasily Ivanovich returned, asked for a shovel - it turned out to be broken - the horse was buried - the village was attacked by the Whites while Chapay was away. Realizing, that I don't think anyone will want to get into details of other people's code, I can only refer to the indicator output, which (apart from brakes and other stuff) will work out as follows: https://www.mql5.com/ru/forum/1111/page577#comment_119227. And now think about it and say, is it reasonable to think that everything is simple there and to suggest seemingly obvious solutions?

It is not for nothing that I simplify and limit the code before asking anything in any particular part. That's why I'm asking you to limit yourself to just that, and not to exhume the whole horse, unless there's an amateur...

Actually, the fourth - special - buffer is longer in principle than the first three (equal in length), and thanks to SetIndexBuffer() it stretches for the entire history! If we expand the loop bounds to the fourth buffer and at the same time resize the first three arrays to it, then at least the number of elements in the loop will increase, which will increase the estimated time of reading the completely left buffer element segment. This is just the tip of an iceberg of problems, which will emerge with such variant of algorithm. On top of that it will take more time to re-initialize other buffers because their size is larger now. The fourth special array cannot be filled explicitly with EMPTY_VALUE in else, as the indicator has a severe transposition of fractals from other timeframes according to a certain algorithm, where there is no correspondence between the indices of the first three buffers and the fourth buffer...

Swan:

//and EMPTY_VALUE values are assigned to 0 and 1 elements of arrays, mm... and on the last three bars)

How so? Why not all of them? I don't understand this one. Can you explain? Actually, I'm not referring to assigning only actual (effective) values, but to the inevitable scouring of the entire buffer. ArrayInitialize(), as well as many other array functions, are based on a loop that is implicit to end MQL programmers.

The question about memory overrun remains valid, and the developers should think about introducing an additional parameter inArrayInitialize() which would specify the number and even better the limits of buffer reinitialization.

P.S.: I guess I can guess why ArrayInitialize() in OnInit() is not efficient here. Buffers are dynamic, they change size, and in OnInit() they initialize with values only once and for the current length, not knowing yet the actual sizes of buffers in OnCalculate().

Files:
cleanup.mq5  2 kb
 
papaklass:

The indicator in the visualiser is not working:

In the terminal in the online terminal, it works fine:

Would you give any details? How did the indicator get on the visualiser chart?
 
papaklass:

I insert the following lines in the code of the Expert Advisor

I put these three indicators on a clean chart and save the template as an Expert Advisor. The picture is online in my previous post.

I am running the Expert Advisor in the visualizer.

1. Show the saved template

2. Try to run the visualisation without the template (i.e. delete the relevant tpl file beforehand). In the latest, 555 build, the automatically added custom indicators should display correctly.

 
papaklass:

Everything works. Thank you.

Removed the template. In expert in OnInit() prescribed:

Show your template. The indicator should also display normally with the template (i.e. there is a problem and it should be solved)
 
papaklass:

Sending the *.tpl file

Now tried again with template - doesn't work. Removing the template - it works.

Thank you. We'll look into it.
 

x100intraday:

Now think about it and tell me, is it worth believing that everything there is simple and suggesting seemingly obvious solutions?

all geniuses are simple.

I couldn't do the rest. The anecdote about the question on the forum, how to remove tonsils reminds me :)

I'm not sure how to do it... I'm not sure how to do it.

//+------------------------------------------------------------------+
//|                                                     Fractals.mq5 |
//+------------------------------------------------------------------+
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_ARROW
#property indicator_type2   DRAW_ARROW
#property indicator_color1  clrGray
#property indicator_color2  clrGray
#property indicator_label1  "Fractal Up"
#property indicator_label2  "Fractal Down"
//--- input parameters
input int BarsCount=100;
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int    ExtArrowShift=-10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_ARROW,217);
   PlotIndexSetInteger(1,PLOT_ARROW,218);
//---- arrow shifts when drawing
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-ExtArrowShift);
//---- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- initialization done
  }
//+------------------------------------------------------------------+
//|  Fractals                                                        |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,
                const datetime &Time[],
                const double &Open[],
                const double &High[],
                const double &Low[],
                const double &Close[],
                const long &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
   int i,limit;
//---
   if(rates_total<5) return(0);
//---
   if(prev_calculated<7)
     {
      limit=2;
      if(rates_total-2>BarsCount) limit=rates_total-BarsCount;
      PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,limit);//отрисовываются и расчитываются только значения на последних BarsCount барах
      PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,limit);

      for(i=rates_total-2;i<rates_total;i++)//Последним двум барам присваивается EMPTY_VALUE. Исправил циферку в соответствии с iFractal(там фрактал может быть на 2ом баре)
         {
         ExtUpperBuffer[i]=EMPTY_VALUE;
         ExtLowerBuffer[i]=EMPTY_VALUE;
         }
     }
   else
      {
      limit=prev_calculated-3;//Здесь от prev_calculated правильнее считать..
      
      //---Добавленным с появлением нового бара элементам массивов присваиваем значение EMPTY_VALUE//Возможно всё будет нормально и без этого.
      if(rates_total>prev_calculated)
         {
         for(i=prev_calculated;i<rates_total;i++)
            {
            ExtUpperBuffer[i]=EMPTY_VALUE;
            ExtLowerBuffer[i]=EMPTY_VALUE;
            }
         }
      //---
      }
//---
   for(i=limit;i<rates_total-2 && !IsStopped();i++)//Исправил циферку
     {
      //---- Upper Fractal
      if(High[i]>High[i+1] && High[i]>High[i+2] && High[i]>=High[i-1] && High[i]>=High[i-2])
         ExtUpperBuffer[i]=High[i];
      else ExtUpperBuffer[i]=EMPTY_VALUE;
      //---- Lower Fractal
      if(Low[i]<Low[i+1] && Low[i]<Low[i+2] && Low[i]<=Low[i-1] && Low[i]<=Low[i-2])
         ExtLowerBuffer[i]=Low[i];
      else ExtLowerBuffer[i]=EMPTY_VALUE;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
Fractals
Fractals
  • votes: 8
  • 2010.01.26
  • MetaQuotes Software Corp.
  • www.mql5.com
Фракталы (Fractals) — это один из пяти индикаторов торговой системы Билла Вильямса, позволяющий обнаруживать дно или вершину.
 
Swan:

all geniuses are simple.

I couldn't do the rest. The anecdote about the question on the forum, how to remove tonsils reminds me :)

The example of imho orthodox indicator fractals limited. maybe it will help...

Actually, I write the indicator via a handle... But I like the idea of refusing from ArrayInitialize() in favour of explicit manual filling with EMPTY_VALUE values. Thanks, I'll try to make a new mess on it which I hope I won't have to clean up later. Although there will be subtleties and inconveniences, I foresee them in advance... but whatever.
 

Next code:

struct Pos
{
   int x;
   int y;
};

class Test
{
public:
   Test(const Pos& other)
      : pos(other)
   {
      Print("other = {", other.x, ", ", other.y, "}");
      Print("pos = {", pos.x, ", ", pos.y, "}");
   }
   
public:
   Pos pos;
};

int OnInit()
{
   Pos pos = {123, 456};
   Test test(pos);
   
   return(0);
}

Outputs:

2011.12.05 22:01:28 RectLabel (EURUSD,H1) pos = {12, 176314750}
2011.12.05 22:01:28 RectLabel (EURUSD,H1) other = {123, 456}

So, initialization list didn't work, there is rubbish in the structure. Is this a bug or not?

 

Disconnected two agents from the cloud and they still connect to the cloud servers every 30 seconds.

MO 0 Network 00:00:17 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
LK 0 Network 00:00:47 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
RG 0 Network 00:01:17 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
NS 0 Network 00:01:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
RO 0 Network 00:02:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
OK 0 Network 00:02:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
MG 0 Network 00:03:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
DR 0 Network 00:03:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
DN 0 Network 00:04:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
EJ 0 Network 00:04:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
GF 0 Network 00:05:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
RR 0 Network 00:05:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
NN 0 Network 00:06:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
KJ 0 Network 00:06:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
QF 0 Network 00:07:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
HQ 0 Network 00:07:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
PM 0 Network 00:08:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
QI 0 Network 00:08:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
KE 0 Network 00:09:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
NQ 0 Network 00:09:51 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
OM 0 Network 00:10:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
RI 0 Network 00:10:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
LE 0 Network 00:11:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
EP 0 Network 00:11:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
IL 0 Network 00:12:18 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
HH 0 Network 00:12:48 connected to 2.agents.mql5.com (through a proxy server 192.168.0. )
FD 0 Network 00:13:18 connected to 2.agents.mql5.com (through a proxy server

 
Konstantin83:

Disconnected two agents from the cloud and they still connect to the cloud servers every 30 seconds.

Let's go to servicedesk.

Please clarify how exactly did you disconnect? Have you deleted (frozen) the services? Please attach the logs of the problem agents.

The proxy settings in your logs are somewhat strange. Did you write the proxy settings in your agent configs? Please attach common.ini of your agent manager to the application.