nd1Stop
Download scriptThis script is a specialized technical analysis tool designed to help traders identify the primary direction of the market and pinpoint potential trend reversals. Instead of just showing simple moving averages, it focuses on "trailing" price action to visualize the momentum of a market movement.
Core Logic Overview
The indicator works by calculating a dynamic buffer zone based on recent market volatility. Here is a breakdown of how it processes information:
1. Volatility Assessment The tool begins by looking at a specific window of past data (defined by the "Average Period"). It measures the difference between the highest and lowest prices within that timeframe to determine the current "volatility" of the market. This calculation ensures that the indicator adapts to whether the market is currently moving in small, stable increments or large, aggressive swings.
2. Trend Detection and Tracking The script identifies the initial trend by comparing the opening and closing prices of a candle.
- If the price closes higher than it opened, it establishes an upward trend.
- If the price closes lower than it opened, it establishes a downward trend.
Once a trend is established, the indicator begins to "track" the highest or lowest prices reached during that movement. It effectively follows the "path of least resistance," keeping updated records of the peak (in an uptrend) or the trough (in a downtrend).
3. Dynamic Stop-Loss Logic (The "Trailing" Effect) The most unique feature of this logic is how it calculates its position line:
- In an Uptrend: The indicator looks for the highest price reached so far. It then subtracts a calculated percentage based on the volatility (the "dK" value) from that peak. This creates a trailing line that stays just below the market highs. If the price falls significantly enough to cross under this calculated line, the script recognizes that the upward momentum has broken and flips the trend to downward.
- In a Downtrend: The logic reverses. It tracks the lowest price reached and adds the volatility buffer above it. If the price rallies high enough to break above this buffered "floor," the script identifies a reversal and switches the trend to upward.
Visual Output
On your chart, this logic manifests as two distinct markers or lines:
- Blue Indicators: Represent the active upward trend, trailing below the price action.
- Red Indicators: Represent the active downward trend, trailing above the price action.
By observing where these lines sit relative to the current price, a trader can see not only which direction the market is currently heading but also how much "breathing room" remains before a potential trend reversal might occur.
//+-----------------------------------------------------------------------+
//| BrainTrend1Stop.mq4 |
//| Copyright © 2005. Alejandro Galindo |
//| http://elCactus.com |
//| Author := VG many thanks to Konkop and dupidu1 |
//+-----------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int AveragePeriod=10;
//---- buffers
double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexBuffer(0,Buffer1);
SetIndexBuffer(1,Buffer2);
SetIndexArrow(0,159);
SetIndexArrow(1,159);
//----
return(0);
}
//+------------------------------------------------------------------+
//| BrainTrend1Stop |
//+------------------------------------------------------------------+
int start()
{
int i,shift,counted_bars=IndicatorCounted();
double value=0, price=0, trend=0, dK=0, AvgRange=0;
int bar=0;
int CountBars=20000;
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+11+1);
SetIndexDrawBegin(1,Bars-CountBars+11+1);
//---- initial zero
AvgRange=0;
for (i=1;i<=AveragePeriod;i++) { AvgRange+= MathAbs(High[i]-Low[i]); }
if (Point>=0.01) { dK = (AvgRange/AveragePeriod)*Point; }
else { dK = (AvgRange/AveragePeriod); }
if (Close[Bars-1] > Open[Bars-1])
{
value = Close[Bars - 1] * (1 - dK);
trend = 1;
Buffer2[Bars-1]=value;
}
if (Close[Bars-1] < Open[Bars-1])
{
value = Close[Bars - 1] * (1 + dK);
trend = -1;
Buffer1[Bars-1]=value;
}
bar=CountBars-11-1;
while(bar>=0)
{
Buffer1[shift]=0;
Buffer2[shift]=0;
if (trend >= 0)
{
if (Close[bar] > price) { price = Close[bar]; }
value = price * (1 - dK);
if (Close[bar] < value)
{
price = Close[bar];
value = price * (1 + dK);
trend = -1;
}
} else {
if (trend <= 0) {
if (Close[bar] < price) { price = Close[bar]; }
value = price * (1 + dK);
if (Close[bar] > value)
{
price = Close[bar];
value = price * (1 - dK);
trend = 1;
}
}
}
if (trend == -1) { Buffer1[bar]=value; }
if (trend == 1) { Buffer2[bar]=value; }
//----
bar--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments