REIMT4
Download scriptThis script is a custom technical analysis tool designed for the MetaTrader platform. Its primary purpose is to measure and visualize the "momentum" or direction of price movement by comparing current price levels against historical data from two periods ago.
Core Logic Overview
Instead of simply looking at the immediate previous candle, this indicator looks back specifically at the high and low prices from two candles prior. It calculates the difference between the current price points and those past points to determine if the market is moving in a positive or negative direction.
How the Calculation Works
The script performs the following steps automatically for every candle on your chart:
- Difference Tracking: It identifies the change in "High" prices (comparing today's high to the high from two periods ago) and "Low" prices (comparing today's low to the low from two periods ago).
- Summation: It combines these two differences into a single numerical value. A positive result indicates an upward trend, while a negative result indicates a downward trend.
- Absolute Measurement: Simultaneously, it calculates the total "distance" moved (the absolute value of the changes), regardless of whether that move was up or down.
- Smoothing and Averaging: To prevent the indicator from reacting too wildly to single erratic price spikes, the script looks at a specific window of recent data (defined by the user as the "length"). It calculates an average based on the sum of these differences relative to the total distance moved.
- Normalization: Finally, the result is converted into a percentage-style scale. This allows you to see a smoothed trend line where a higher value represents stronger upward pressure and a lower value represents downward pressure.
Visual Representation
The result is displayed in a separate window below your main price chart as a continuous red line. By observing this line, users can get a clearer picture of the underlying trend strength, filtering out minor market "noise" to show whether the current price action is fundamentally trending higher or lower compared to its recent history.
//+------------------------------------------------------------------+
//| REI.mq4 |
//| Mishutka |
//| www.ourarsenal.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Mishutka"
#property link "www.ourarsenal.narod.ru"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
extern int lenght=8;
extern int NBars=100;
double REABS[21];
double RE[21];
double REI;
double SUM;
double SUMABS;
int Z;
double TDREI;
double WORK[];
int init()
{
REI=0;
SUM=0;
SUMABS=0;
Z=0;
TDREI=0;
int www=14;
IndicatorBuffers(1);
SetIndexBuffer(0,WORK);
//---- drawing settings
SetIndexLabel(0,"REI");
//SetIndexDrawBegin(0,0);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
//---- name for DataWindow and indicator subwindow label
//---- initialization done
return(0);
}
int start()
{
Sleep(100);
int counted_bars=IndicatorCounted();
int limit;
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- rei counted in the 1-st buffer
//Äëÿ ýòîãî ÿ ñðàâíèâàþ öåíîâûå ìàêñèìóì è ìèíèìóì â îïðåäåëåííûé äåíü ñ ìàêñèìóìîì è ìèíèìóìîì çà äâà äíÿ äî ýòîãî.
//Ïîëîæèòåëüíàÿ ðàçíîñòü ôèêñèðóåòñÿ òîãäà, êîãäà ìàêñèìàëüíàÿ öåíà âûøå, ÷åì äâà äíÿ íàçàä. Îòðèöàòåëüíàÿ ðàçíîñòü
// ôèêñèðóåòñÿ òîãäà, êîãäà ýòà ìàêñèìàëüíàÿ öåíà ìåíüøå, ÷åì äâà äíÿ íàçàä. Åñëè ìèíèìàëüíàÿ öåíà âûøå ìèíèìàëüíîé
//öåíû äâà äíÿ òîìó íàçàä, òî ôèêñèðóåòñÿ ïîëîæèòåëüíàÿ ðàçíîñòü. Åñëè îíà ìåíüøå, ÷åì äâà äíÿ íàçàä, òî ôèêñèðóåòñÿ î
//òðèöàòåëüíàÿ ðàçíîñòü. Çàòåì äâà ïîëó÷åííûõ çíà÷åíèÿ ñóììèðóþòñÿ è îïðåäåëÿåòñÿ çíà÷åíèå äëÿ äàííîãî äíÿ.
for (int shift=limit;shift>=0;shift--)
{
RE[0]=(High[shift]-High[shift+2])+(Low[shift]-Low[shift+2]);
REABS[0]=MathAbs(High[shift]-High[shift+2])+MathAbs(Low[shift]-Low[shift+2]);
SUM=0;
SUMABS=0;
for (Z=0;Z<=lenght-1;Z++)
{
SUM=SUM+RE[Z];
SUMABS=SUMABS+REABS[Z];
}
if (SUMABS>0) {REI=SUM/SUMABS;}
TDREI=100*REI;
if (TDREI==0) {TDREI=0.00001;}
WORK[shift]=TDREI;
for (Z=21;Z>=0;Z--)
{
RE[Z]=RE[Z-1];
REABS[Z]=REABS[Z-1];
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments