RWI
Download scriptThe Random Walk Index (RWI) is a technical analysis tool designed to help traders distinguish between actual market trends and "noise"—those random, directionless movements that often occur in volatile trading environments. By analyzing price action over a specific timeframe, the indicator helps identify whether a financial instrument is moving with purposeful momentum or simply drifting aimlessly within a range.
How the Logic Works
To provide a clear picture of market movement, the script follows a structured three-step logic:
1. Defining the Trading Range The indicator begins by establishing the "trading range" of the asset. It looks at historical price data to understand the typical volatility and boundaries within which the price usually fluctuates.
2. Calculating Movement Strength The script then performs a series of mathematical calculations over a set period (the "RWI Period"). It measures the distance between high and low prices relative to the market's average volatility (Average True Range).
By doing this, it essentially asks: "How significant is the move we are seeing right now compared to the usual 'choppiness' of the market?"
3. Determining Trend vs. Randomness The core of the logic lies in comparing these movements against a "Random Walk." A random walk represents a scenario where price changes have no predictable direction.
- Upward Trend: If the calculated movement strength (RWI High) is consistently greater than 1, it suggests that the upward pressure is stronger than what would be expected from pure chance, indicating a developing bullish trend.
- Downward Trend: If the downward movement strength (RWI Low) exceeds 1, it suggests that the price is dropping with more intent than random fluctuation, pointing toward a bearish trend.
Visual Interpretation
The indicator provides two separate visual lines:
- RWI High (Green): Tracks the strength of potential upward trends.
- RWI Low (Red): Tracks the strength of potential downward trends.
By observing these lines, a user can quickly see when the market is breaking out into a sustained trend versus when it is simply "walking" randomly without clear direction.
//+------------------------------------------------------------------+
//| RWI.mq4 |
//| Èíäåêñ Ñëó÷àéíîé Ïðîãóëêè (Random Walk Index) |
//| From MetaStock Indicator: Random Walk Index by E. Michael Poulos |
//| Ramdass |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// (Random Walk Index) |
// Èíäèêàòîð ñëó÷àéíîé ïðîãóëêè èñïîëüçóåòñÿ, ÷òîáû |
// îïðåäåëèòü, ðàçâèâàåò ëè ðûíî÷íûé èíñòðóìåíò òðåíä èëè |
// ñîâåðøàåò ñëó÷àéíûå äâèæåíèÿ â òîðãîâîì äèàïàçîíå. |
// Äàííûé èíäèêàòîð ïûòàåòñÿ ñäåëàòü ýòî, îïðåäåëÿÿ ñíà÷àëà |
// òîðãîâûé äèàïàçîí ðûíî÷íîãî èíñòðóìåíòà. Ñëåäóþùèé |
// øàã ñîñòîèò â âû÷èñëåíèè ñåðèè èíäåêñîâ RWI äëÿ |
// ìàêñèìóìà ðàññìàòðèâàåìîãî ïåðèîäà. Íàèáîëüøåå äâèæåíèå |
// èíäåêñà îòíîñèòåëüíî Ñëó÷àéíîé ïðîãóëêè èñïîëüçóåòñÿ |
// â êà÷åñòâå òåêóùåãî èíäåêñà. Ðûíîê ðàçâèâàåò âîñõîäÿùèé |
// òðåíä, åñëè RWI ìàêñèìóìîâ áîëüøå 1, â òî âðåìÿ |
// êàê íèñõîäÿùèé òðåíä óêàçûâàåòñÿ, åñëè RWI ìèíèìóìîâ áîëüøå 1. |
// |
//+------------------------------------------------------------------+
#property copyright "Ramdass"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_level1 1
//---- buffers
double RWI_High[];
double RWI_Low[];
//----
int RWI_Period = 8;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, RWI_High);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, RWI_Low);
//----
IndicatorShortName("RWI");
SetIndexLabel(0, "RWI_High");
SetIndexLabel(1, "RWI_Low");
//----
SetIndexDrawBegin(0, RWI_Period + 1);
SetIndexDrawBegin(1, RWI_Period + 1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| RWI |
//+------------------------------------------------------------------+
int start()
{
int i,j;
double max_1,max_2,max_High,max_Low,atr,sqrt;
//----
if(Bars <= RWI_Period)
return(0);
int limit = Bars - IndicatorCounted();
//----
for(i = 0; i < limit; i++)
{
max_High=0.0; max_Low=0.0;
for(j = 1; j <= RWI_Period; j++)
{
sqrt = MathSqrt(j + 1);
atr = iATR(NULL, 0, j + 1, i + 1);
if(atr != 0.0)
{
max_1 = (High[i] - Low[i+j]) / (atr * sqrt); // RWI_High Index
max_2 = (High[i+j] - Low[i]) / (atr * sqrt); // RWI_Low Index
if(max_1 > max_High)
max_High = max_1; // Maximum_RWI_High Index
if(max_2 > max_Low)
max_Low = max_2; // Maximum_RWI_Low Index
}
}
RWI_High[i] = max_High;
RWI_Low[i] = max_Low;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments