RSI_Crossing_50_plus_ATR_ver1.2_FXA0
Download scriptThis technical indicator is designed to identify specific trend reversals and momentum shifts by analyzing the relationship between price volatility and relative strength. It provides visual cues on a trading chart to help users identify potential entry points, expansion signals, and exit zones.
Core Methodology
The logic operates primarily on two financial metrics:
- Relative Strength Index (RSI): Used to determine the speed and change of price movements to identify overbought or oversold conditions, as well as momentum shifts across specific thresholds (30, 40, 50, 60, and 70).
- Average True Range (ATR): Used to measure current market volatility. The script utilizes this to calculate dynamic price levels for potential targets and risk boundaries.
Trading Logic & Visual Signals
The indicator monitors the "crossings" of these metrics to generate three distinct types of visual markers:
1. Primary Trend Entries
The script looks for significant shifts in momentum when the RSI crosses the 50-level midpoint:
- Bullish Entry: When the RSI moves from below 50 to above 50, a blue arrow appears. Simultaneously, the script clears previous markers and draws horizontal lines representing a potential "Long Entry" and a "Long Stop" based on a percentage of the daily volatility (ATR).
- Bearish Entry: When the RSI moves from above 50 to below 50, a red arrow appears. It also clears previous markers and draws horizontal lines for a "Short Entry" and "Short Stop."
2. Position Expansion Signals
In addition to the primary entries, the script identifies secondary momentum signals to help traders gauge trend strength:
- Bullish Additions: If the price is already in a bullish state (RSI above 50), it monitors for a cross of the 60-level to signal further upward momentum.
- Bearish Additions: If the price is already in a bearish state (RSI below 50), it monitors for a cross of the 40-level to signal further downward momentum.
3. Exit Signals
To help manage risk and realize profits, the script identifies "exhaustion" points:
- Bullish Exit: When the RSI drops from an overbought state (above 70) back below 70, a green checkmark/signal appears to suggest taking profits or closing a long position.
- Bearish Exit: When the RSI rises from an oversold state (below 30) back above 30, a signal appears to suggest taking profits or closing a short position.
User Summary
For a trader, this tool acts as a visual roadmap. It highlights exactly where a trend might be starting (the arrows), where it might be gaining extra strength (expansion markers), and where the momentum is becoming exhausted (exit signals). By incorporating ATR-based lines, it also provides a structural reference for where to place stop-loss orders relative to current market volatility.
//+------------------------------------------------------------------+
//| FXA0 - RSI Crossing 50.mq4 |
//| Copyright © 2007, Adam J. Richter M.S. |
//|RSI_Crossing_50_plus_ATR_ver1.2_FXA0 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Adam J. Richter M.S."
//Version 1.2 fixed 8 digit double to 4 digits and set to remove all objects in deinitialize
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
double dUpRsiBuffer[];
double dDownRsiBuffer[];
double dSellBuffer[];
extern double ATR_Percent = 0.15; //This value sets the ATR Used, The ATR is 15%
extern double RSI_Period = 21; //This value sets the RSI Period Used, The default is 21
extern double ATR_Period = 21; //This value sets the ATR Period Used, The default is 21
int RowNum = 0;
int LastTrend = -1;
int UP_IND = 1;
int DOWN_IND = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,dUpRsiBuffer);
SetIndexBuffer(1,dDownRsiBuffer);
SetIndexBuffer(2,dSellBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233); //241 option for different arrow head
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234); //242 option for different arrow head
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,252); //251 x sign or 252 green check
//----
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(2,0.0);
//---- name for DataWindow
SetIndexLabel(0,"Rsi Buy");
SetIndexLabel(1,"Rsi Sell");
SetIndexLabel(2,"Exit");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll();
//----
return(0);
}
void printmyline(double vala, int topbottom) //print target line
{
vala = NormalizeDouble(vala,4);
if(topbottom==1)//target
{
ObjectCreate("theentry " + vala,OBJ_HLINE,0,0,vala);
ObjectSet("theentry " + vala,OBJPROP_COLOR, Blue);
ObjectSetText("theentry " + vala,"Long Entry",13,"Arial",Black);
}
if(topbottom==2)//stop
{
ObjectCreate("thestop " + vala,OBJ_HLINE,0,0,vala);
ObjectSet("thestop " + vala,OBJPROP_COLOR, Blue);
ObjectSetText("thestop " + vala,"Long Stop",13,"Arial",Black);
}
}
void printmylinedown(double vala, int topbottom) //print target line
{
vala = NormalizeDouble(vala,4);
if(topbottom==1)//target
{
ObjectCreate("theentry " + vala,OBJ_HLINE,0,0,vala);
ObjectSet("theentry " + vala,OBJPROP_COLOR, Red);
ObjectSetText("theentry " + vala,"Short Entry",13,"Arial",Black);
}
if(topbottom==2)//stop
{
ObjectCreate("thestop " + vala,OBJ_HLINE,0,0,vala);
ObjectSet("thestop " + vala,OBJPROP_COLOR, Red);
ObjectSetText("thestop " + vala,"Short Stop",13,"Arial",Black);
}
}
void deletealllines()
{
ObjectsDeleteAll();
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int nBars,nCountedBars;
nCountedBars=IndicatorCounted(); //ncountedbars 655
//---- check for possible errors
if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted
if(nCountedBars<=2)
nBars=Bars-nCountedBars-3;
if(nCountedBars>2)
{
nCountedBars--;
nBars=Bars-nCountedBars-1; //number of bars in current chart-655-1
}
double lastRSI60arrow = NULL; //if going long
double lastRSI40arrow = NULL; //if going short
int lastCloseLong=0;
int lastCloseShort=0;
for (int ii=Bars; ii>0; ii--)
{
dUpRsiBuffer[ii]=0;
dDownRsiBuffer[ii]=0;
double myRSInow = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,ii);
double myRSI2 = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,ii+1); //RSI One bar ago
double myATR1 = iATR(NULL,PERIOD_D1,ATR_Period,ii);
if (myRSInow>=50) //is going long
{
if(myRSInow>50 && myRSI2<50) //did it cross from below 50
{
deletealllines();
dUpRsiBuffer[ii] = Low[ii] - 2 * MarketInfo(Symbol(),MODE_POINT);
printmyline((iHigh(NULL,0,ii+1)+(myATR1*ATR_Percent)),1);
printmyline((iHigh(NULL,0,ii+1)+(myATR1*ATR_Percent))-(0.30*myATR1),2);
lastRSI60arrow=0;
lastCloseLong=0;
}
if(myRSInow>=60 && myRSI2<60) //add to position at cross of 60, sometimes this can occur twice
{
if(lastRSI60arrow>=60) //don't draw another arrow
{
}
if(lastRSI60arrow<=60) //draw another arrow for adding to position
{
dUpRsiBuffer[ii] = Low[ii] - 2 * MarketInfo(Symbol(),MODE_POINT);
lastRSI60arrow = myRSInow;
}
}
if(myRSInow<70 && myRSI2>=70) //sell first lot
{
if(lastCloseLong==0)
{
dSellBuffer[ii] = High[ii] + 2 * MarketInfo(Symbol(),MODE_POINT);
lastCloseLong=1;
}
}
}
if(myRSInow<50) //is going short
{
if(myRSInow<50 && myRSI2>50) //did it cross from above 50
{
deletealllines();
dDownRsiBuffer[ii] = High[ii] + 2 * MarketInfo(Symbol(),MODE_POINT);
printmylinedown((iLow(NULL,0,ii+1)-(myATR1*ATR_Percent)),1);
printmylinedown((iLow(NULL,0,ii+1)-(myATR1*ATR_Percent))+(0.30*myATR1),2);
lastCloseShort=0;
lastRSI40arrow=myRSInow; //set out of area
}
if(myRSInow<40 && myRSI2>40)
{
if(lastRSI40arrow<=40) //don't draw another arrow
{
}
if(lastRSI40arrow>=40) //draw another arrow to add to position
{
dDownRsiBuffer[ii] = High[ii] + 2 * MarketInfo(Symbol(),MODE_POINT);
lastRSI40arrow=myRSInow;
}
}
if(myRSInow>30 && myRSI2<30)
{
if(lastCloseShort==0)
{
dSellBuffer[ii] = Low[ii] - 4 * MarketInfo(Symbol(),MODE_POINT);
lastCloseShort=1;
}
}
}
}
}
Comments