The indicator buffer is showing an unusually large number like '5161657722...' in the Data Window.. Please help me solve it...

 

Buffer & Plot Arrow

👆 Please see the screenshot (Yellow Colour Marked).
The indicator buffer is displaying an unusually large number like '5161657722...' in the Data Window, which seems to be a bug. The chart is correctly plotting Downward & Upward arrows, but the corresponding buffer value is incorrect. Please help me fix this issue.


Buffer & Arraow

👆 Please see the blue colour marked in the screenshot
The upward and downward arrows are plotted correctly on the chart. However, in the Data Window, both 'UP Trend' and 'Down Trend' buffers are showing the same value. This seems to be a bug in the indicator. Please help me fix this issue.


Indicator Code :-

//+------------------------------------------------------------------+
//|                                               Test Indicator.mq5 |
//|                                            Source Code by Vikram |
//|                                            Vik20010219@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Source Code by Vikram"
#property link      "Vik20010219@gmail.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

#property indicator_label1 "UP Trend"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDodgerBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_label2 "Down Trend"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

double Up_BOS[];
double Down_BOS[];

input int maxBars     = 500;     // Bars to check
input int swingLength = 17;      // Swing detection range
input int shiftOffset = 1;       // Future candle offset for break confirmation

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ChartSetInteger(0, CHART_SHOW_GRID, false);

   SetIndexBuffer(0, Up_BOS, INDICATOR_DATA);
   SetIndexBuffer(1, Down_BOS, INDICATOR_DATA);

   PlotIndexSetInteger(0, PLOT_ARROW, 216);
   PlotIndexSetInteger(1, PLOT_ARROW, 216);

   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, swingLength);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, swingLength);

   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);

   PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, 10);
   PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, -10);

   IndicatorSetInteger(INDICATOR_DIGITS, Digits());

   ArraySetAsSeries(Up_BOS, true);
   ArraySetAsSeries(Down_BOS, true);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Deinitialization                                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0, "SwingPoint_");
   ObjectsDeleteAll(0, "BreakUP_");
   ObjectsDeleteAll(0, "BreakDown_");
  }

//+------------------------------------------------------------------+
//| Main Indicator Logic                                             |
//+------------------------------------------------------------------+
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[])
  {
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(open, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   ArraySetAsSeries(close, true);
   ArraySetAsSeries(tick_volume, true);
   ArraySetAsSeries(volume, true);
   ArraySetAsSeries(spread, true);

   if(rates_total < swingLength * 2)
      return 0;

   static double swing_H = -1;
   static double swing_L = -1;

   for(int bar = swingLength; bar < MathMin(rates_total - swingLength - shiftOffset, maxBars) ; bar++)
     {
      bool isSwingHigh = true;
      bool isSwingLow  = true;

      for(int j = 1; j <= swingLength; j++)
        {
         if(high[bar] <= high[bar - j] || high[bar] <= high[bar + j])
            isSwingHigh = false;

         if(low[bar] >= low[bar - j] || low[bar] >= low[bar + j])
            isSwingLow = false;
        }

      if(isSwingHigh)
        {
         swing_H = high[bar];
         drawSwingPoint("SwingPoint_" + TimeToString(time[bar]), time[bar], swing_H, 217, clrBlue, -1);

         // Check if future price breaks the swing high
         for(int i = bar - 1; i >= MathMax(0, bar - 100); i--)
           {
            if(swing_H > 0 && close[i] > swing_H && close[i + shiftOffset] > swing_H)
              {
               drawBreakLevel("BreakUP_" + TimeToString(time[bar]),
                              time[bar], swing_H,
                              time[i + shiftOffset], swing_H, clrDodgerBlue, -1);

               Up_BOS[bar] = swing_H;
               break;
              }
           }
        }

      if(isSwingLow)
        {
         swing_L = low[bar];
         drawSwingPoint("SwingPoint_" + TimeToString(time[bar]), time[bar], swing_L, 218, clrRed, 1);

         // Check if future price breaks the swing low
         for(int i = bar - 1; i >= MathMax(0, bar - 100); i--)
           {
            if(swing_L > 0 && close[i] < swing_L && close[i + shiftOffset] < swing_L)
              {
               drawBreakLevel("BreakDown_" + TimeToString(time[bar]),
                              time[bar], swing_L,
                              time[i + shiftOffset], swing_L, clrRed, 1);

               Down_BOS[bar] = swing_L;
               break;
              }
           }
        }
     }

   return(rates_total);
  }




//+------------------------------------------------------------------+

//| Draw Swing Point Arrow and Label                                 |

//+------------------------------------------------------------------+

void drawSwingPoint(string objName, datetime time, double price, int arrowCode,

                    color clr, int direction)

  {
   if(ObjectFind(0, objName) < 0)
     {
      ObjectCreate(0, objName, OBJ_ARROW, 0, time, price);
      ObjectSetInteger(0, objName, OBJPROP_ARROWCODE, arrowCode);
      ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
      ObjectSetInteger(0, objName, OBJPROP_WIDTH, 1);
      ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, 10);
      if(direction > 0)
         ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_TOP);
      if(direction < 0)
         ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_BOTTOM);


      /*
      string txt = " BoS";
      string labelName = objName + "_label";
      ObjectCreate(0, labelName, OBJ_TEXT, 0, time, price);
      ObjectSetInteger(0, labelName, OBJPROP_COLOR, clr);
      ObjectSetInteger(0, labelName, OBJPROP_FONTSIZE, 10);
      if(direction > 0)
        {
         ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_TOP);
         ObjectSetInteger(0, labelName, OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
         ObjectSetString(0, labelName, OBJPROP_TEXT, "?" + txt);
        }
      else
        {
         ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
         ObjectSetInteger(0, labelName, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetString(0, labelName, OBJPROP_TEXT, "?" + txt);
        }
        */
     }
  }



