Untitled
unknown
plain_text
4 months ago
3.4 kB
3
Indexable
//@version=6 indicator("EasyCator Bounce Zones", overlay=true, max_boxes_count=500) rightBars=input(20,'Pivot Size',tooltip="the higher the pivot size, the bigger the bounce zones") leftBars = rightBars lookBack=input(300,'Candles Searched',tooltip="How many candles it looks back to detect Bounce Zones") atr_val = ta.atr(14) ph = ta.pivothigh(high, leftBars, rightBars) pl = ta.pivotlow(low, leftBars, rightBars) lastBar = last_bar_index pIndex = bar_index - rightBars calcHeightHigh() => wick = high[rightBars] - math.max(open[rightBars], close[rightBars]) body = high[rightBars] - low[rightBars] h = wick >= atr_val and wick <= 5 * atr_val ? wick : (body >= atr_val and body <= 5 * atr_val ? body : (wick < atr_val and body < atr_val ? atr_val : 5 * atr_val)) h calcHeightLow() => wick = math.abs(math.min(open[rightBars], close[rightBars]) - low[rightBars]) body = high[rightBars] - low[rightBars] h = wick >= atr_val and wick <= 5 * atr_val ? wick : (body >= atr_val and body <= 5 * atr_val ? body : (wick < atr_val and body < atr_val ? atr_val : 5 * atr_val)) h // Arrays to store box IDs and their pivot levels var supplyBoxes = array.new_box() var supplyLevels = array.new_float() var demandBoxes = array.new_box() var demandLevels = array.new_float() // Function to check and remove overlapping zones removeOverlappingZones(array<float> levelsArray, array<box> boxesArray, float newLevel) => i = array.size(levelsArray) - 1 while i >= 0 existingLevel = array.get(levelsArray, i) if math.abs(existingLevel - newLevel) <= atr_val // Overlap detected box.delete(array.get(boxesArray, i)) array.remove(boxesArray, i) array.remove(levelsArray, i) i := i - 1 // Create supply (resistance) box if conditions are met if not na(ph) and pIndex >= (lastBar - lookBack) and pIndex < lastBar - 1 and close <= ph removeOverlappingZones(supplyLevels, supplyBoxes, ph) // Remove older overlapping zones height_box = calcHeightHigh() b = box.new(pIndex, ph, lastBar, ph - height_box, border_color=color.red, bgcolor=color.new(color.red, 80)) array.push(supplyBoxes, b) array.push(supplyLevels, ph) // Create demand (support) box if conditions are met if not na(pl) and pIndex >= (lastBar - lookBack) and pIndex < lastBar - 1 and close >= pl removeOverlappingZones(demandLevels, demandBoxes, pl) // Remove older overlapping zones height_box = calcHeightLow() b = box.new(pIndex, pl, lastBar, pl + height_box, border_color=color.green, bgcolor=color.new(color.green, 80)) array.push(demandBoxes, b) array.push(demandLevels, pl) // Iterate over supply boxes in reverse order using a while loop i = array.size(supplyBoxes) - 1 while i >= 0 level = array.get(supplyLevels, i) if close > level // Delete if price closes above resistance box.delete(array.get(supplyBoxes, i)) array.remove(supplyBoxes, i) array.remove(supplyLevels, i) i := i - 1 // Iterate over demand boxes in reverse order using a while loop j = array.size(demandBoxes) - 1 while j >= 0 level = array.get(demandLevels, j) if close < level // Delete if price closes below support box.delete(array.get(demandBoxes, j)) array.remove(demandBoxes, j) array.remove(demandLevels, j) j := j - 1
Editor is loading...
Leave a Comment