sessiontimepine-scriptpine-script-v5

How do I create a session that runs from friday till sunday the following week?


I understand that sessions can be written as such

For e.g. session1 = "1000-1300" or session2 = "1000-1300:2" for mondays only

However I am unable to write a session that runs from Friday 10:00 till Sunday 21:00. How can I go about doing that as I am coding the sessions for NQ futures market.

I tried writing this code but the session stops at 16:59 on Friday when trading stops for the week.

session1 = "1000 - 2100:6"


Solution

  • `"1000-2100:6" in this case, your session only contains Friday (6). You need to add Sunday (1) to the string as well.

    //@version=5
    indicator("My script", overlay=true)
    
    session1 = "1000-2100:16"
    
    is_in_sess = bool(time(timeframe.period, session1))
    
    bgcolor(is_in_sess ? color.new(color.green, 85) : na)
    

    enter image description here