RSIOMA
Download scriptThis tool is a specialized technical analysis indicator designed to help traders identify momentum, potential trend reversals, and overbought or oversold conditions in the financial markets. It enhances the standard Relative Strength Index (RSI) by adding visual cues for specific price actions.
Core Logic and Functionality
Momentum Calculation The script works by analyzing price movements over a set period (defaulting to 14 units). Instead of looking at raw price changes, it utilizes a "smoothed" approach. It calculates the difference between consecutive averages to determine if the market is moving upward or downward. By averaging these gains and losses, it produces a momentum score represented on a scale of 0 to 100.
Trend Identification The indicator establishes two primary "Main Trend" thresholds set at the midpoint (50).
- When the momentum score stays above this level, it suggests a bullish bias.
- When the momentum score falls below this level, it suggests a bearish bias.
Overbought and Oversold Signals The logic includes specific triggers to alert traders when the market might be "overextended":
- Oversold Conditions: When the momentum drops into the lower extreme (below 20) and begins to tick upward, the script identifies a potential buying opportunity or a "support" area.
- Overbought Conditions: When the momentum climbs into the upper extreme (above 80) and begins to tick downward, the script identifies a potential selling opportunity or a "ceiling" area.
Visual Representation
To make this information easy to read at a glance, the script translates these calculations into several visual elements on your chart:
- The Main Line: A solid line that tracks the current momentum score.
- Histogram Bars: These serve as visual highlights for specific triggers. They appear automatically when certain conditions are met:
- Buy Signals: Shown when momentum is strongly in the upper trend zone.
- Sell Signals: Shown when momentum is strongly in the lower trend zone.
- Support/Supply Markers: These highlight the exact moments when the price enters overextended territory and shows signs of reversing direction.
Summary for the User
Essentially, this script automates the process of "reading" market exhaustion. Rather than just telling you if the price is high or low, it combines momentum trends with specific reversal triggers to help you see where the trend is strongest and where it might be reaching a breaking point.
//+------------------------------------------------------------------+
//| RSI.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 100
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Magenta
#property indicator_color5 DodgerBlue
//---- input parameters
extern int RSIOMA = 14;
extern int BuyTrigger = 80;
extern int SellTrigger = 20;
extern int MainTrendLong = 50;
extern int MainTrendShort = 50;
//---- buffers
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
double bdn[],bup[];
double sdn[],sup[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 2 additional buffers are used for counting.
IndicatorBuffers(7);
SetIndexBuffer(0,RSIBuffer);
SetIndexBuffer(2,bup);
SetIndexBuffer(1,bdn);
SetIndexBuffer(3,sdn);
SetIndexBuffer(4,sup);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexBuffer(5,PosBuffer);
SetIndexBuffer(6,NegBuffer);
short_name="RSIOMA("+RSIOMA+")";
IndicatorShortName(short_name);
SetIndexDrawBegin(0,RSIOMA);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
SetLevelValue(0, BuyTrigger);
SetLevelValue(1, SellTrigger);
SetLevelValue(2, MainTrendLong);
SetLevelValue(3, MainTrendShort);
SetLevelStyle(STYLE_DOT, 1, Yellow);
int i,counted_bars=IndicatorCounted();
double rel,negative,positive;
//----
if(Bars<=RSIOMA) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=RSIOMA;i++) RSIBuffer[Bars-i]=0.0;
//----
i=Bars-RSIOMA-1;
if(counted_bars>=RSIOMA) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIOMA-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
double cma = iMA(Symbol(),0,RSIOMA,0,MODE_EMA,PRICE_CLOSE,k);
double pma = iMA(Symbol(),0,RSIOMA,0,MODE_EMA,PRICE_CLOSE,k+1);
rel=cma-pma;
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIOMA;
negative=sumn/RSIOMA;
}
else
{
//---- smoothed moving average
double ccma = iMA(Symbol(),0,RSIOMA,0,MODE_EMA,PRICE_CLOSE,i);
double ppma = iMA(Symbol(),0,RSIOMA,0,MODE_EMA,PRICE_CLOSE,i+1);
rel=ccma-ppma;
if(rel>0) sump=rel;
else sumn=-rel;
positive=(PosBuffer[i+1]*(RSIOMA-1)+sump)/RSIOMA;
negative=(NegBuffer[i+1]*(RSIOMA-1)+sumn)/RSIOMA;
}
PosBuffer[i]=positive;
NegBuffer[i]=negative;
if(negative==0.0) RSIBuffer[i]=0.0;
else
{
RSIBuffer[i]=100.0-100.0/(1+positive/negative);
bdn[i] = 0;
bup[i] = 0;
sdn[i] = 0;
sup[i] = 0;
if(RSIBuffer[i]>MainTrendLong)
bup[i] = -10;
if(RSIBuffer[i]<MainTrendShort)
bdn[i] = -10;
if(RSIBuffer[i]<20 && RSIBuffer[i]>RSIBuffer[i+1])
sup[i] = -10;
if(RSIBuffer[i]>80 && RSIBuffer[i]<RSIBuffer[i+1])
sdn[i] = -10;
}
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments