Sessions on Chart

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #129483 quote
    Marcel van Vliet
    Participant
    Veteran

    Hi, I was looking for an indicator that visualize the London and US session (open/ close times) with a vertical color zone. I found exactly what I was looking for on Tradingview.  https://www.tradingview.com/script/nY823NXq-Sessions-on-Chart/

    Is there anybody with enough technical knowledge to translate this indicator to a PRT (V11) version?

    The included code below is the tradingview code!

    //@version=4
    
    
    study("Sessions", overlay=true)
    
    bgColor = input(title="Activate High/Low View", type=input.bool, defval=false)
    
    LondonColor = color.green
    NYColor = color.red
    AsiaColor = color.yellow
    SydneyColor = color.navy
    
    ///Sessions
    
    res = input(title="Resolution", type=input.resolution, defval="D", options=["D","W","M"])
    london = input(title="London Session", type=input.session, defval="0300-1200")
    ny = input(title="New York Session", type=input.session, defval="0800-1700")
    tokyo = input(title="Tokyo Session", type=input.session, defval="2000-0215")
    sydney = input(title="Sydney Session", type=input.session, defval="1700-0200")
    
    //Bars
    
    is_newbar(sess) =>
        t = time(res, sess)
        na(t[1]) and not na(t) or t[1] < t
    
    is_session(sess) =>
        not na(time(timeframe.period, sess))
        
    
    //London
    
    London = input(title="London Session", type=input.bool, defval=true)
    
    londonNewbar = is_newbar(london)
    londonSession = is_session(london)
    
    float londonLow = na
    londonLow := if londonSession
        if londonNewbar
            low
        else
            min(londonLow[1],low)
    else
        londonLow[1]
    
    float londonHigh = na
    londonHigh := if londonSession
        if londonNewbar
            high
        else
            max(londonHigh[1],high)
    else
        londonHigh[1]
    
    
    plotLL = plot(londonLow, transp = 100)
    plotLH = plot(londonHigh, transp = 100)
    fill(plotLL, plotLH, color = londonSession and London and bgColor ? LondonColor : na)
    
    bgcolor(londonSession and London and not bgColor ? LondonColor : na)
    
    
    
    //New York
    
    NY = input(title="New York Session", type=input.bool, defval=true)
    
    nyNewbar = is_newbar(ny)
    nySession = is_session(ny)
    
    float nyLow = na
    nyLow := if nySession
        if nyNewbar
            low
        else
            min(nyLow[1],low)
    else
        nyLow[1]
    
    float nyHigh = na
    nyHigh := if nySession
        if nyNewbar
            high
        else
            max(nyHigh[1],high)
    else
        nyHigh[1]
    
    
    plotNYL = plot(nyLow, transp = 100)
    plotNYH = plot(nyHigh, transp = 100)
    fill(plotNYL, plotNYH, color = nySession and NY and bgColor ? color.red : na)
    
    bgcolor(nySession and NY and not bgColor ? NYColor : na)
    
    
    //Tokyo
    
    Tokyo = input(title="Tokyo Session", type=input.bool, defval=true)
    
    tokyoNewbar = is_newbar(tokyo)
    tokyoSession = is_session(tokyo)
    
    float tokyoLow = na
    tokyoLow := if tokyoSession
        if tokyoNewbar
            low
        else
            min(tokyoLow[1],low)
    else
        tokyoLow[1]
    
    float tokyoHigh = na
    tokyoHigh := if tokyoSession
        if tokyoNewbar
            high
        else
            max(tokyoHigh[1],high)
    else
        tokyoHigh[1]
    
    
    plotTL = plot(tokyoLow, transp = 100)
    plotTH = plot(tokyoHigh, transp = 100)
    fill(plotTL, plotTH, color = tokyoSession and Tokyo and bgColor ? color.yellow : na)
    
    bgcolor(tokyoSession and Tokyo and not bgColor ? AsiaColor : na)
    
    
    
    //Tokyo
    
    Sydney = input(title="Sydney Session", type=input.bool, defval=false)
    
    sydneyNewbar = is_newbar(sydney)
    sydneySession = is_session(sydney)
    
    float sydneyLow = na
    sydneyLow := if sydneySession
        if sydneyNewbar
            low
        else
            min(sydneyLow[1],low)
    else
        sydneyLow[1]
    
    float sydneyHigh = na
    sydneyHigh := if sydneySession
        if sydneyNewbar
            high
        else
            max(sydneyHigh[1],high)
    else
        sydneyHigh[1]
    
    
    plotSL = plot(sydneyLow, transp = 100)
    plotSH = plot(sydneyHigh, transp = 100)
    fill(plotSL, plotSH, color = sydneySession and Sydney and bgColor ? color.navy : na)
    
    bgcolor(sydneySession and Sydney and not bgColor ? SydneyColor : na)
    
    
    #129485 quote
    robertogozzi
    Moderator
    Master

    I wrote this code for the Asian session, but it can easily modified to accomodate other sessions.

    You can remove the part where the highest high and lowest low are detected and plotted.

    https://www.prorealcode.com/reply/66423/

    Marcel van Vliet and klimasm thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Sessions on Chart


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
5 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/02/2020
Status: Active
Attachments: No files
Logo Logo
Loading...