Hi. Im trying to write an indicator for this, but not getting it right.
What we are looking for is a price consolidation that usually stays within a 10-40 point range.
We want to see the price stay within this range for at least 5 candlesticks, where a lower timeframe (TF) would require more bars to confirm the consolidation.
The example picture is on a 15-minute TF for Tech100
Next, we want to see the price break out with reasonable strength, where at least 50% of the breakout bar is outside this “box.”
There are two different approaches for trading this:
1. If the trend is upward, we take an entry at the bottom of the consolidation after a certain number of bars, and the opposite at the top if the trend is downward.
2. An entry is taken as the breakout occurs, preferably when the breakout bar is outside the box, to avoid false moves.
This pattern can also occur in larger intervals. For example, we have a range of over 100 points on NAS in a 5-minute TF.
The main rule is that we want to see the price find clear resistance on both the upside and downside, and then break out with significant strength.
// Parameters
minBars = 5 // Minimum number of bars for consolidation
maxRangePoints = 40 // Maximum range in points for consolidation
minRangePoints = 10 // Minimum range in points for consolidation
breakoutStrength = 0.5 // At least 50% of the breakout bar must be outside the box
// Variables to store the highest and lowest prices within the consolidation range
highestHigh = highest(minBars)(high)
lowestLow = lowest(minBars)(low)
// Check if the range is within the defined point range
priceRange = highestHigh - lowestLow
if priceRange <= maxRangePoints * pipsize and priceRange >= minRangePoints * pipsize then
// Draw the consolidation box
drawrectangle(barindex[minBars], highestHigh, barindex, lowestLow, colorRGBA(100, 100, 255, 50))
// Check for a breakout
if close > highestHigh and (close - highestHigh) >= (high - low) * breakoutStrength then
DRAWTEXT("▲", barindex, high, color.green)
elsif close < lowestLow and (lowestLow - close) >= (high - low) * breakoutStrength then
DRAWTEXT("▼", barindex, low, color.red)
endif
endif
return close