Сoncentrated Market Maker Strategy by oxowl
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © deperp

//@version=5
indicator('Сoncentrated Market Maker Strategy by oxowl', shorttitle='СMM by oxowl', overlay=true)

// Set input parameters
liquidityPercentage = input(5, title='Liquidity Range %')
rebalanceFrequency = input(60, title='Rebalance Frequency (minutes)')
minTradeSize = input(0.01, title='Minimum Trade Size (Asset)')

// Calculate the range for liquidity provision
rangeMultiplier = 1 + liquidityPercentage / 100
upperBound = close * rangeMultiplier
lowerBound = close / rangeMultiplier

// Define the rebalancing logic
var float lastRebalanceTime = na
var float lastRebalancePrice = na

rebalanceCondition = (na(lastRebalanceTime) or time - lastRebalanceTime >= rebalanceFrequency * 60 * 1000 * 1000) and close >= lowerBound and close <= upperBound

if rebalanceCondition
    lastRebalanceTime := time
    lastRebalancePrice := close
    lastRebalancePrice

// Plot the range and trades on the chart
upperBoundLine = plot(upperBound, color=color.new(color.red, 0), linewidth=1, title='Upper Bound')
lowerBoundLine = plot(lowerBound, color=color.new(color.green, 0), linewidth=1, title='Lower Bound')

// Display price labels for upper and lower bounds
label.new(x=bar_index, y=upperBound, text=str.tostring(upperBound, '#.##'), style=label.style_none, color=color.red, textcolor=color.red, size=size.large, yloc=yloc.price)
label.new(x=bar_index, y=lowerBound, text=str.tostring(lowerBound, '#.##'), style=label.style_none, color=color.green, textcolor=color.green, size=size.large, yloc=yloc.price)

// Define alert conditions
alertConditionUpper = ta.crossover(close, upperBound)
alertConditionLower = ta.crossunder(close, lowerBound)

// Create alert conditions
alertcondition(alertConditionUpper, title='Price crossed Upper Bound', message='Price crossed the Upper Bound')
alertcondition(alertConditionLower, title='Price crossed Lower Bound', message='Price crossed the Lower Bound')

