Trend SMC v2_v1
Download scriptThis script is designed as a visual analytical tool for the MetaTrader platform, specifically crafted to help traders identify and interpret market trends by analyzing price action relative to moving averages.
Core Logic Overview
The primary objective of this indicator is to measure the "strength" or "density" of a trend over a specific period. Instead of simply showing a line that follows the price, it calculates how frequently the price interacts with a calculated average, providing a clearer picture of market momentum and volatility.
How It Works
To determine the trend dynamics, the script performs three main operations:
1. Establishing the Baseline (Moving Average) The tool first looks back at a set number of previous price bars (defined by the user) to calculate a Simple Moving Average. This serves as the "center" or "equilibrium" point for the market during that specific timeframe.
2. Measuring Price Interaction Once the baseline is established, the script examines a smaller window of recent price movement. It counts how many times the high and low prices have crossed through that baseline.
- A high count suggests that the price is frequently oscillating around the average, which can indicate specific types of market behavior or consolidation.
- The script then plots these counts as a visual line on your chart.
3. Smoothing the Data To make the information easier for a human to read and less "choppy," the script applies an averaging technique to the resulting counts. By blending the current data with the preceding values, it creates a smoother visual trendline. This helps traders filter out minor market noise and focus on the broader directional flow.
Visual Representation
The indicator operates in a separate window below your main price chart. It provides three distinct visual elements:
- Trend Density: A primary line representing the frequency of price interactions.
- Reference Level: A horizontal marker that serves as a midpoint or benchmark for the trend data.
- Smoothed Average: A secondary line that helps identify the overall direction of the trend, making it easier to spot whether momentum is increasing or decreasing at a glance.
Summary for the Trader
Essentially, this tool translates raw price movement into a "trend intensity" score. By observing how these lines move, you can better visualize whether the market is in a stable trend, experiencing high-frequency interaction with its average, or shifting in direction, allowing for more informed decision-making.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| SMC Trend.mq4 |
//| Copyright © 2004|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004"
#property link "na"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DarkOliveGreen
#property indicator_color2 FireBrick
#property indicator_color3 Red
//---- input parameters
extern int TPeriodMA=24;
extern int TPeriodL= 8;
//---- buffers
double TBuffer[];
double HorizBuffer[];
double AvgBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TBuffer);
SetIndexStyle(1,DRAW_LINE,1);
SetIndexBuffer(1,HorizBuffer);
SetIndexStyle(2,DRAW_LINE,0,2,Red);
SetIndexBuffer(2,AvgBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="SMC Trend("+TPeriodMA+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,TPeriodMA);
SetIndexDrawBegin(1,TPeriodMA);
SetIndexDrawBegin(2,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 Simple MA for TPeriod for Current Bar
x=0;
cnt=0;
while(x < TPeriodL+1)
{if(High[i+x] > Total && Low[i+x] < Total) cnt= cnt+1;
x=x+1;
}
TBuffer[i] = cnt;
HorizBuffer[i] = TPeriodL/2;
AvgBuffer[i] = (TBuffer[i] + TBuffer[i+1])/2;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments