Settlement price
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © konidtaly88

//@version=5
indicator("Settlement price",overlay=true)

i_res = input.timeframe('D', "Resolution", options=['D', 'W', 'M'])

daily_settlement_price = request.security(syminfo.tickerid, "D", close[1], barmerge.gaps_off, barmerge.lookahead_on)
daily_index = request.security(syminfo.tickerid, "D", bar_index[1], barmerge.gaps_off, barmerge.lookahead_on)
weekly_settlement_price = request.security(syminfo.tickerid, "W", close[1], barmerge.gaps_off, barmerge.lookahead_on)
weekly_index = request.security(syminfo.tickerid, "W", bar_index[1], barmerge.gaps_off, barmerge.lookahead_on)
monthly_settlement_price = request.security(syminfo.tickerid, "M", close[1], barmerge.gaps_off, barmerge.lookahead_on)
monthly_index = request.security(syminfo.tickerid, "M", bar_index[1], barmerge.gaps_off, barmerge.lookahead_on)

var today = daily_index
var this_week = weekly_index
var this_month = monthly_index

settlement_price = switch i_res
    'D' => today == daily_index? daily_settlement_price:na
    'W' => this_week == weekly_index? weekly_settlement_price:na
    'M' => this_month == monthly_index? monthly_settlement_price:na
    => na

plot(timeframe.isintraday?settlement_price:na, style=plot.style_linebr, color=color.new(color.blue, 25), offset=-1)

today := daily_index
this_week := weekly_index
this_month := monthly_index
