Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1171

 
Igor Zakharov:

Does it pump up the history?

It probably does. But I'm not 100% sure. How do you check this, Printers change the number of bars?

Igor Zakharov:

You don't have a recalculation for this case.

Thanks, looks like it.

Igor Zakharov:

And the newindicator buffer items appearing are filled with rubbish.

It looks like not only the new ones, but the old ones too. I have a feeling that not only arrows are randomly drawn, but the indicator line breaks while it shouldn't. Please advise how to organize recalculation in case of history swap or where to look for example.

 
Alexey Viktorov:

I made a mistake in inserting this add-on separately. You should only put the arrows when the buffer changes. At the same time, do not forget to put an empty value in the buffer in all other cases.

It would even be better to put an empty value at once, and fill one of the buffers with an arrow when the trend changes.

Thank you for your reply.

I checked the original indicator and it turns out it was not me who messed up but originally it was wrongly written. I.e. even without my modifications it also crashes when swapping history.

 
This is the first time I've asked a question and not heard anything back. Some kind of selective help for newcomers.
 
novichok2018:
This is the third time I have asked a question and got silence in reply. This is a kind of selective help for newbies.

the first thing that catches your eye is that you create a graphical trendline object with the name LowLine and do not delete it later or create similar objects with different names...

You cannot run ObjectCreate() with the same name several times - it will only work the first time, then there will be an error.


There is also a problem with determining the fractals, you try to find the fractal on the bar #2 after the bar opening, usually perform a cycle on the bars with a call of the fractal indicator and break the cycle when the first fractal is found, and obtain the bar number, on which the fractal was

 
Igor Makanu:

There is also a problem with the definition of fractals, you try to find a fractal on the bar opening #2, usually do a cycle on the bars with the call of the fractal indicator and break the cycle when the first fractal is found, and get the bar number on which the fractal was

Thank you!

Indeed, I don't understand how to get the numbers of the bars where the fractal appeared, because it appears two bars later. That's why I catch it on the second bar. Alert displays the number of fractals in a specified period, but how can I set the point of the second fractal to draw the trend line? It is not clear how to do it as per your recommendation.

The called fractal indicator draws fractals on all available history. I am trying to solve the task of drawing the trend line by a fractal falling within a certain period of the day, taking into account the fractals of the previous day and automatically rebuilding the line according to the last fractal. And there is a lack of knowledge.

 
novichok2018:

Thank you!

Really, I don't understand how to get the numbers of the bars where the fractal appeared, as it appears two bars late. That's why I catch it on the second bar. Alert displays the number of fractals in a specified period, but how can I set the point of the second fractal to draw the trend line? It is not clear how to do it as per your recommendation.

The called fractal indicator draws fractals on all available history. I am trying to solve the task of drawing the trend line by a fractal falling within a certain period of the day, taking into account the fractals of the previous day and automatically rebuilding the line according to the last fractal. And there is a lack of knowledge.

Are you sure you need to catch on the SECOND bar?

Here are the tests:

Forum on trading, automated trading systems and testing trading strategies

MQL5: Examples.

Vladimir Karputov, 2018.03.19 05:54

  • 2.3. iFractals. Two important factors to consider

There are two factors to consider when working with fractals:

Factor one

Fractal on the bars from "rates_total-5" to"rates_total-3" can not be redrawn - it follows from the indicator"Fractals.mq5" design (open code of the indicator is located in [data folder]\MQL5\Indicators\Examples\Fractals.mq5) - as the bars in the intervalfrom "rates_total-5" to"rates_total-3" are already formed

//---
   if(prev_calculated<7)
     {
      limit=2;
      //--- clean up arrays
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else limit=rates_total-5;

   for(i=limit;i<rates_total-3 && !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

Fig. 1. This is how the "Fractals" indicator works. Numbering of files from the position of the indicator "Fractals.mq5"

It means that when we receive data in the Expert Advisor from the iFractals indicator, on the "rates_total-5" and "rates_total-4" bars (numbering of the bars from the "Fractals.mq5" indicator position) there will be a fractal, which is guaranteed not to be re-rendered.


And here is the moment, when the fractal is formed on the bar "rates_total-5" - at the moment, when there is a new bar on the right, January 2, 03:00 (numbering of the files from the position of the indicator "Fractals.mq5") :

Fractals, 5 bar

Fig. 2. The moment when the fractal is formed on the bar "rates_total-5"

The second factor

The fractal indicator uses EMPTY_VALUE instead of "0.0" as an empty value. The exception is the first initialization, when the indicator buffers are initialized with zero (this is done not by the indicator "Fractals.mq5", but by MQL5 when creating an array and linking it with an indicator buffer).


 
novichok2018:

It's not clear how to do it from your recommendation either.

Here's a function for finding a fractal, just for an Expert Advisor, it worked for me

https://www.mql5.com/ru/forum/160683/page968#comment_13214633

 
Vladimir Karputov:

Are you sure you should be catching on the SECOND bar?

Here are the tests:


Yes, thank you. No redraw on the third bar. Only it doesn't change the essence of the problem.

 
Igor Makanu:

Here's a function for finding a fractal, just for an EA, it worked for me

https://www.mql5.com/ru/forum/160683/page968#comment_13214633

Thank you, it works.

I only do not understand how to reflect the appearance of a new fractal in the code. Because barfrup_1 is always smaller than barfrup_2, so the jump in numbering barfrup_1 when a new fractal appears gives nothing, because it remains less than barfrup_2.

One more thing: I don't understand how to extract the high values for barfrup_1 and barfrup_2.

 
novichok2018:

One more thing: I don't understand how to extract high values for barfrup_1 and barfrup_2.

Throw a fractal indicator on the chart and a test EA with this function

and reprinter the found values by passing to my functionMODE_UPPER and MODE_LOWER

novichok2018:

Thank you, it works.

I only do not understand how to render the occurrence of a new fractal in the code.

You need to remember the bar time; when a new bar appears, the numbering will change, while the bar open time is always constant.

I.e., when you open my code, remember the time of the bar where the fractal was detected, then open it again - find the bar and compare the time of the bar with the remembered one - the time is different, it means a new fractal