RSIFilter_v1
Download scriptThis tool is designed to act as a visual trend filter for your trading charts. By utilizing the Relative Strength Index (RSI)—a common technical indicator that measures the speed and change of price movements—this script identifies specific market directions to help traders distinguish between primary trends and minor price fluctuations.
Core Logic and Functionality
The indicator operates by monitoring the RSI values relative to two primary "extremes" (30 and 70). Here is how it interprets market behavior:
Trend Identification
- Bearish Momentum: When the RSI value drops below 30, the script recognizes a strong downward push.
- Bullish Momentum: When the RSI value climbs above 70, the script recognizes a strong upward push.
Visual Filtering and Mapping Rather than simply plotting a standard line, this tool creates a filtered visual representation in a separate window:
- UpTrend Detection: Once a bullish trend is established, the script maintains a "Blue" indicator signal as long as the RSI remains above a secondary threshold (40). This ensures that the upward trend signal persists during healthy price growth but disappears if momentum weakens significantly.
- DownTrend Detection: Once a bearish trend is established, the script maintains an "OrangeRed" indicator signal as long as the RSI remains below a secondary threshold (60). Similarly, this ensures the downward signal remains active during sustained price declines but clears out if the market shows signs of recovery.
Automated Notifications
To keep traders informed without requiring constant manual oversight of the charts, the script includes an integrated alert system. It monitors for "Trend Flips." Whenever the logic detects a significant shift—moving from a confirmed downward trend to an upward one (or vice versa)—the software will trigger a real-time alert notification. This provides immediate feedback on major shifts in market sentiment.
Summary for the User
In short, this script acts as a "smart filter." It ignores minor market noise and only highlights sustained trends. By providing clear visual cues and automated alerts when a trend changes direction, it helps traders stay aligned with the prevailing market momentum while providing a cleaner, more organized view of price action.
//+------------------------------------------------------------------+
//| 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 -2
#property indicator_maximum 2
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 OrangeRed
//---- input parameters
extern int PeriodRSI=14;
//---- indicator buffers
double UpBuffer[];
double DnBuffer[];
double alertTag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexBuffer(0,UpBuffer);
SetIndexBuffer(1,DnBuffer);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="RSI Filter("+PeriodRSI+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"UpTrend");
SetIndexLabel(1,"DownTrend");
//----
SetIndexDrawBegin(0,PeriodRSI);
SetIndexDrawBegin(1,PeriodRSI);
//----
return(0);
}
//+------------------------------------------------------------------+
//| RSIFilter_v1 |
//+------------------------------------------------------------------+
int start()
{
int shift,trend,prev;
double RSI0;
for(shift=Bars-PeriodRSI-1;shift>=0;shift--)
{
RSI0=iRSI(NULL,0,PeriodRSI,PRICE_CLOSE,shift);
if (RSI0>70) trend=1;
if (RSI0<30) trend=-1;
if(prev==0)prev=trend;
if(trend==-1 && trend != prev && DnBuffer[shift]== 0 && alertTag!=Time[0]){ Alert("RSIFilter changing trend to Up on ",Symbol()," Period ",Period());alertTag = Time[0];prev=trend;}
if(trend==1 && trend != prev && UpBuffer[shift]== 0 && alertTag!=Time[0]){ Alert("RSIFilter changing trend to Down on ",Symbol()," Period ",Period());alertTag = Time[0];prev=trend;}
if (trend>0)
{
if (RSI0 > 40) UpBuffer[shift]=1.0;
else UpBuffer[shift] = EMPTY_VALUE;
DnBuffer[shift]=0;
}
if (trend<0)
{
if (RSI0 < 60) DnBuffer[shift]=-1.0;
else DnBuffer[shift] = EMPTY_VALUE;
UpBuffer[shift]=0;
}
}
return(0);
}
Comments