Alerts & TIME SESSIONS • Pine Script [OUTDATED V4] Tutorial

Pine Script Mastery Course:
FREE Pine Script Basics Course:
Source Code:
My Indicators:
Pine Scripters Network (Forum):

This lesson comes from a question submitted by Jason over at The Chart Guys:

Want to learn Pine Script? Look no further. I have you covered.

This guide covers how to use time sessions to determine when (or when not) to trigger alerts.

With over 15 years of coding experience and 4+ years of trading experience, I now specialize in TradingView’s Pine Script programming language and I’m here to pass on everything I’ve learned about both trading and coding.

If you want more information about who I am and what I do, head over to

00:00 – Intro
00:52 – User Input
02:30 – Time Session Function
05:40 – Check Candle Time
07:30 – Change Bar Color
08:50 – Disable Alerts Within Session
10:30 – Enable Alerts Within Session
12:16 – Pine Script Mastery Course

#PineScript #TradingView #Trading


  1. Hello. Thank you for this video. I was wondering if you could help me. When I input this script, I receive the error: Undeclared identifier 'session' on this line: 

    // Check if the current bar falls within our session

    isInSession = isInSession(session)

    Any help would be much appreciated. Thank you for the hard work.

  2. Hi, I want a pine script where I can put an alert when the moving average changes its color from green to red or from red to green. Please tell me how can i do it.

  3. Thank you very much! I have followed your lesson and use the script on Hang Seng Index future HSI1! Your script works well on Monday to Thursday. For Friday after market, ie. Hong Kong Time Friday 1601-Sat 0300, the script cannot detect. Very grateful if you can teach me how to detect the Friday after market session. Thank you!

  4. Whats the code for Backtesting for Intraday Basis . Like Im Backtesting a Strategy for a month . i Need every Orders to be Exited (as im not a Delivery trader) at certain time before market close.
    Currently my backtest traders pick buy and close in Next day . HOW TO ADD MARKET TIMING IN BACKTEST . tnx

  5. hello can you do a video based how to create a tradingview alerts based on time. For instance if I only want my alerts to trigger at 7am based on the 3hr chart with gbpusd pair using 7sma crossing 21sma. I guess your "Trigger Alerts WITHIN Time Session" script should do the trick right.

  6. hello sir. hope u r good. saw your tutorials and they are really awesome for newcomers like me. i need your help in modifying your RSI script== lets suppose price of 'X' is $6000, and it rises to $7000 and RSI also goes above band70. now i want alert gets activated when it drops to $6980(i.e. gets trail back by $20). how can i code this TRAIL script in your RSI pinescript below:


    study("rsi overbought", overlay=true)

    // Get user input

    rsiSource = input(title="RSI Source", type=input.source, defval=close)

    rsiLength = input(title="RSI Length", type=input.integer, defval=14)

    rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=70)

    // Get RSI Value

    rsiValue = rsi(rsiSource, rsiLength)

    isRsiOB = rsiValue >= rsiOverbought

    // Plot signals to chart

    plotshape(isRsiOB, title="Overbought", location=location.abovebar,, transp=0, style=shape.triangledown, text="Sell")

    // Send out an alert if this candle meets our conditions

    alertcondition(isRsiOB , title="RSI Signal!", message="RSI Signal Detected for {{ticker}}")

Leave a Reply

© 2023 53GB