Session Input
Yaser Rahmati | یاسر رحمتی
Goals
This script allows the user to select a specific session time range (e.g., 09:30-16:00) and colors the price plot based on whether the current bar's time falls within that selected session. If it does, the plot will be green; otherwise, it will be red.
Pine Script Code
Code Output
Explanation
1. Script Header
//@version=5
: This indicates that the script is written in Pine Script version 5.indicator("Input Session")
: This defines an indicator script with the name "Input Session." The indicator will appear on the chart with this name.
2. User Input: Session Selection
input.session
: This creates a user input field for selecting a session time range.defval = "0930-1600"
: This sets the default session time to 09:30 to 16:00.title = "Select Session"
: This is the title of the input field that will be displayed to the user.options=["0930-1600","1300-1700","1700-2100"]
: These are the available session options that the user can select from.
3. Time Calculation
time(timeframe.period, session)
: This calculates the time for the selected session based on the current chart's timeframe. Thetime
function checks whether the current bar falls within the selected session.
4. Conditional Coloring
This block defines a variable
myColor
, which is used to color the plot based on the condition:If the current time (
time
) is within the selected session (t
),myColor
is set tocolor.green
.Otherwise,
myColor
is set tocolor.red
.
5. Plotting the Close Price
plot(close, color = myColor)
: This plots the closing price of each bar on the chart. The color of the plot is determined bymyColor
(green or red) depending on whether the bar falls within the selected session.
Keywords
pine script
, trading view
, script editor
, indicators
, strategies
, backtesting
, alerts
, custom scripts
, stock analysis
, charting tools
, technical analysis
, built-in functions
, pine script syntax
, trading bots
, automated trading
, scripting language
, market data
, trading signals
, financial markets
, programming trading strategies
, یاسر رحمتی
External Links
🌐 Personal Website 📄 Resume 🎥 Video Archive 💼 Finance Blog 🔐 Network & Security Notebook 🎬 Aparat Channel
Last updated