nd1
Download scriptThis tool is designed to identify and visualize significant trend shifts in financial markets by analyzing price volatility and momentum. Instead of simply following every small movement in price, the logic filters out "market noise" to highlight moments where the market establishes a clear direction.
Core Logic & Mechanics
The script functions by evaluating three specific dimensions of market behavior:
1. Volatility Measurement The tool begins by calculating the average price range (the distance between the highest and lowest points) over a rolling 10-bar window. This creates a baseline for "normal" movement. By establishing this baseline, the script can distinguish between standard market fluctuations and outsized, meaningful price actions.
2. Trend Detection Filters To determine if a trend is actually forming, the script applies two distinct tests:
- The Expansion Test: It looks for a sudden, large gap in price movement that exceeds twice the average range. This identifies "breakout" behavior where the market moves aggressively in one direction.
- The Momentum Test: It looks for a sustained move over a longer period (specifically checking if the price has moved significantly more than 4.5 times the average range within a short window).
3. Dynamic Sensitivity Adjustment One of the most sophisticated parts of this logic is its ability to "self-adjust." Depending on whether it detects a strong expansion or a high-momentum move, it changes its internal sensitivity settings. If the market is moving strongly, the script tightens its parameters to stay accurate; if the market is sideways or slow, it widens them to avoid false signals.
Visual Output and Interpretation
The final result is translated into two visual buffers on your chart:
- Bullish Signals: When the momentum and volatility reach a high positive threshold (calculated via a Weighted Percentage Oscillator), the tool marks the "Low" and "High" of that price point in blue, indicating upward pressure.
- Bearish Signals: When the indicators fall below a specific lower threshold, it marks the price points in red, signaling strong downward pressure.
In essence, the logic acts as a filter that waits for the market to prove it has "conviction" before providing a signal, ensuring that traders are focused on significant trends rather than minor fluctuations.
//+-----------------------------------------------------------------------+
//| BrainTrend1.mq4 |
//| Copyright © 2005. Alejandro Galindo |
//| http://elCactus.com |
//| ASCTrend1 modified to generate similar signals to BrainTrend1 |
//| Author := C0Rpus - big thanks CHANGE2002, STEPAN and SERSH |
//| Notes := ASCTrend1 3.0 Open Source |
//+-----------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int RISK=3;
extern int CountBars=5000;
//---- buffers
double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_HISTOGRAM,0,1);
SetIndexStyle(1,DRAW_HISTOGRAM,0,1);
SetIndexBuffer(0,Buffer1);
SetIndexBuffer(1,Buffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| ASCTrend1 |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+11+1);
SetIndexDrawBegin(1,Bars-CountBars+11+1);
int i,shift,counted_bars=IndicatorCounted();
int Counter,i1,value10,value11;
double value1,x1,x2;
double value2,value3;
double TrueCount,Range,AvgRange,MRO1,MRO2;
value10=3+RISK*2;
x1=67+RISK;
x2=33-RISK;
value11=value10;
//----
if(Bars<=value11+1) return(0);
//---- initial zero
if(counted_bars<value11+1)
{
for(i=1;i<=0;i++) Buffer1[CountBars-i]=0.0;
for(i=1;i<=0;i++) Buffer2[CountBars-i]=0.0;
}
//----
shift=CountBars-11-1;
while(shift>=0)
{
Counter=shift;
Range=0.0;
AvgRange=0.0;
for (Counter=shift; Counter<=shift+9; Counter++) AvgRange=AvgRange+MathAbs(High[Counter]-Low[Counter]);
Range=AvgRange/10;
Counter=shift;
TrueCount=0;
while (Counter<shift+9 && TrueCount<1)
{if (MathAbs(Open[Counter]-Close[Counter+1])>=Range*2.0) TrueCount=TrueCount+1;
Counter=Counter+1;
}
if (TrueCount>=1) {MRO1=Counter;} else {MRO1=-1;}
Counter=shift;
TrueCount=0;
while (Counter<shift+6 && TrueCount<1)
{if (MathAbs(Close[Counter+3]-Close[Counter])>=Range*4.6) TrueCount=TrueCount+1;
Counter=Counter+1;
}
if (TrueCount>=1) {MRO2=Counter;} else {MRO2=-1;}
if (MRO1>-1) {value11=3;} else {value11=value10;}
if (MRO2>-1) {value11=4;} else {value11=value10;}
value2=100-MathAbs(iWPR(NULL,0,value11,shift)); // PercentR(value11=9)
Buffer1[shift]=0;
Buffer2[shift]=0;
if (value2>x1)
{
Buffer1[shift]=Low[shift]; Buffer2[shift]=High[shift];
}
if (value2<x2)
{
Buffer1[shift]=High[shift]; Buffer2[shift]=Low[shift];
}
shift--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments