i4_DRF_v2_v2
Download scriptThis tool is designed as a visual momentum indicator for trading platforms. It functions by analyzing recent price movements to determine the current strength of a market trend, helping traders distinguish between active trends and periods of consolidation.
Core Logic and Methodology
The script operates by examining a specific "look-back" window of historical price data—defined by a user-adjustable period (set to 21 bars by default). Instead of looking at just the most recent price, it compares the current closing price against a series of previous prices within that window.
How the calculation works:
- Comparative Analysis: The logic loops through the previous 10 price points relative to the current bar.
- Trend Scoring: For every price point in that sequence, the tool performs a simple "higher or lower" check:
- If the current price is higher than a previous price in the sequence, it assigns a positive value (+1).
- If the current price is lower than a previous price, it assigns a negative value (-1).
- Net Momentum Score: The script sums these values together to create a final "net score" for that specific point in time.
Visual Representation
The result of this calculation is plotted as a line on a separate window below your main chart.
- Positive Values: When the line moves above zero, it indicates that the current price is consistently higher than the recent historical average, suggesting upward momentum.
- Negative Values: When the line drops below zero, it indicates that the current price is lower than the recent historical average, suggesting downward momentum.
- Neutrality: When the score sits near zero, it suggests a lack of clear direction, where the price is fluctuating without a dominant trend.
By following this line, traders can visually identify when a trend is gaining strength (the line moving further away from zero) or losing steam (the line moving back toward zero), providing a clearer picture of market sentiment than price action alone.
//+------------------------------------------------------------------+
//| i4_DRF_v2.mq4 |
//| goldenlion@ukr.net |
//| http://GlobeInvestFund.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright (c) 2005, goldenlion@ukr.net"
#property link "http://GlobeInvestFund.com/"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
//---- buffers
double Buffer1[];
int MyPeriod=21;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Buffer1);
//---- name for DataWindow and indicator subwindow label
short_name="i4_DRF_v1.mq4("+MyPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int d, i, ii, counted_bars=IndicatorCounted();
//----
if(Bars<=MyPeriod)return(0);
ii=Bars-MyPeriod*1.1;
if(counted_bars>=MyPeriod)ii=Bars-MyPeriod*1.1;
while( ii>=0)
{
d=0;
for( i=11;i < 21; i++)
if(Close[ii]>=Close[ii+i])d=d+1; else d=d-1;
//if d=0 then d=0.0000001;
Buffer1[ii]=d;
ii--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments