//+------------------------------------------------------------------+ //| cand_color_RSI.mq5 | //| ProF | //| http:// | //+------------------------------------------------------------------+ #property copyright "ProF" //Author #property indicator_chart_window //Indicator in separate window //Specify the number of indicator's buffers //4 buffers for candles + 1 buffer for color indexes + 1 buffer to store the data of RSI #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 - colored candles #property indicator_width1 3 //Width of a line (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_tmp[1]; //Temporary buffer for RSI values double buffer_RSI[]; //Indicator buffer for RSI int handle_rsi=0; //Handle of the RSI indicator //+------------------------------------------------------------------+ //| Set colors for a graphic plot | //+------------------------------------------------------------------+ /* * The function sets colors for a graphic plot * 50 colors from the Green to Blue. * The index of a graphic plot is passed to the function. */ void setPlotColor(int plot) { PlotIndexSetInteger(plot,PLOT_COLOR_INDEXES,50); //Specify the number of colors //In the loops we specify the colors for(int i=0;i<=24;i++) { PlotIndexSetInteger(plot,PLOT_LINE_COLOR,i,StringToColor("\"255,1,"+IntegerToString(i*7)+"\"")); } for(int i=0;i<=24;i++) { PlotIndexSetInteger(plot,PLOT_LINE_COLOR,i+25,StringToColor("\"0,"+IntegerToString(175-i*7)+",175\"")); } } //+------------------------------------------------------------------+ //| Get index of the color | //+------------------------------------------------------------------+ /* * The function returnes the index of the color. * The first parameter is the current value of the indicator. * The second parameter is the minimal value of the indicator. * The third parameter is the maximal value of the indicator. */ int getPlotColor(double current,double min,double max) { return((int)NormalizeDouble((50/(max-min))*current,0)); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { /** * The order of the indicator's buffers 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 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 the color indexes buffer SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX); //Assign the array with RSI indicator buffer SetIndexBuffer(5,buffer_RSI,INDICATOR_CALCULATIONS); //Specify color indexes setPlotColor(0); //Get handle of the RSI indicator, it's necessary get its values handle_rsi=iCustom(_Symbol,_Period,"Examples\\RSI",14); return(0); } //+------------------------------------------------------------------+ //| 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[]) { //For each bar we fill the data buffers and buffer with color indexes using the loop for(int i=prev_calculated;i<=rates_total-1;i++) { //Copying the RSI indicator data to the temporary buffer buffer_tmp CopyBuffer(handle_rsi,0,BarsCalculated(handle_rsi)-i-1,1,buffer_tmp); //Then copying the data from the termporary buffer buffer_RSI[i]=buffer_tmp[0]; //Specify the 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 //Paint the candles depending on RSI indicator values //RSI = 0 - candle is Green //RSI = 100 - candle is Blue //0