how can I set color to a bar when this bar is above ATR value?

 

I adapted this code, but this is not working...I appreciate some tips.


cheers


//+------------------------------------------------------------------+
//|                                                   cand_color.mq5 |
//|                                                             ProF |
//|                                                          http:// |
//+------------------------------------------------------------------+
#property copyright "ProF"                      //Author
#property indicator_chart_window                //Indicator in separate window

//Specify the number of buffers

#property indicator_buffers 6

//Specify the names, shown in the Data Window
#property indicator_label1 "Open;High;Low;Close"

#property indicator_plots 1                     //Number of graphic plots
#property indicator_type1 DRAW_COLOR_CANDLES    //Drawing style - color candles
#property indicator_width1 3                    //Width of the graphic plot (optional)

//Declaration of buffers
double buffer_open[],buffer_high[],buffer_low[],buffer_close[]; //Buffers for data
double buffer_color_line[]; //Buffer for color indexes

double buffer_tmpa[1];

double buffer_ATR[];

int handle_atr=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   /**
           *       The order of the buffers assign is VERY IMPORTANT!
           *  The data buffers are first
           *       The color buffers are next
           *       And finally, the buffers for the internal calculations.
           */
//Assign the arrays with the indicator's buffers
   SetIndexBuffer(0,buffer_open,INDICATOR_DATA);
   SetIndexBuffer(1,buffer_high,INDICATOR_DATA);
   SetIndexBuffer(2,buffer_low,INDICATOR_DATA);
   SetIndexBuffer(3,buffer_close,INDICATOR_DATA);

//Assign the array with color indexes with the indicator's color indexes buffer
   SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(5,buffer_ATR,INDICATOR_CALCULATIONS);

//Define the number of color indexes, used for a graphic plot
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

//Set color for each index
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrAqua);   //Zeroth index -> Blue
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Orange); //First index  -> Orande
   
   handle_atr=iATR(_Symbol,_Period,14);
   
  // ArraySetAsSeries( buffer_ATR,true );                          
     
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator calculation 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[])
  {
//In the loop we fill the data buffers and color indexes buffers for each bar
   for(int i=prev_calculated; i<=rates_total-1; i++)
     {

      //CopyBuffer(handle_atr,0,BarsCalculated(handle_atr)-i-1,1,buffer_tmpa);

      //CopyBuffer(handle_atr,0,BarsCalculated(handle_atr)-i-1,1,buffer_tmpa);

      buffer_ATR[i]=buffer_tmpa[0];

      //Set data for plotting
      buffer_open[i]=open[i];  //Open price
      buffer_high[i]=high[i];  //High price
      buffer_low[i]=low[i];    //Low price
      buffer_close[i]=close[i];//Close price

      int colora =1;

      double size = high[i] - low[i];
      double body = open[i] - close[i];

      double atrx = buffer_ATR[i];


      if (atrx>size) break;

      if(body<0)
        {

         body=body*-1;
         colora=0;

        }

      double tail = size-body;

      
      if(tail==0)

        {

         buffer_color_line[i]=colora;

        }

      else

        {

         if((body/size) > 0.58)

            buffer_color_line[i]=colora;

        }
     }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   return(rates_total-1); //Return the number of calculated bars,
//Subtract 1 for the last bar recalculation
  }
//+------------------------------------------------------------------+

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