Here is a smart idea for an indicator to detect range, as it compares 2 bollinger bandwidth spread as an hint for current price contraction.
When the oscillator is set to 1, price is ranging and “NoTrade” would be initiated.
a = BollingerUp[40](close)
b = BollingerDown[40](close)
B1Range = a - b
c = BollingerUp[20](close)
d = BollingerDown[20](close)
B2Range = c - d
if B2Range < (B1Range/2) then
NoTrade = 1
else
NoTrade = 0
endif
return NoTrade AS "No Trade"
You must be logged in to post a comment.
Hello, what does it mean the 20 and 40 number on this code ? Thank you !
I modified it to make parameters customizable and to Draw a Grey candlestick when a range is detected (sorry for the code, but the "Add PRT code" button didn't work): // Bollinger Band range setection // DEFPARAM CalculateOnLastBars = 1000 // BB1 = 40 // BB2 = 20 // RangeDivisor = 2.0 // a = BollingerUp[BB1](close) b = BollingerDown[BB1](close) B1Range = a - b c = BollingerUp[BB2](close) d = BollingerDown[BB2](close) B2Range = c - d if B2Range < (B1Range/RangeDivisor) then DRAWCANDLE(Open,High,Low,Close) COLOURED(230,230,250,255) bordercolor(0,255,255,50) //Cyan border //NoTrade = 1 else //NoTrade = 0 endif return // NoTrade AS "No Trade"