The SilverTrend indicator is designed to provide traders with a visual representation of market momentum and trend direction by analyzing price extremes over a specific period. Rather than following every minor price fluctuation, the logic focuses on identifying significant structural shifts in the market.
How the Logic Works
1. Historical Data Analysis The script looks back at a predetermined number of bars (the "lookback period") to identify the highest highs and lowest lows reached during that time. By focusing on these extremes, the tool attempts to filter out "market noise"—the small, insignificant movements that can often mislead short-term traders.
2. Dynamic Threshold Calculation
Once the highest high and lowest low are identified, the script calculates the total price range (the distance between those two points). It then applies a specific percentage-based reduction (controlled by the Kmax variable) to the high point. This creates a "threshold" or a "ceiling."
Essentially, the logic asks: "Based on the recent range of movement, where does the price need to be to confirm a trend?"
3. Trend Detection and Visualization The indicator compares the current price action against these calculated thresholds. It uses two distinct visual components to communicate the market state:
- Trend Direction: The script constantly monitors whether the current price is pushing above or below the calculated structural levels.
- Visual Signaling: Based on this comparison, the tool produces a histogram in a separate window. When the trend shifts significantly enough to cross the internal threshold, the indicator changes color.
- One color typically represents bullish momentum (upward pressure).
- The other color represents bearish momentum (downward pressure).
Summary for the Trader
Instead of telling you exactly when to buy or sell at a specific second, this script acts as a trend filter. It visualizes the "path of least resistance" by calculating where the price should realistically be based on recent history. When the histogram changes color, it signals that the market has moved beyond its previous range boundaries, suggesting a potential shift in the prevailing trend.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| SilverTrend .mq4 |
//| SilverTrend rewritten by CrazyChart |
//| http://viac.ru/ |
//| modified by Kalenzo bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "SilverTrend rewritten by CrazyChart"
#property link "http://viac.ru/ "
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue //Red //Aqua
#property indicator_color2 Red
extern int SSP=7;
extern double Kmax=50.6; //24 21.6 21.6
extern int CountBars=300;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtHBuffer1[];
double ExtHBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_HISTOGRAM,0,2); //Red
SetIndexBuffer(0,ExtHBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,0,2); //Aqua
SetIndexBuffer(1,ExtHBuffer2);
SetIndexBuffer(2,ExtMapBuffer1);
SetIndexBuffer(3,ExtMapBuffer2);
IndicatorShortName("FxTrend v2("+SSP+")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+SSP);
SetIndexDrawBegin(1,Bars-CountBars+SSP);
int i, counted_bars=IndicatorCounted();
double SsMax, SsMin, smin, smax;
if(Bars<=SSP+1) return(0);
if(counted_bars<SSP+1)
{
for(i=1;i<=SSP;i++) ExtMapBuffer1[CountBars-i]=0.0;
for(i=1;i<=SSP;i++) ExtMapBuffer2[CountBars-i]=0.0;
}
for(i=CountBars-SSP;i>=0;i--) {
SsMax = High[Highest(NULL,0,MODE_HIGH,SSP,i-SSP+1)];
SsMin = Low[Lowest(NULL,0,MODE_LOW,SSP,i-SSP+1)];
smax = SsMax-(SsMax-SsMin)*Kmax/100;
ExtMapBuffer1[i-SSP+6]=smax;
ExtMapBuffer2[i-SSP-1]=smax;
}
for(int b=CountBars-SSP;b>=0;b--)
{
if(ExtMapBuffer1[b]>ExtMapBuffer2[b])
{
ExtHBuffer1[b]=1;
ExtHBuffer2[b]=0;
}
else
{
ExtHBuffer1[b]=0;
ExtHBuffer2[b]=1;
}
}
return(0);
}
Comments