Plots CAGR lines for a given set of rates
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © iravan

//@version=5
indicator("Plots CAGR lines for a given set of rates", "CAGR Curves", overlay=true)

rate1 = input.float(10, "Growth Rate 1 (%)", minval=1, maxval=100)
rate2 = input.float(15, "Growth Rate 2 (%)", minval=1, maxval=100)
rate3 = input.float(20, "Growth Rate 3 (%)", minval=1, maxval=100)
custom_begin = input.bool(false, "", inline="begin")
begin = input.time(timestamp("01 Jan 2000"), "Begin At", confirm=false, inline="begin", tooltip="Enable and set this option to use a custom start date. If this option is unchecked earliest date available in TradingView for the security will be used as start date.")

var seed = 0.0
var set = false
var display = not timeframe.isintraday
var begin_time = begin
if (open > 0 and time >= begin and not set) or (not custom_begin and not set)
    seed := open
    set := true
    begin_time := time
    
days = (time_close - begin_time) / (24 * 60 * 60 * 1000)    

price1 = seed * math.pow(1 + rate1/100, days/365)
price2 = seed * math.pow(1 + rate2/100, days /365)
price3 = seed * math.pow(1 + rate3/100, days /365)

plot(set and display ? price1 : na, color=color.blue, title="Growth Rate 1")
plot(set and display ? price2 : na, color=color.green, title="Growth Rate 2")
plot(set and display ? price3 : na, color=color.red, title="Growth Rate 3")

if barstate.islast and display
    rate = str.tostring(math.round((math.pow(close / seed, 365 / days) - 1) * 100, 2)) + "%"
    label.new(bar_index + 1, close, rate, color=color.yellow, style=label.style_label_left)