Gotobi Teriyaki
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hosono_p

//@version=5
strategy("Gotobi Teriyaki", overlay=true)

current_day= dayofmonth(time("1"), "Asia/Tokyo")
saturday = dayofmonth(time("1")+ 1000*60*60*24 , "Asia/Tokyo")
sunday = dayofmonth(time("1")+ 1000*60*60*48, "Asia/Tokyo")
is_5day_10day= current_day % 5==0
flyday = dayofweek(time("1"), "Asia/Tokyo") == 6
flyday_5day_10day = (flyday and saturday % 5==0) or (flyday and sunday % 5==0)

buy_time = time("1", "0200-0955:23456","Asia/Tokyo") and is_5day_10day or time("1", "0200-0955:23456","Asia/Tokyo") and flyday_5day_10day
bgcolor(buy_time ? color.new(color.green, 90) : na)

sell_time = time("1", "0955-1500:23456","Asia/Tokyo") and is_5day_10day or time("1", "0955-1500:23456","Asia/Tokyo") and flyday_5day_10day
bgcolor(sell_time ? color.new(color.red, 90) : na)

if strategy.position_size > 0
    if not buy_time
        strategy.close_all()
if strategy.position_size < 0
    if not sell_time
        strategy.close_all() 

if strategy.position_size == 0
    if buy_time
        strategy.entry("buy",strategy.long)
    if sell_time
        strategy.entry("sell",strategy.short)