Navigation:Home > Content >

rsi_chart_bars_1.02.mq4

Time: 2014-02-09 | Download file:rsi_chart_bars_1.02.mq4

//------------------------------------------------------------------
#property copyright "free code"
#property link      "free code"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Orange
#property indicator_color3 DeepSkyBlue
#property indicator_color4 Orange
#property indicator_color5 Blue
#property indicator_color6 Red
#property indicator_color7 Blue
#property indicator_color8 Red
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width7 3
#property indicator_width8 3


extern int	RSI_Period		= 14;
extern int  RSI_Price      = 0;
extern int	Overbought1		= 65;
extern int	Overbought2		= 75;
extern int	Oversold2		= 25;
extern int	Oversold1		= 35;
extern int	BarWidth			= 1,
				CandleWidth		= 3;

double Bar11[],Bar12[],Candle11[],Candle12[];
double Bar21[],Bar22[],Candle21[],Candle22[];
		 

//------------------------------------------------------------------
//
//------------------------------------------------------------------
int init()
{
	IndicatorShortName("RSI Candles:("+	RSI_Period+")");
	SetIndexBuffer(0,Bar11);     SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth);
	SetIndexBuffer(1,Bar12);	  SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth);		
	SetIndexBuffer(2,Candle11);  SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth);
	SetIndexBuffer(3,Candle12);  SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth);
	SetIndexBuffer(4,Bar21);     SetIndexStyle(4,DRAW_HISTOGRAM,0,BarWidth);
	SetIndexBuffer(5,Bar22);	  SetIndexStyle(5,DRAW_HISTOGRAM,0,BarWidth);		
	SetIndexBuffer(6,Candle21);  SetIndexStyle(6,DRAW_HISTOGRAM,0,CandleWidth);
	SetIndexBuffer(7,Candle22);  SetIndexStyle(7,DRAW_HISTOGRAM,0,CandleWidth);
	return(0);
}

//
//
//

void SetCandleColor(double& Bar1[],double& Bar2[],double& Candle1[],double& Candle2[], int col, int i)
{
	double high,low,bodyHigh,bodyLow;
	{
		bodyHigh = MathMax(Open[i],Close[i]);
		bodyLow  = MathMin(Open[i],Close[i]);
		high		= High[i];
		low		= Low[i];
	}

	Bar1[i] = low;	Candle1[i] = bodyLow;
	Bar2[i] = low;	Candle2[i] = bodyLow;
	switch(col)
	{
		case 1: 	Bar1[i] = high;	Candle1[i] = bodyHigh;	break;
		case 2: 	Bar2[i] = high;	Candle2[i] = bodyHigh;	break;
	
	}
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);

    
   for (int i=limit; i>=0; i--)
   {
	  Bar11[i]    = EMPTY_VALUE;
	  Bar12[i]    = EMPTY_VALUE;
	  Candle11[i] = EMPTY_VALUE;
	  Candle12[i] = EMPTY_VALUE;
	  Bar21[i]    = EMPTY_VALUE;
	  Bar22[i]    = EMPTY_VALUE;
	  Candle21[i] = EMPTY_VALUE;
	  Candle22[i] = EMPTY_VALUE;
   	  double	rsi	= iRSI(NULL,0,RSI_Period,RSI_Price,i);
   	  if(rsi > Overbought2)	{ SetCandleColor(Bar21,Bar22,Candle21,Candle22,1,i); continue; }
   	  if(rsi > Overbought1)	{ SetCandleColor(Bar11,Bar12,Candle11,Candle12,1,i); continue; }
   	  if(rsi < Oversold2)	{ SetCandleColor(Bar21,Bar22,Candle21,Candle22,2,i); continue; }
   	  if(rsi < Oversold1)	{ SetCandleColor(Bar11,Bar12,Candle11,Candle12,2,i); continue; }
	}
	return(0);
}

Recommend