weird bug in indicator

 

Hi 

I'm trying to write my first indicator - at the moment its simply plotting the SMA (red  in chart below), and SMA at 60min and 120min SHIFT (purple and blue respectively). When I test it over the last few months I get a number of regions where the SMA lines hold the same value for around a week eg Nov 23 to Dec 1st in the GBPUSD M15 chart. 

Can anyone suggest what might be casuing it? Code below

Thanks

Chris



//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                                     Copyright 2021, Chris Arthur |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Chris Arthur"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window 
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDarkOrchid
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrRoyalBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- input parameters
input int      minutes = 60;
input int      offset = 60;
input int      Input3;
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   SetIndexBuffer(2,Label3Buffer);
   
//---
   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 uncalculatedBar = rates_total - prev_calculated;
   
   for (int i =0; i <uncalculatedBar; i++){
      Label1Buffer[i] = iMA(_Symbol,PERIOD_M1, minutes, 0, MODE_SMA, PRICE_CLOSE,0);
      Label2Buffer[i] = iMA(_Symbol,PERIOD_M1, minutes, 0, MODE_SMA, PRICE_CLOSE,offset);
      Label3Buffer[i] = iMA(_Symbol,PERIOD_M1, minutes, 0, MODE_SMA, PRICE_CLOSE,offset*2);  
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
Capture.JPG  166 kb