Braid_Filter
Download scriptThis tool is designed to help traders identify clear market trends while filtering out "market noise"—those small, insignificant price fluctuations that can often lead to false signals. By analyzing the relationship between multiple moving averages and current market volatility, it provides a visual representation of whether the market is trending strongly in one direction or remaining in a neutral state.
Core Logic Overview
The script operates by calculating three different types of Moving Averages (MAs) simultaneously. These averages are based on different timeframes and price points (such as the closing price versus the opening price). By looking at these three values together, the tool determines the "spread"—the distance between the highest and lowest moving average values at any given moment.
The Three Market States
The indicator categorizes the market into three distinct visual states based on how that spread compares to the current market volatility:
- Bullish Trend (Green): If the shortest-term trend is higher than the others and the price spread is significantly wider than the average daily movement, the tool identifies a strong upward trend. This suggests the momentum is sufficient to be considered a meaningful move.
- Bearish Trend (Red): Conversely, if the opening prices/longer trends are positioned higher than the shorter-term closing trends and the spread exceeds the volatility threshold, the tool signals a strong downward trend.
- Neutral/No Trend (Gray): If the price spread is smaller than the calculated volatility threshold (meaning the movements are too small to be considered significant) or if the averages are not showing a clear directional lead, the indicator remains gray. This tells the trader that the market is currently range-bound or "choppy," and there may not be a reliable trend to follow.
Volatility Filtering
A key feature of this logic is its use of a volatility filter (based on the Average True Range). Rather than just showing every tiny price movement as a trend, it sets a dynamic "minimum threshold." The market must move more than this specific percentage of average volatility to trigger a color change. This ensures that traders only see signals during periods of high-conviction movement, helping to avoid entering trades during flat or indecisive market conditions.
ÿþ/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
/ / | B r a i d _ F i l t e r . m q 4 |
/ / | B r a i d F i l t e r i n d i c a t o r o f R o b e r t H i l l s t o c k s a n d c o m m o d i t i e s m a g a z i n e 2 0 0 6 |
/ / | M T 4 c o d e b y M a x M i c h a e l 2 0 2 1 |
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
# p r o p e r t y i n d i c a t o r _ s e p a r a t e _ w i n d o w
# p r o p e r t y i n d i c a t o r _ b u f f e r s 4
# p r o p e r t y i n d i c a t o r _ c o l o r 1 G r e e n
# p r o p e r t y i n d i c a t o r _ w i d t h 1 4
# p r o p e r t y i n d i c a t o r _ c o l o r 2 R e d
# p r o p e r t y i n d i c a t o r _ w i d t h 2 4
# p r o p e r t y i n d i c a t o r _ c o l o r 3 G r a y
# p r o p e r t y i n d i c a t o r _ w i d t h 3 4
# p r o p e r t y i n d i c a t o r _ c o l o r 4 D o d g e r B l u e
# p r o p e r t y i n d i c a t o r _ w i d t h 4 2
# p r o p e r t y s t r i c t
/ / - - - - i n p u t p a r a m e t e r s
e x t e r n i n t M A p e r i o d 1 = 3 ;
e x t e r n i n t M A p e r i o d 2 = 7 ;
e x t e r n i n t M A p e r i o d 3 = 1 4 ;
e x t e r n i n t A T R P e r i o d = 1 4 ;
e x t e r n d o u b l e P i p s M i n S e p P e r c e n t = 4 0 ;
i n p u t E N U M _ M A _ M E T H O D M o d e M A = M O D E _ S M M A ;
/ / - - - - b u f f e r s
d o u b l e B u f f e r U P [ ] ;
d o u b l e B u f f e r D N [ ] ;
d o u b l e B u f f e r Z [ ] ;
d o u b l e V f i l t e r [ ] ;
i n t i n i t ( )
{
S e t I n d e x B u f f e r ( 0 , B u f f e r U P ) ; S e t I n d e x S t y l e ( 0 , D R A W _ H I S T O G R A M , E M P T Y , 4 ) ;
S e t I n d e x B u f f e r ( 1 , B u f f e r D N ) ; S e t I n d e x S t y l e ( 1 , D R A W _ H I S T O G R A M , E M P T Y , 4 ) ;
S e t I n d e x B u f f e r ( 2 , B u f f e r Z ) ; S e t I n d e x S t y l e ( 2 , D R A W _ H I S T O G R A M , E M P T Y , 4 ) ;
S e t I n d e x B u f f e r ( 3 , V f i l t e r ) ; S e t I n d e x S t y l e ( 3 , D R A W _ L I N E , E M P T Y , 2 ) ;
r e t u r n ( 0 ) ;
}
i n t s t a r t ( )
{
i n t M A p e r i o d = M a t h M a x ( M a t h M a x ( M A p e r i o d 1 , M A p e r i o d 2 ) , M A p e r i o d 2 ) ;
i n t l i m i t = 0 , c o u n t e d _ b a r s = I n d i c a t o r C o u n t e d ( ) ;
i f ( c o u n t e d _ b a r s <