TrendManager_recentweight
Download scriptThe Trend Manager is a visual trading tool designed to help market participants identify and track price momentum by smoothing out "noise" in the marketplace. Rather than showing every jagged movement of the price, this script calculates specific average values to provide a clearer picture of the underlying trend.
How the Logic Works
The tool operates by looking at a specific window of recent price activity (determined by the user-defined period) and performing three main steps to generate its visual data:
1. Identifying Key Boundaries For every point on the chart, the script scans backward through the recent history to find two critical pieces of information:
- The highest price reached during that timeframe.
- The lowest price reached during that timeframe.
2. Calculating the Weighted Center Once it knows the high and low points, the tool focuses on the area between them. It calculates the midpoint of every individual candle (the average between that specific candle's high and low) and finds the overall average of those midpoints. This creates a "weighted" value that represents where the price has spent the majority of its time during that period.
3. Generating the Visual Signals The script then combines these elements to create two distinct visual components:
- Primary Trend Line: This is calculated by taking the average of the period's high, the period's low, and the weighted center value. By blending these three factors, the tool provides a smoothed representation of where the "true" price level sits.
- Shifted Support/Resistance: The tool also projects a secondary value that is slightly offset (shifted) forward in time. This allows traders to see a comparison between the current trend and the immediate preceding movement.
Visual Representation
On your chart, these calculations are displayed as two distinct histograms. By observing how these two lines move in relation to each other and the current price, users can better visualize whether the market is gaining strength, losing momentum, or consolidating in a specific range.
// Trend Manager.mq4
// Based on indicator sold at traderstradingsystem.com
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
extern int TM_Period = 7;
extern int TM_Shift = 2;
double SpanA_Buffer[];
double SpanB_Buffer[];
int a_begin;
int init()
{
a_begin=TM_Shift;
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexBuffer(0,SpanB_Buffer);
SetIndexDrawBegin(0,TM_Period+a_begin-1);
SetIndexLabel(0,"TM_Period+");
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexBuffer(1,SpanA_Buffer);
SetIndexDrawBegin(1,TM_Period+a_begin-1);
SetIndexLabel(1,"TM_Period");
return(0);
}
int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double high,low,price;
int rhs,rls, j, rhls;
double weight;
if(Bars<=TM_Period) return(0);
if(counted_bars<1)
{
for(i=1;i<=TM_Period;i++)
{
SpanA_Buffer[Bars-i]=0;
SpanB_Buffer[Bars-i]=0;
}
}
i=Bars-TM_Period;
if(counted_bars>TM_Period) i=Bars-counted_bars-1;
while(i>=0)
{
high=High[i]; low=Low[i]; k=i-1+TM_Period;
while(k>=i)
{
price=High[k];
if(high<price)
{
high=price;
rhs=k;
}
price=Low[k];
if(low>price)
{
low=price;
rls=k;
}
k--;
}
rhls=MathMin(rls,rhs);
int cnt=0;
double lw=0;
double hg=0;
double mid=0;
double midsum=0;
for(j=rhls;j>=i;j--)
{
hg=High[j];
lw=Low[j];
mid=(hg+lw)/2;
midsum=midsum+mid;
cnt++;
}
weight=NormalizeDouble(midsum/cnt,Digits);
if (i==0)
{
//Alert(weight);
//Alert(rls);
}
SpanA_Buffer[i] = NormalizeDouble((high+low+weight)/3.0, Digits);
SpanB_Buffer[i] = SpanA_Buffer[i+TM_Shift];
i--;
}
return(0);
}
Comments