StepRSI_v2 with Alert

Download script
Author: Copyright � 2005, TrendLaboratory Ltd.
StepRSI_v2 with Alert

Overview of the StepRSI Logic

The StepRSI_v2 script is a technical analysis tool designed to provide visual signals for market trends by modifying the standard Relative Strength Index (RSI). While a standard RSI provides a smooth line showing momentum, this tool adds "dynamic boundaries" that react to price movement, helping traders identify specific zones of strength and potential turning points.

How the Logic Works

The script processes market data through three distinct layers:

1. The Core Foundation (Standard RSI)

At its base, the script calculates a standard RSI value based on a user-defined period. This serves as the primary indicator of whether an asset is currently overbought, oversold, or moving with steady momentum.

2. Dynamic "Step" Boundaries

The unique logic of this script lies in its creation of two additional lines: Fast StepRSI and Slow StepRSI.

  • Instead of moving fluidly like a normal line, these boundaries act more like "floors" and "ceilings."
  • They use a "step" mechanic: they remain flat unless the RSI breaks significantly above or below them. Once a threshold is breached, the boundary "steps" to a new level.
  • Fast StepRSI: Reacts quickly to price changes to capture shorter-term momentum.
  • Slow StepRSI: Provides a broader view of the market trend, moving less frequently and offering a more stable reference point.

3. Signal Generation (Crossover Logic)

The script is designed to identify specific moments where these two dynamic boundaries interact. It looks for "crossovers" between the Fast and Slow step lines:

  • Upward Signals: When the Fast Step boundary crosses below the Slow Step boundary in a specific manner, the script identifies a potential entry point (marked visually on the chart).
  • Downward Signals: When the Fast Step boundary crosses above the Slow Step boundary, it identifies a potential exit or opposing trend move.

Summary for the User

In simple terms, this tool filters out the "noise" of constant small price fluctuations. By creating a staircase-like boundary system (the "Steps"), it helps you visualize when momentum is truly shifting. Rather than reacting to every tiny wiggle in the RSI, the script waits for the moment that fast-moving momentum breaks through or crosses the slower, more established trend boundary, providing a clear visual cue on your chart.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1It plays sound alertsIt sends emails
12 Views
0 Downloads
0 Favorites
StepRSI_v2 with Alert
//+------------------------------------------------------------------+
//|                                                   StepRSI_v2.mq4 |
//|                           Copyright © 2005, TrendLaboratory Ltd. |
//|                                       E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link      "E-mail: igorad2004@list.ru"

#property indicator_separate_window
#property indicator_minimum 20
#property indicator_maximum 80
#property indicator_buffers 5
#property indicator_color1 Orange
#property indicator_color2 SkyBlue
#property indicator_color3 Magenta
#property indicator_color4 Green
#property indicator_color5 Red
//---- input parameters
extern int PeriodRSI=15;
extern int StepSizeFast=5;
extern int StepSizeSlow=10;
extern bool EMAIL_ON = false;
//extern int HighLow=0;
//---- indicator buffers
double Line1Buffer[];
double Line2Buffer[];
double Line3Buffer[];
double ArrowUp[];
double ArrowDn[];

bool   firsttime=true;
bool   aBuyalert=false;
bool   aSellalert=false;
datetime starttime;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_ARROW,EMPTY,2);
   SetIndexStyle(4,DRAW_ARROW,EMPTY,2);
   SetIndexBuffer(0,Line1Buffer);
   SetIndexBuffer(1,Line2Buffer);
   SetIndexBuffer(2,Line3Buffer);
   SetIndexBuffer(3,ArrowUp);
   SetIndexBuffer(4,ArrowDn);
   SetIndexArrow(3,233);
   SetIndexArrow(4,234);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="StepRSI("+PeriodRSI+","+StepSizeFast+","+StepSizeSlow+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"RSI");
   SetIndexLabel(1,"StepRSI fast");
   SetIndexLabel(2,"StepRSI slow");
//----
   SetIndexDrawBegin(0,1);
   SetIndexDrawBegin(1,1);
   SetIndexDrawBegin(2,1);
//----
   if(firsttime)
   {
      starttime=CurTime();
      firsttime=false;
   }
   return(0);
  }

//+------------------------------------------------------------------+
//| StepRSI_v2                                                       |
//+------------------------------------------------------------------+
int start()
  {
   int shift,ftrend,strend;
   double fmin0,fmax0,fmin1,fmax1,smin0,smax0,smin1,smax1,RSI0;

   int isCrossed;

   for(shift=Bars-1;shift>=0;shift--)
   {	
   RSI0=iRSI(NULL,0,PeriodRSI,PRICE_CLOSE,shift);
   
	  fmax0=RSI0+2*StepSizeFast;
	  fmin0=RSI0-2*StepSizeFast;
	  	    
	  if (RSI0>fmax1)  ftrend=1; 
	  if (RSI0<fmin1)  ftrend=-1;

	  if(ftrend>0 && fmin0<fmin1) fmin0=fmin1;
	  if(ftrend<0 && fmax0>fmax1) fmax0=fmax1;
	  
	  smax0=RSI0+2*StepSizeSlow;
	  smin0=RSI0-2*StepSizeSlow;
		
	  if (RSI0>smax1)  strend=1; 
	  if (RSI0<smin1)  strend=-1;

	  if(strend>0 && smin0<smin1) smin0=smin1;
	  if(strend<0 && smax0>smax1) smax0=smax1;
	    
	  
	  Line1Buffer[shift]=RSI0;
	  
	  if (ftrend>0) Line2Buffer[shift]=fmin0+StepSizeFast;
	  if (ftrend<0) Line2Buffer[shift]=fmax0-StepSizeFast;
	  
	  if (strend>0) Line3Buffer[shift]=smin0+StepSizeSlow;
	  if (strend<0) Line3Buffer[shift]=smax0-StepSizeSlow;
	  
	  fmin1=fmin0;
	  fmax1=fmax0;
	  smin1=smin0;
	  smax1=smax0;
   }  //end for(shift=Bars-1;shift>=0;shift--)

   
     /*-------*/
     /* ALERT */
     /*-------*/
   for(shift=Bars-1;shift>=0;shift--)
   {
     isCrossed=Crossed(Line2Buffer[shift],Line3Buffer[shift]);
     
     ArrowUp[shift]=EMPTY_VALUE;
     ArrowDn[shift]=EMPTY_VALUE;
     if(isCrossed==1)
     {
         ArrowUp[shift]=MathMin(MathMin(Line1Buffer[shift],Line2Buffer[shift]),Line3Buffer[shift])-10;
         ArrowDn[shift]=EMPTY_VALUE;
/*
         if(Time[shift]>starttime)
         {

            if(!aBuyalert)
            {
               PlaySound("StepRSI cable.wav");
               if(EMAIL_ON)
                  SendMail("StepRSI with Alert:  BUY signal alert", 
                           ", Ask price: " + DoubleToStr(Ask,4) + ", Bid price: " + DoubleToStr(Bid,4) + ", Date: " + TimeToStr(CurTime())
                           + " Symbol: " + Symbol() + " Period: " + Period());
               aBuyalert=true;
               aSellalert=false;
            }

         }//end if(CurTime()>starttime)
*/
     }
     if(isCrossed==2)
     {
         ArrowDn[shift]=MathMax(MathMax(Line1Buffer[shift],Line2Buffer[shift]),Line3Buffer[shift])+10;
         ArrowUp[shift]=EMPTY_VALUE;
/*
         if(Time[shift]>starttime)
         {
            if(!aSellalert)
            {
               PlaySound("StepRSI cable.wav");
               if(EMAIL_ON)
                  SendMail("StepRSI with Alert:  SELL signal alert", 
                           ", Ask price: " + DoubleToStr(Ask,4) + ", Bid price: " + DoubleToStr(Bid,4) + ", Date: " + TimeToStr(CurTime())
                           + " Symbol: " + Symbol() + " Period: " + Period());
               aSellalert=true;
               aBuyalert=false;
            }
         }//end if(CurTime()>starttime)
*/
     }//end if(isCrossed==2)
      
   }  //end for(shift=Bars-1;shift>=0;shift--)
	return(0);	
 }
//***************************************************************************************// 
 int Crossed(double line1 , double line2)
   {
      static int last_direction = 0;
      static int current_direction = 0;
/*
      static bool first_time = true;
      if(first_time == true)
      {
         first_time = false;
         return (0);
      }
*/        
      if(line1>line2)current_direction    = 1;
      if(line1<line2)current_direction    = 2;

      if(current_direction != last_direction) //changed 
      {
            last_direction = current_direction;
            return (last_direction);
      }
      else  return (0); //not changed
   }


Comments