bug or programming error

To add comments, please log in or register
GmA
35
GmA  

Dear experts!

Could you please clarify if something is wrong with indicator coding or it is a bug of new release 1687? 

Description: Shift back of the painted bars on the chart.  Max bars on chart = 100 000. Number of bars in the history  is bigger than 100 000

This behavior does not presented if Bars in the history  less than Max bars on chart (for example if time frame is M15).

After indicator is inserted to the chart it looks correct till the next bar comes (see GBPCHF_good.jpg). On the next bar  the shift is happening (see GBPCHF_bad.jpg)

Indicator code:


//+------------------------------------------------------------------+
//|                                                     BAR_Test.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                      https://www.noemailr.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.noemailr.com"
#property version   "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

#property indicator_buffers 5
#property indicator_plots 1


double sgBarTrend_O [];
double sgBarTrend_H [];
double sgBarTrend_L [];
double sgBarTrend_C [];
double sgBarTrend_Color  [];

int OnInit()
  {
//--- indicator buffers mapping
   
 SetIndexBuffer(0,sgBarTrend_O,        INDICATOR_DATA);
 SetIndexBuffer(1,sgBarTrend_H,        INDICATOR_DATA);
 SetIndexBuffer(2,sgBarTrend_L,        INDICATOR_DATA);
 SetIndexBuffer(3,sgBarTrend_C,        INDICATOR_DATA);
 SetIndexBuffer(4,sgBarTrend_Color,    INDICATOR_COLOR_INDEX);   
  
 PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_BARS);
 PlotIndexSetInteger(0,PLOT_DRAW_BEGIN, 1);            
 PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);                
 PlotIndexSetInteger(0,PLOT_LINE_WIDTH, 3); 
 PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3);   
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,0, clrGreen);
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,1, clrBlack);
 PlotIndexSetInteger(0,PLOT_LINE_COLOR,2, clrRed);
 PlotIndexSetString (0,PLOT_LABEL,"Bar Trend");   
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{
 int iLastBar = rates_total - 1;
 int i = 0;
 
 sgBarTrend_O [iLastBar]                                        = EMPTY_VALUE;
 sgBarTrend_H [iLastBar]                                        = EMPTY_VALUE;
 sgBarTrend_L [iLastBar]                                        = EMPTY_VALUE;
 sgBarTrend_C [iLastBar]                                        = EMPTY_VALUE;
 
 for(i = prev_calculated; i < iLastBar; i++)   
        {
         sgBarTrend_O [i]                                       = open [i];
         sgBarTrend_H [i]                                       = high [i];
         sgBarTrend_L [i]                                       = low [i];
         sgBarTrend_C [i]                                       = close [i];
         if (i > 0)
                {
                 if (close [i] > close [i - 1])
                        {
                         sgBarTrend_Color [i]           = 0;    
                        }
                 else
                        {
                         if (close [i] < close [i - 1])
                                {
                                 sgBarTrend_Color [i]   = 2;    
                                }
                         else
                                {
                                 sgBarTrend_Color [i]   = 1;    
                                }                                               
                        }
                }
         else
                {        
                 sgBarTrend_Color [i]           = 1;  
                }       
                 
        }
 if (rates_total > 1)
        {       
         return(rates_total - 2);
        }
 else
        {
         return(0);
        }
}



On previous version similar indicator was working properly.

Thank you in advance and

With kind regards

Grigory

Files:
To add comments, please log in or register