This tool is designed to help traders visualize and identify the strength of a current market trend by analyzing the relationship between price action and moving averages. Instead of simply showing a price line, it provides a numerical representation of "market activity" within a specific timeframe.
How the Logic Works
The script operates by looking at two different layers of data simultaneously:
1. The Baseline (Moving Average)
First, the tool establishes a baseline by calculating an average price over a set period (defined by the TPeriodMA parameter). This represents the "fair value" or the general direction of the market trend over that duration.
2. The Activity Check (Price Interaction)
Once the baseline is established, the script looks at a smaller, more immediate window of time (defined by the TPeriodL parameter). It examines every individual price candle within this short window to see if the price actually "crossed" or "interacted" with the baseline.
Specifically, it checks if:
- The highest point of a candle reached above the baseline, AND
- The lowest point of that same candle dipped below the baseline.
3. The Final Output Instead of plotting a price, the indicator counts how many times these interactions occurred within that short window.
What This Means for the User
The resulting line on your chart represents a "frequency score."
- Higher Values: Indicate a high level of interaction between the current price and the moving average. This suggests significant volatility or a "tug-of-war" where the price is actively testing the trend line from both sides.
- Lower Values: Suggest that the price is moving more smoothly in one direction without frequently crossing back over the baseline, potentially indicating a more stable or directional phase of the market.
By monitoring this score, traders can get a sense of how much "noise" or "conflict" there is currently happening around the prevailing trend line.
//+------------------------------------------------------------------+
//| SMC Trend.mq4 |
//| Copyright © 2004|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004"
#property link "na"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int TPeriodMA=55;
extern int TPeriodL= 15;
//---- buffers
double TBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="SMC Trend("+TPeriodMA+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,TPeriodMA);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Trend |
//+------------------------------------------------------------------+
int start()
{
int i,x,cnt;
int counted_bars=IndicatorCounted();
double Total;
//----
if(Bars<=TPeriodMA) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=TPeriodMA;i++) TBuffer[Bars-i]=0.0;
//----
i=Bars-TPeriodMA-1;
if(counted_bars>=TPeriodMA) i=Bars-counted_bars-1;
while(i>=0)
{
Total=0;
x=0;
while (x < TPeriodMA)
{Total=Total + Close[i+x];
x=x+1;
}
Total= Total / TPeriodMA; //Calculates MA for TPeriod for Current Bar
x=0;
cnt=0;
while(x < TPeriodL)
{if(High[i+x] > Total && Low[i+x] < Total) cnt= cnt+1;
x=x+1;
}
TBuffer[i] = cnt;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments