MQL5 Indicator

 

Hello, I have developed an indicator that should change the color alternately with every candlestick, but the color remains the same all the time. I would be very grateful for any help.

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                        Copyright 2018, Arthur S. |
//|                    https://www.mql5.com/de/users/michael12345678 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Arthur S."
#property link      "https://www.mql5.com/de/users/michael12345678"
#property version   "1.00"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1

#property indicator_type1 DRAW_COLOR_CANDLES

double OpenBuffer[];
double HighBuffer[];
double LowBuffer[];
double CloseBuffer[];
double ColorBuffer[];

bool Wechsel=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{  
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ColorBuffer,INDICATOR_COLOR_INDEX);
   
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrBlue);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrRed);
   
   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[])
{
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(OpenBuffer,true);
   ArraySetAsSeries(HighBuffer,true);
   ArraySetAsSeries(LowBuffer,true);
   ArraySetAsSeries(CloseBuffer,true);
   
   OpenBuffer[0]=open[0];
   HighBuffer[0]=high[0];
   LowBuffer[0]=low[0];
   CloseBuffer[0]=close[0];
   
   if(isNewBar()==true)
   {
      if(Wechsel==true)
      {
         ColorBuffer[0]=0;
      
         Wechsel=false;
      }
      if(Wechsel==false)
      {
         ColorBuffer[0]=1;
      
         Wechsel=true;
      }
   }
   
   return(rates_total);
}
//+------------------------------------------------------------------+
bool isNewBar()
{
   static datetime last_time=0;
   
   datetime lastbar_time=SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
   
   if(last_time==0)
   {
      last_time=lastbar_time;
      return(false);
   }
   
   if(last_time!=lastbar_time)
   {
      last_time=lastbar_time;
      return(true);
   }
   
   return(false);
}
 
      if(Wechsel==true)
      {
         ColorBuffer[0]=0;
      
         Wechsel=false;
      }
      else
      {
         ColorBuffer[0]=1;
      
         Wechsel=true;
      }
 
It still doesn't work.
 

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(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(time,true);
   ArraySetAsSeries(OpenBuffer,true);
   ArraySetAsSeries(HighBuffer,true);
   ArraySetAsSeries(LowBuffer,true);
   ArraySetAsSeries(CloseBuffer,true);
   ArraySetAsSeries(ColorBuffer,true);
   
   OpenBuffer[0]=open[0];
   HighBuffer[0]=high[0];
   LowBuffer[0]=low[0];
   CloseBuffer[0]=close[0];
   
   static datetime last_time=-1;
   if(last_time!=time[0])
   {
      last_time = time[0];
      if(Wechsel==true)
      {
         ColorBuffer[0]=0;
      
         Wechsel=false;
      }
      else
      {
         ColorBuffer[0]=1;
      
         Wechsel=true;
      }
   }
   return(rates_total);
}
 
Thank you so much!!!
Reason: