ForexOFFTrendCustom
Download scriptThe SilverTrend indicator is designed to provide visual guidance on market trends by identifying potential price boundaries and movement directions. It functions by analyzing historical price action over a specific timeframe to determine key levels of resistance and support.
Core Logic and Functionality
Price Range Analysis The script continuously scans a predetermined number of recent bars (the "Lookback Period") to identify the highest highs and lowest lows reached during that time. By establishing these extremes, the tool creates a dynamic boundary of the current market's volatility.
Dynamic Level Calculation Instead of using fixed price points, the logic calculates two specific levels based on the percentage of the distance between the recent high and low:
- Upper Boundary: Derived from the maximum reach of the current price range.
- Lower Boundary: Calculated relative to the minimum reach.
The tool uses customizable percentage parameters (minimum and maximum thresholds) to determine where these boundaries sit. This allows the indicator to project "zones" rather than single lines, helping traders see the outer limits of current market momentum.
Trend Identification The script tracks these calculated values over time and compares them to identify shifts in momentum:
- Buy Signals: When the primary data value exceeds its secondary historical counterpart, the logic suggests upward bullish sentiment.
- Sell Signals: Conversely, when the primary data value falls below the secondary counterpart, the logic indicates downward bearish sentiment.
Visual Representation
The indicator renders these calculations on your chart as two distinct lines:
- Black Line: Represents one set of trend data points.
- SaddleBrown Line: Represents the secondary set of data points used for comparison.
By observing the interaction between these two lines, users can visually identify "crossovers" or gaps that signal a change in market direction. Additionally, the script provides real-time text feedback on the chart interface, explicitly labeling whether the current technical logic favors a "Buy" or a "Sell" position based on the most recent data calculation.
//+------------------------------------------------------------------+
//| SilverTrend .mq4 |
//| SilverTrend rewritten by CrazyChart |
//| http://viac.ru/ |
//+------------------------------------------------------------------+
#property copyright "SilverTrend rewritten by CrazyChart"
#property link "http://viac.ru/ "
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 SaddleBrown
//---- input parameters
extern int CountBars=300;
extern int SSP=7;
extern double Kmin=1.6;
extern double Kmax=50.6; //24 21.6 21.6
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE,0,2,Black);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE,0,2,SaddleBrown);
SetIndexBuffer(1,ExtMapBuffer2);
//----
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, i2,loopbegin,counted_bars=IndicatorCounted();
double SsMax, SsMin, K, val1, val2, smin, smax, price;
if(Bars<=SSP+1) return(0);
//---- initial zero
//K=33-RISK;
/*
if (firstTime==true) {
loopbegin = CountBars;
if (loopbegin>(Bars-2*SSP+1)) loopbegin=Bars-2*SSP+1;
firstTime=False;
}; ðóäèìåíò ñòàðîé ïðîãðàììû
*/
if(Bars<=SSP+1) return(0);
//---- initial zero
//+++++++
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;
}
//+++++++-SSP
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)];
smin = SsMin-(SsMax-SsMin)*Kmin/100;
smax = SsMax-(SsMax-SsMin)*Kmax/100;
ExtMapBuffer1[i-SSP+6]=smax;
ExtMapBuffer2[i-SSP-1]=smax;
val1 = ExtMapBuffer1[0];
val2 = ExtMapBuffer2[0];
if (val1 > val2) Comment("ïîêóïêà buy ",val1);
if (val1 < val2) Comment("ïðîäàæà sell ",val2);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments