Day/Week/Month/3M/6M/12M MTF breaks by makuchaku
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © makuchaku

//@version=4
study("Day/Week/Month/3M/6M/12M MTF breaks by makuchaku", shorttitle="Day/Week/Month/3M/6M/12M MTF breaks", overlay=true, scale=scale.none)

// workaround to apply this indicator to another indicator
src = input(title="Source", type=input.source, defval=close)

is_new(resolution) =>
    t = time(resolution)
    not na(t) and (na(t[1]) or t > t[1])

is_new_month() =>
    is_new('M')
is_new_week() =>
    is_new('W')
is_new_quarter() =>
    is_new("3M")    
is_new_half_year() =>
    is_new("6M")        
is_new_year() =>
    is_new("12M")
is_new_day() =>
    is_new("D")    

// plotting
plot(is_new_day() ? 1 : na, style=plot.style_histogram, color=color.new(color.gray, 50), title='Day breaks')
plot(is_new_week() ? 1 : na, style=plot.style_histogram, color=color.new(color.blue, 50), title='Week breaks')
plot(is_new_month() ? 1 : na, style=plot.style_histogram, color=color.new(color.red, 50), title='Month breaks')
plot(is_new_year() ? 1 : na, style=plot.style_histogram, color=color.new(color.gray, 50), title='Year breaks')
plot(is_new_quarter() ? 1 : na, style=plot.style_histogram, color=color.new(color.gray, 50), title='Quarter breaks')
plot(is_new_half_year() ? 1 : na, style=plot.style_histogram, color=color.new(color.gray, 50), title='Half year breaks')












