// This Pine Scriptβ„’ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // Β© ChartPrime // 1. CHANGE VERSION TO V6 // 2. INITIALIZE BOOLEANS AS FALSE IN PINESCRIPT V6 breakout_resistance, breakout_sup, resistance_holds, support_holds // 3. CHANGE brekout to breakout with ctrl + f // 4. CHANGE res to resistance and sup to support // 5. CHANGE library to strategy // 6. If support holds: Buy, If resistance holds: sell //@version=6 strategy("Support and Resistance (High Volume Boxes) [ChartPrime]", shorttitle = "SR Breaks and Retests [ChartPrime]", overlay=true, max_boxes_count = 50) // ---------------------------------------------------------------------------------------------------------------------} // π™π™Žπ™€π™ π™„π™‰π™‹π™π™π™Ž // ---------------------------------------------------------------------------------------------------------------------{ int lookbackPeriod = input.int(20, "Lookback Period", minval=1, group = "Settings") int vol_len = input.int(2, "Delta Volume Filter Length", tooltip = "Higher input, will filter low volume boxes" , group = "Settings") float box_withd = input.float(1, "Adjust Box Width", maxval = 1000, minval = 0, step = 0.1) float riskReward = input.float(3, "Risk Reward") // Add a dropdown for strategy selection string strategySelector = input.string(defval = "Strategy 1 - Resistance Holds: Short, Support Holds: Long", options = ["Strategy 1 - Resistance Holds: Short, Support Holds: Long", "Strategy 2 - Buy on new support level", "Strategy 3 - Sell on new support level", "Strategy 4 - Buy on breakout of Resistance. SL = Resistance", "Strategy 5 - Buy on Rapid false breakouts of support zones (Stop Hunting)"], title = "Select Strategy") // ---------------------------------------------------------------------------------------------------------------------} // π™„π™‰π˜Ώπ™„π˜Ύπ˜Όπ™π™Šπ™ π˜Ύπ˜Όπ™‡π˜Ύπ™π™‡π˜Όπ™π™„π™Šπ™‰π™Ž // ---------------------------------------------------------------------------------------------------------------------{ // Delta Volume Function upAndDownVolume() => posVol = 0.0 negVol = 0.0 var isBuyVolume = true switch close > open => isBuyVolume := true close < open => isBuyVolume := false if isBuyVolume posVol += volume else negVol -= volume posVol + negVol // Function to identify support and resistance boxes calcSupportResistance(src, lookbackPeriod) => // Volume Vol = upAndDownVolume() vol_hi = ta.highest(Vol/2.5, vol_len) vol_lo = ta.lowest(Vol/2.5, vol_len) var float supportLevel = na var float supportLevel_1 = na var float resistanceLevel = na var float resistanceLevel_1 = na var box support = na var box resistance = na var color resistance_color = na var color support_color = na var float multi = na var bool breakout_resistance = false var bool breakout_support = false var bool resistance_holds = false var bool support_holds = false // Find pivot points pivotHigh = ta.pivothigh(src, lookbackPeriod, lookbackPeriod) pivotLow = ta.pivotlow (src, lookbackPeriod, lookbackPeriod) // Box width atr = ta.atr(200) withd = atr * box_withd // Find support levels with Positive Volume if (not na(pivotLow)) and Vol > vol_hi supportLevel := pivotLow supportLevel_1 := supportLevel-withd topLeft = chart.point.from_index(bar_index-lookbackPeriod, supportLevel) bottomRight = chart.point.from_index(bar_index, supportLevel_1) support_color := color.from_gradient(Vol, 0, ta.highest(Vol, 25), color(na), color.new(color.green, 30)) support := box.new( top_left = topLeft, bottom_right = bottomRight, border_color = color.green, border_width = 1, bgcolor = support_color, text = "Vol: "+str.tostring(math.round(Vol,2)), text_color = chart.fg_color, text_size = size.small ) // Find resistance levels with Negative Volume if (not na(pivotHigh)) and Vol < vol_lo resistanceLevel := pivotHigh resistanceLevel_1 := resistanceLevel + withd topLeft = chart.point.from_index(bar_index-lookbackPeriod, resistanceLevel) bottomRight = chart.point.from_index(bar_index, resistanceLevel_1) resistance_color := color.from_gradient(Vol, ta.lowest(Vol, 25), 0, color.new(color.red, 30), color(na)) resistance := box.new( top_left = topLeft, bottom_right = bottomRight, border_color = color.red, border_width = 1, bgcolor = resistance_color, text = "Vol: "+str.tostring(math.round(Vol,2)), text_color = chart.fg_color, text_size = size.small ) // Adaptive Box Len support.set_right(bar_index+1) resistance.set_right(bar_index+1) // Break of support or resistance conditions breakout_resistance := ta.crossover(low, resistanceLevel_1) resistance_holds := ta.crossunder(high, resistanceLevel) support_holds := ta.crossover(low, supportLevel) breakout_support := ta.crossunder(high, supportLevel_1) // Change Color of Support to red if it was break, change color of resistance to green if it was break if breakout_support support.set_bgcolor(color.new(color.red, 80)) support.set_border_color(color.red) support.set_border_style(line.style_dashed) if support_holds support.set_bgcolor(support_color) support.set_border_color(color.green) support.set_border_style(line.style_solid) if breakout_resistance resistance.set_bgcolor(color.new(color.green, 80)) resistance.set_border_color(color.new(color.green, 0)) resistance.set_border_style(line.style_dashed) if resistance_holds resistance.set_bgcolor(resistance_color) resistance.set_border_color(color.new(color.red, 0)) resistance.set_border_style(line.style_solid) [supportLevel, resistanceLevel, breakout_resistance, resistance_holds, support_holds, breakout_support] // Calculate support and resistance levels and their breakouts [supportLevel, resistanceLevel, breakout_resistance, resistance_holds, support_holds, breakout_support] = calcSupportResistance(close, lookbackPeriod) // Check if Resistance become Support or Support Become Resistance var bool resistance_is_support = false var bool support_is_resistance = false switch breakout_resistance => resistance_is_support := true resistance_holds => resistance_is_support := false switch breakout_support => support_is_resistance := true support_holds => support_is_resistance := false // ---------------------------------------------------------------------------------------------------------------------} // π™‘π™„π™Žπ™π˜Όπ™‡π™„π™•π˜Όπ™π™„π™Šπ™‰ // ---------------------------------------------------------------------------------------------------------------------{ // Plot resistance and support breakouts and holds plotchar(resistance_holds, "Resistance Holds", "β—†", color = #e92929, size = size.tiny, location = location.abovebar, offset = -1) plotchar(support_holds, "Support Holds", "β—†", color = #20ca26, size = size.tiny, location = location.belowbar, offset = -1) plotchar(breakout_resistance and resistance_is_support[1], "Resistance as Support Holds", "β—†", color = #20ca26, size = size.tiny, location = location.belowbar, offset = -1) plotchar(breakout_support and support_is_resistance[1], "Support as Resistance Holds", "β—†", color = #e92929, size = size.tiny, location = location.abovebar, offset = -1) // Break Out Labels if breakout_support and not support_is_resistance[1] label.new( bar_index[1], supportLevel[1], text = "Break Sup", style = label.style_label_down, color = #7e1e1e, textcolor = chart.fg_color, size = size.small ) if breakout_resistance and not resistance_is_support[1] label.new( bar_index[1], resistanceLevel[1], text = "Break Res", style = label.style_label_up, color = #2b6d2d, textcolor = chart.fg_color, size = size.small ) // Initialize longCondition and shortCondition var bool longCondition = false var bool shortCondition = false // Set conditions based on selected strategy if strategySelector == "Strategy 1 - Resistance Holds: Short, Support Holds: Long" longCondition := support_holds shortCondition := resistance_holds if strategySelector == "Strategy 2 - Buy on new support level" longCondition := (supportLevel[1] != supportLevel[0]) and (resistanceLevel > supportLevel) shortCondition := (resistanceLevel[1] != resistanceLevel[0]) and (supportLevel < resistanceLevel) if strategySelector == "Strategy 3 - Sell on new support level" longCondition := (resistanceLevel[1] != resistanceLevel[0]) and (supportLevel < resistanceLevel) shortCondition := (supportLevel[1] != supportLevel[0]) and (resistanceLevel > supportLevel) if strategySelector == "Strategy 4 - Buy on breakout of Resistance. SL = Resistance" longCondition := breakout_resistance shortCondition := breakout_support // Define ATR period and threshold atrPeriod = 14 // ATR calculated over the last 14 periods atrValue = ta.atr(atrPeriod) // Calculate ATR atrThreshold = 1.5 * atrValue // ATR must be 1.5 times higher than its average value // Strategy 5 - Buy on Rapid false breakouts of support zones (Stop Hunting) if strategySelector == "Strategy 5 - Buy on Rapid false breakouts of support zones (Stop Hunting)" longCondition := low[1] < supportLevel and close[1] > supportLevel and open[1] > supportLevel and close > open and atrValue > atrThreshold shortCondition := high[1] > resistanceLevel and close[1] < resistanceLevel and open[1] < resistanceLevel and close < open and atrValue > atrThreshold // --- Display the selected strategy title in the top-right corner of the chart --- // Create a table to display text var table strategyTable = table.new(position.top_right, 1, 1) // Update the table with the selected strategy text if bar_index == 0 table.cell(table_id = strategyTable,column = 0,row = 0,text = strategySelector,text_color = color.white,bgcolor = color.new(color.black, 90)) if strategy.position_size == 0 if longCondition stop = supportLevel limit = close + (close - supportLevel) * riskReward strategy.entry("Long", strategy.long) strategy.exit("TP / SL", "Long", limit = limit, stop = stop) if shortCondition stop = resistanceLevel limit = supportLevel strategy.entry("Short", strategy.short) strategy.exit("TP / SL", "Short", limit = limit, stop = stop) // plot(resistanceLevel, color=color.red) // plot(supportLevel, color=color.green) // β—† // ---------------------------------------------------------------------------------------------------------------------}