[TTI] MarketSmith & IBD Style Model Stock Quarters 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TintinTrading

//@version=5
indicator("[TTI] MarketSmith & IBD Style Model Stock Quarters ", overlay=true, max_lines_count=500)

// Function to get the abbreviation of the next month
nextMonthAbbreviation(month) =>
    month == 1 ? "Feb" :
     month == 2 ? "Mar" :
     month == 3 ? "Apr" :
     month == 4 ? "May" :
     month == 5 ? "Jun" :
     month == 6 ? "Jul" :
     month == 7 ? "Aug" :
     month == 8 ? "Sep" :
     month == 9 ? "Oct" :
     month == 10 ? "Nov" :
     month == 11 ? "Dec" : "Jan"

nextmonth = month == 1 ? "Feb" : month == 2 ? "Mar" : month == 3 ? "Apr" : month == 4 ? "May" : month == 5 ? "Jun" : month == 6 ? "Jul" : month == 7 ? "Aug" : month == 8 ? "Sep" : month == 9 ? "Oct" : month == 10 ? "Nov" : month == 11 ? "Dec" : "Jan"

// Draw a line at the beginning of the quarter
if month==1 and month[1] !=1 or month==4 and month[1] !=4 or month==7 and month[1] !=7 or month==10 and month[1] !=10  
    line.new(bar_index, close, bar_index, close*1.01, width = 1, color=color.black, extend = extend.both)

// linescol = month==1 and month[1] !=1 or month==4 and month[1] !=4 or month==7 and month[1] !=7 or month==10 and month[1] !=10 
// bgcolor(linescol ? color.black : na)


//var t1 = 0
t1 = month==2 or month==5 or month==8 or month==11 
t2 = t1 and t1[1] != t1 ? 1 : 0

if t2 
    label.new(bar_index, 0, text=nextMonthAbbreviation(month)+" "+str.tostring(year%100), style=label.style_none, textalign=text.align_center)

