///+------------------------------------------------------------------ //| RSIFilter_v1.mq4 //| Copyright © 2006, Forex-TSD.com //| Written by IgorAD,igorad2003@yahoo.co.uk //| http://finance.groups.yahoo.com/group/TrendLaboratory //+------------------------------------------------------------------ #property copyright "Copyright © 2006, Forex-TSD.com " #property link "http://www.forex-tsd.com/" #property indicator_separate_window #property indicator_minimum -1 #property indicator_maximum 1 #property indicator_buffers 4 #property indicator_color1 White #property indicator_color2 Yellow #property indicator_color3 Blue #property indicator_color4 Blue //---- input parameters extern int PeriodRSI=8; //---- indicator buffers double UpBuffer[]; double DnBuffer[]; double UpsBuffer[]; double DnsBuffer[]; //+------------------------------------------------------------------ //| Custom indicator initialization function //+------------------------------------------------------------------ int Chart_Scale,nn,Bar_Width1;//,counted_bars,limit; bool Deinitialized; bool Alert_Allowed; static bool allow = true; static bool disallow = false; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { Deinitialized = false; //Determine the current chart scale (chart scale number should be 0-5) Chart_Scale = ChartScaleGet(); //Set bar widths if(Chart_Scale == 0) {Bar_Width1 = 1;} else {if(Chart_Scale == 1) {Bar_Width1 = 1;} else {if(Chart_Scale == 2) {Bar_Width1 = 2;} else {if(Chart_Scale == 3) {Bar_Width1 = 4;} else {if(Chart_Scale == 4) {Bar_Width1 = 8;}//6 else {Bar_Width1 = 16;} }}}}//12 //string short_name; //---- indicator line SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,Bar_Width1); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,Bar_Width1); SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,Bar_Width1); SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,Bar_Width1); SetIndexBuffer(0,UpBuffer); SetIndexBuffer(1,DnBuffer); SetIndexBuffer(2,UpsBuffer); SetIndexBuffer(3,DnsBuffer); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); //---- name for DataWindow and indicator subwindow label // short_name="RSI Filter("+PeriodRSI+") (Down trade only when down bars are orange)"; IndicatorShortName("RSI Filter"); SetIndexLabel(0,"UpTrend"); SetIndexLabel(1,"DownTrend"); //---- SetIndexDrawBegin(0,PeriodRSI); SetIndexDrawBegin(1,PeriodRSI); SetIndexDrawBegin(2,PeriodRSI); SetIndexDrawBegin(3,PeriodRSI); //---- return(0); } //+------------------------------------------------------------------ //| RSIFilter_v1 //+------------------------------------------------------------------ int start() { int shift,trend; double RSI0; for(shift=Bars-PeriodRSI-1;shift>=0;shift--) { RSI0=iRSI(NULL,0,PeriodRSI,PRICE_CLOSE,shift); if (RSI0>50) trend=1; if (RSI0<50) trend=-1; if (trend>0) { if (RSI0 > 50 && RSI0 < 80) UpBuffer[shift]=1.0; else UpBuffer[shift] = EMPTY_VALUE; DnBuffer[shift]=0; // UpsBuffer[shift]=0; // DnsBuffer[shift]=0; } if (trend<0) { if (RSI0 < 50 && RSI0 > 20) DnBuffer[shift]=-1.0; else DnBuffer[shift] = EMPTY_VALUE; UpBuffer[shift]=0; //UpsBuffer[shift]=0; //DnsBuffer[shift]=0; } if (trend>0) { if (RSI0 > 80 && RSI0 < 100) UpsBuffer[shift]=1.0; else UpsBuffer[shift] = EMPTY_VALUE; //DnBuffer[shift]=0; //UpBuffer[shift]=0; DnsBuffer[shift]=0; } if (trend<0) { if (RSI0 < 20 && RSI0 > 0) DnsBuffer[shift]=-1.0; else DnsBuffer[shift] = EMPTY_VALUE; //DnBuffer[shift]=0; //UpBuffer[shift]=0; UpsBuffer[shift]=0; } } return(0); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { Chart_Scale = ChartScaleGet(); if(Alert_Allowed == allow) { init(); Alert_Allowed = allow; } else { init(); Alert_Allowed = disallow; } } //+-------------------------------------------------------------------------------------------+ //| Subroutine: Get the chart scale number | //+-------------------------------------------------------------------------------------------+ int ChartScaleGet() { long result = -1; ChartGetInteger(0,CHART_SCALE,0,result); return((int)result); return(0); } //+------------------------------------------------------------------+