REI
Download scriptThis tool is a custom technical analysis indicator designed for the MetaTrader 4 platform. It functions by creating a visual representation of market momentum and price movement volatility within a specific timeframe, allowing traders to see smoothed trends in a separate window rather than directly on the price chart.
Core Logic Overview
The script operates by analyzing historical price data—specifically looking at the highs and lows of previous candles—to calculate a unique ratio. It evaluates how "active" the price movement is relative to its immediate surroundings.
Key Components of the Calculation:
- Volatility Tracking: The logic examines the difference between current price peaks and troughs compared to those from several bars back. This helps identify whether the market is expanding or contracting in its range.
- Condition Filtering: The script includes specific logical checks that look at previous closing prices relative to high and low points. These filters act as a "gatekeeper," determining which price movements are significant enough to be factored into the final calculation. Essentially, it helps ignore minor market noise and focuses on meaningful shifts in price structure.
- Weighted Averaging: The indicator uses a user-defined period (the "REI Period") to look back at a specific number of candles. Instead of just looking at the very last price change, it sums up the movement over this entire period to provide a smoother, more reliable trend line.
- The Final Ratio: The final value displayed on your screen is a percentage. It is calculated by taking the filtered price movements and dividing them by the total absolute volatility of the chosen period.
How it appears on your chart:
Because the indicator calculates a ratio, the resulting line fluctuates around a zero-point. It provides a visual "pulse" of the market:
- Trend Identification: By observing the direction of the line, you can see if the current momentum is accelerating or slowing down.
- Smoothing: Because it averages data over your chosen period, it reduces the "jitter" often found in raw price movements, making it easier to identify the underlying trend of the asset.
//+------------------------------------------------------------------+
//| REI.mq4 |
//| Copyright © 2009, LeMan. |
//| b-market@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, LeMan"
#property link "b-market@mail.ru"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_level1 60
#property indicator_level2 -60
//---- Âõîäíûå ïàðàìåòðû
extern int REIPeriod = 5;
//---- Áóôåðû
double REIBuffer[];
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè |
//+------------------------------------------------------------------+
int init() {
string short_name;
IndicatorBuffers(1);
IndicatorShortName("REI ("+REIPeriod+")");
//---- Ëèíèè èíäèêàòîðà
SetIndexBuffer(0, REIBuffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexDrawBegin(0,REIPeriod+9);
//----
return(0);
}
double SV(int i = 0) {
double var1 = High[i] - High[i+2];
double var2 = Low[i] - Low[i+2];
if (High[i+2] < Close[i+7] && High[i+2] < Close[i+8] && High[i] < High[i+5] && High[i] < High[i+6]) {
int num_zero = 0;
} else {
num_zero = 1;
}
if (Low[i+2] > Close[i+7] && Low[i+2] > Close[i+8] && Low[i] > Low[i+5] && Low[i] > Low[i+6]) {
int num_zero2 = 0;
} else {
num_zero2 = 1;
}
return((num_zero*num_zero2*var1)+(num_zero*num_zero2*var2));
}
double ADV(int i = 0) {
double var3 = MathAbs(High[i] - High[i+2]);
double var4 = MathAbs(Low[i] - Low[i+2]);
return(var3+var4);
}
//+------------------------------------------------------------------+
//| Ìåòîä Êàèðè |
//+------------------------------------------------------------------+
int start() {
int i, k, counted_bars = IndicatorCounted();
//----
if (Bars <= 8+REIPeriod) return(0);
if (counted_bars > 0) counted_bars--;
int limit = Bars-counted_bars;
for(i = 0; i <= limit; i++) {
double sv = 0.0;
double adv = 0.0;
for(k = 0; k < REIPeriod; k++) {
adv += ADV(i+k);
}
for(k = 0; k < REIPeriod; k++) {
sv += SV(i+k);
}
REIBuffer[i] = (sv/adv)*100;
}
return(0);
}
//+------------------------------------------------------------------+
Comments