This tool is designed as a technical indicator for the MetaTrader trading platform, specifically created to help traders visualize price momentum and fluctuations over time. Rather than cluttering the main price chart, it generates a separate line graph that tracks specific movements in the market's behavior.
How the Logic Works
The core purpose of this script is to calculate a "Strength Index" based on how current prices react compared to previous candles. Here is a breakdown of the underlying logic:
- Price Comparison: The script looks at the relationship between the current price (High, Low, Open, and Close) and the preceding price candle. It specifically measures the distances between these points to determine which direction the market is pushing most aggressively.
- Range Analysis: It identifies the "Range" of the market by looking at four specific different types of movements:
- The distance between the previous close and the current high.
- The distance between the previous close and the current low.
- The total height of the current candle (High to Low).
- The body size of the previous candle (Open to Close).
- Dynamic Weighting: Not all price movements are treated equally. The logic evaluates which movement is the largest (the "K" factor) and uses it to weight the result. It essentially decides whether the current momentum is driven by an upward push, a downward drop, or a period of consolidation.
- Momentum Calculation: By combining these weighted ranges with the average price movements, the script produces a numerical value representing the strength of the current trend.
The Final Output
The final result is presented as a continuous line on your screen. Instead of showing raw numbers, it uses a cumulative logic: each new calculation is added to the previous one. This creates a smooth, flowing line that shows the accumulation or depletion of market strength.
For a trader, this means you can see the "flow" of the market—observing when momentum is building up, slowing down, or potentially reversing by watching the direction and steepness of the resulting line.
//+------------------------------------------------------------------+
//| SI.mq4 |
//| Raff |
//| raff1410@o2.pl |
//+------------------------------------------------------------------+
#property copyright "Raff"
#property link "just_raff1410@yahoo.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern double T = 1;
extern int CountBars = 10000;
//---- buffers
double ASI[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(1);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ASI);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, counted_bars=IndicatorCounted();
//----
double pHigh, pLow, pOpen, pClose;
double pHigh_1, pLow_1, pOpen_1, pClose_1;
double K, R, R_1, R_2, R_3, R_4, X, SI ;
if (CountBars>Bars) CountBars=Bars-10;
i=CountBars-10;
ASI[i+1]=0;
while(i>=0)
{
pHigh = High[i];
pLow = Low[i];
pOpen = Open[i];
pClose = Close[i];
pHigh_1 = High[i+1];
pLow_1 = Low[i+1];
pOpen_1 = Open[i+1];
pClose_1 = Close[i+1];
R_1 = MathAbs(pHigh-pClose_1);
R_2 = MathAbs(pLow-pClose_1);
R_3 = MathAbs(pHigh-pLow);
R_4 = MathAbs(pClose_1-pOpen_1);
K = MathMax(R_1,R_2);
if (R_1>=MathMax(R_2,R_3))
{
R = R_1 - R_2/2 + R_4/4;
}
else
if (R_2>=MathMax(R_1,R_3))
{
R = R_2 - R_1/2 + R_4/4;
}
else
{
R = R_3 + R_4/4;
}
if (R==0) SI=0;
else
{
X = (pClose_1-pClose)+(pClose_1-pOpen_1)/2+(pClose-pOpen)/4;
SI = 50 * (X/R) * (K/T);
}
ASI[i] = ASI[i+1]-SI;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments