fractals ring buffer = Ghost Arrow

 

Hello, I used the Indicator The class for drawing the Fractals using the ring buffer from Konstantin Gruzdev

https://www.mql5.com/en/code/1422

Ghost arrows are displayed there with buffer values, but I can't find the error.

Unfortunately, the error does not appear in the visual tester either, only in the live chart.

Can someone help me there?

 

 

The same problem is also in the standard indicator Fractals from Metaquotes

  ?

//+------------------------------------------------------------------+
//|                                                     Fractals.mq5 |
//|                   Copyright 2009-2020, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2020, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//--- 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  Gray
#property indicator_color2  Gray
#property indicator_label1  "Fractal Up"
#property indicator_label2  "Fractal Down"
//--- 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);
  }
//+------------------------------------------------------------------+
//|  Fractals on 5 bars                                              |
//+------------------------------------------------------------------+
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 &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(rates_total<5)
      return(0);

   int start;
//--- clean up arrays
   if(prev_calculated<7)
     {
      start=2;
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else
      start=rates_total-5;
//--- main cycle of calculations
   for(int i=start; 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);
  }

//+------------------------------------------------------------------+
 
Alexander P. #: The same problem is also in the standard indicator Fractals from Metaquotes?

What build of MetaTrader are you using?

I'm using build 3540 (the latest official release), and I'm not having any such issue with any indicator, including the standard Fractal indicator nor the example Fractal indicator from Metaquotes.

Are you perhaps using a beta build of MetaTrader instead of the latest official release?

EDIT: Please note that official build 3550 will be released today but mine has not been updated yet.

 

I have now updated to 3550 and will test next week when the market is open again.

The problem was not always but only approx. every 10-20 minutes.

Many Thanks.

 
  1.    for(int i=start; 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];

    Your loop is non-series, but you haven't set the indexing direction of high/low nor the buffers.

    In MT5, you must set the direction.

    To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
              Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
  2.    else
          start=rates_total-5;

    Why are you redrawing all bars (except first 5) each tick.
              How to do your lookbacks correctly #9#14 & #19 (2016)

 

Forum on trading, automated trading systems and testing trading strategies

fractals ring buffer = Ghost Arrow

William Roeder, 2022.12.17 14:55

  1.    for(int i=start; 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];

    Your loop is non-series, but you haven't set the indexing direction of high/low nor the buffers.

    In MT5, you must set the direction.

  2.    else
          start=rates_total-5;

    Why are you redrawing all bars (except first 5) each tick.
              How to do your lookbacks correctly #9#14 & #19 (2016)


It works, problem solved.

Thanks. 👍