//+------------------------------------------------------------------+

//| Draw Break Line and Label                                        |

//+------------------------------------------------------------------+

void drawBreakLevel(string objName, datetime time1, double price1,

                    datetime time2, double price2, color clr, int direction)

  {
   if(ObjectFind(0, objName) < 0)
     {
      ObjectCreate(0, objName, OBJ_TREND, 0, time1, price1, time2, price2);
      ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
      ObjectSetInteger(0, objName, OBJPROP_WIDTH, 2);
      string labelName = objName + "_label";
      ObjectCreate(0, labelName, OBJ_TEXT, 0, time2, price2);
      ObjectSetInteger(0, labelName, OBJPROP_COLOR, clr);
      ObjectSetInteger(0, labelName, OBJPROP_FONTSIZE, 10);
      if(direction > 0)
        {
         ObjectSetInteger(0, labelName, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
         ObjectSetString(0, labelName, OBJPROP_TEXT, "BOS");
        }
      else
        {
         ObjectSetInteger(0, labelName, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
         ObjectSetString(0, labelName, OBJPROP_TEXT, "BOS");
        }
     }
  }
//+------------------------------------------------------------------+



I tested the indicator in the Strategy Tester, and it displayed the buffer values correctly — everything worked.
However, if the results different between the Strategy Tester and the live chart,
Please try attaching the indicator to a 'GBPUSD' or any symbol chart on the Daily timeframe to verify the issue.
 

large number could be

EMPTY_VALUE

which you define in code 

 
Rajesh Kumar Nait #:

large number could be

which you define in code 

Nope. 

It's uninitialized buffers.

 
Alain Verleyen #:

Nope. 

It's uninitialized buffers. Look for // INIT comment where i tried to intialize

Great! So as per feedback, you should initialize buffers and then further troubleshoot, for example 

if(rates_total < swingLength * 2)
      return 0;

   ArraySetAsSeries(time, true);
   ArraySetAsSeries(open, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   ArraySetAsSeries(close, true);

   for(int bar = swingLength; bar < MathMin(rates_total - shiftOffset, maxBars); bar++) {
      Up_BOS[bar] = EMPTY_VALUE; // INIT
      Down_BOS[bar] = EMPTY_VALUE; //INIT

      bool isSwingHigh = true;
      bool isSwingLow  = true;

      for(int j = 1; j <= swingLength; j++) {
         if(high[bar] <= high[bar - j] || high[bar] <= high[bar + j]) isSwingHigh = false;
         if(low[bar] >= low[bar - j] || low[bar] >= low[bar + j]) isSwingLow = false;
      }

      if(isSwingHigh) {
         double swing_H = high[bar];
         drawSwingPoint("SwingPoint_H_" + IntegerToString(bar), time[bar], swing_H, 217, clrBlue, -1);

         for(int i = bar - 1; i >= MathMax(0, bar - 100); i--) {
            if(i + shiftOffset >= rates_total) continue;
            if(close[i] > swing_H && close[i + shiftOffset] > swing_H) {
               drawBreakLevel("BreakUP_" + IntegerToString(bar),
                              time[bar], swing_H,
                              time[i + shiftOffset], swing_H, clrDodgerBlue, -1);
               Up_BOS[bar] = swing_H;
               break;
            }
         }
      }

      if(isSwingLow) {
         double swing_L = low[bar];
         drawSwingPoint("SwingPoint_L_" + IntegerToString(bar), time[bar], swing_L, 218, clrRed, 1);

         for(int i = bar - 1; i >= MathMax(0, bar - 100); i--) {
            if(i + shiftOffset >= rates_total) continue;
            if(close[i] < swing_L && close[i + shiftOffset] < swing_L) {
               drawBreakLevel("BreakDown_" + IntegerToString(bar),
                              time[bar], swing_L,
                              time[i + shiftOffset], swing_L, clrRed, 1);
               Down_BOS[bar] = swing_L;
               break;
            }
         }
      }
   }
 
Rajesh Kumar Nait #:

Great! So as per feedback, you should initialize buffers and then further troubleshoot, for example 

Sorry, I didn't mind the 'EMPTY_VALUE' code.  
Thank you for helping to me 🙏

Thank you for sharing the link with me 🙏