Strategy · Pine Script v6 · On the chart

Time and schedule

by JoelPasapera· code credited to JJPP_Joel

This strategy opens a long or short position on a chosen weekday when the chart hour falls inside a user-defined start and end window.

View on GitHub

Repaints

GitHub stars11on the repository
Pine versionv6current
Lines of code44
Settings7inputs
LicenceApache-2.0
Last update5 months ago23 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

44 lines of Pine Script v6 from time_and_schedule/time_and_schedule.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

time_and_schedule.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JJPP_Joel
// Author: Joel Pasapera Pinto
//@version=6

// Constants
var int initial_balance = 10000 // set a realistic initial balance

strategy("Time and schedule", overlay=true, fill_orders_on_standard_ohlc = true, initial_capital = initial_balance, calc_on_every_tick = true)

// Inputs are defined
float lot_size = input.float(defval = 1, title = "lot_size",step=0.1)
int start_time = input.int(defval = 13, title="Start time", minval=0, maxval=24)
int end_time = input.int(defval = 16, title="End time", minval=0, maxval=24)
bool buy_or_sell = input.bool(defval = true, title = "Buy? (otherwise sell)")
int day_of_week = input.int(defval = dayofweek.friday, title = "dayofweek",minval=0,maxval=8)
color color_session   = input.color(defval = color.red,title="Color session",display = display.none) 
int transparency = input.int(defval = 80, title="Transparency (%)", minval=0, maxval=100)

// Global variables are defined
bool long_condition = false
bool short_condition = false

// The current bar is inside of the session?
bool in_session = (dayofweek == day_of_week) and (hour>= start_time and hour <= end_time)

// Buy and sell condition
if in_session
    if hour <= start_time
        long_condition := true // buy
        
    if hour >= end_time
        short_condition := true // sell

// Buy or sell with the signal?
if (buy_or_sell ? long_condition : short_condition) 
    strategy.entry("My Long Entry Id", strategy.long,qty = lot_size)
    
if (buy_or_sell ? short_condition : long_condition) 
    strategy.entry("My Short Entry Id", strategy.short, qty = lot_size)
    

// Colour the background of each in_session
bgcolor(color= in_session ? color.new(color_session, transparency) : na, title="New York")

Overview

With the buy toggle on, it enters long near the window start and short near the window end; turning the toggle off reverses those directions. Quantity follows a fixed lot size. It shades the active session on the price chart. There is no stop loss, take profit, or other exit rule, and calculation on every tick can change signals on the live bar.

Details

Published by

JoelPasapera on GitHub

Code credit

JJPP_Joel, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Sessions & time

Markets

Forex, Gold, Stocks

Timeframes

M1-M5, M15-H1, H4 and above

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Topics

botpinescriptstrategytradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
lot_sizefloat1lot_size
Start timeint13start_time
End timeint16end_time
Buy? (otherwise sell)booltruebuy_or_sell
dayofweekintdayofweek.fridayday_of_week
Color sessioncolorcolor.redcolor_session
Transparency (%)int80transparency
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

361 stars

Forven S01512 — Monday Drift is a calendar-based long trading strategy designed to exploit time-based recurring market patterns. It tracks UTC calendar days and hours to enter a long position at a specified day and hour, holding it for a fixed duration until a

Strategy v6 Sessions & time
Updated today · AGPL-3.0 GitHub repository of Forven S01512 - Monday Drift

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated today · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]
257 stars

Donald - Test Logic Futures is an overlay strategy designed for intraday futures trading. It combines kernel regression functions with exponential moving averages to evaluate price retracements and entry timing. Trades are filtered by session execution windows

Strategy v5 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald - Test Logic Futures

Daily Bias + FVG Strategy

by TradersPost
218 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
106 stars

This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status

Strategy v4 Screeners & dashboardsBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 1St Bar GAP+BkOut Screener v2 by RM
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers