Eurobond Curve
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capriole_charles

//@version=5
indicator('Eurobond Curve (Capriole Investments)')

thresh = input(0.3, "Warning Threshold")

gem2005 = request.security('gem2005', 'D', close)
gem2006 = request.security('gem2006', 'D', close)
gem2007 = request.security('gem2007', 'D', close)
gem2008 = request.security('gem2008', 'D', close)
gem2009 = request.security('gem2009', 'D', close)
gem2010 = request.security('gem2010', 'D', close)
gem2011 = request.security('gem2011', 'D', close)
gem2012 = request.security('gem2012', 'D', close)
gem2013 = request.security('gem2013', 'D', close)
gem2014 = request.security('gem2014', 'D', close)
gem2015 = request.security('gem2015', 'D', close)
gem2016 = request.security('gem2016', 'D', close)
gem2017 = request.security('gem2017', 'D', close)
gem2018 = request.security('gem2018', 'D', close)
gem2019 = request.security('gem2019', 'D', close)
gem2020 = request.security('gem2020', 'D', close)
gem2021 = request.security('gem2021', 'D', close)
gem2022 = request.security('gem2022', 'D', close)
gem2023 = request.security('gem2023', 'D', close)
gem2024 = request.security('gem2024', 'D', close)
gem2025 = request.security('gem2025', 'D', close)
gem2026 = request.security('gem2026', 'D', close)
gem2027 = request.security('gem2027', 'D', close)
gem2028 = request.security('gem2028', 'D', close)
gem2029 = request.security('gem2029', 'D', close)
gem2030 = request.security('gem2030', 'D', close)
gem2031 = request.security('gem2031', 'D', close)
gem2032 = request.security('gem2032', 'D', close)

near=year<=2004 ? gem2005 :
     year==2005 ? gem2006 :
     year==2006 ? gem2007 :
     year==2007 ? gem2008 :
     year==2008 ? gem2009 :
     year==2009 ? gem2010 :
     year==2010 ? gem2011 :
     year==2011 ? gem2012 :
     year==2012 ? gem2013 :
     year==2013 ? gem2014 :
     year==2014 ? gem2015 :
     year==2015 ? gem2016 :
     year==2016 ? gem2017 :
     year==2017 ? gem2018 :
     year==2018 ? gem2019 :
     year==2019 ? gem2020 :
     year==2020 ? gem2021 :
     year==2021 ? gem2022 :
     year==2022 ? gem2023 : 
     year==2023 ? gem2024 : 
     year==2024 ? gem2025 : 
     year==2025 ? gem2026 : 
     year==2026 ? gem2027 : gem2028
     
mid =year<=2004 ? gem2006 :
     year==2005 ? gem2007 :
     year==2006 ? gem2008 :
     year==2007 ? gem2009 :
     year==2008 ? gem2010 :
     year==2009 ? gem2011 :
     year==2010 ? gem2012 :
     year==2011 ? gem2013 :
     year==2012 ? gem2014 :
     year==2013 ? gem2015 :
     year==2014 ? gem2016 :
     year==2015 ? gem2017 :
     year==2016 ? gem2018 :
     year==2017 ? gem2019 :
     year==2018 ? gem2020 :
     year==2019 ? gem2021 :
     year==2020 ? gem2022 :
     year==2021 ? gem2023 :
     year==2022 ? gem2024 : 
     year==2023 ? gem2025 : 
     year==2024 ? gem2026 : 
     year==2025 ? gem2027 : 
     year==2026 ? gem2028 : gem2029

far =year<=2004 ? gem2009 :
     year==2005 ? gem2010 :
     year==2006 ? gem2011 :
     year==2007 ? gem2012 :
     year==2008 ? gem2013 :
     year==2009 ? gem2014 :
     year==2010 ? gem2015 :
     year==2011 ? gem2016 :
     year==2012 ? gem2017 :
     year==2013 ? gem2018 :
     year==2014 ? gem2019 :
     year==2015 ? gem2020 :
     year==2016 ? gem2021 :
     year==2017 ? gem2022 :
     year==2018 ? gem2023 :
     year==2019 ? gem2024 :
     year==2020 ? gem2025 :
     year==2021 ? gem2026 :
     year==2022 ? gem2027 :
     year==2023 ? gem2028 :
     year==2024 ? gem2029 :
     year==2025 ? gem2030 :
     year==2026 ? gem2031 : gem2032

plot(near,color=color.new(color.red,50))
plot(mid,color=color.new(color.purple,50))
plot(far,color=color.new(color.black,50))

warning = ta.barssince(mid-far<thresh)<10 and mid>far and near>far //and ta.barssince(mid-far<thresh)[10]>365
risky1 = ta.barssince(near<far)<10
risky2 = ta.barssince(mid<far)<10

bgcolor(warning  ? color.new(color.orange,90):na)
bgcolor(risky1   ? color.new(color.red,90):na)
bgcolor(risky2   ? color.new(color.purple,90):na)

// Sourcing
var table_source = table(na)
table_source := table.new(position=position.bottom_left, columns=1, rows=1, bgcolor=color.white, border_width=1)
table.cell(table_source, 0, 0, text="Source: Capriole Investments Limited", bgcolor=color.white, text_color=color.black, width=20, height=7, text_size=size.normal, text_halign=text.align_left)