range trading session and days (Range SD)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #247493 quote
    Patrick K Templar
    Participant
    Average

    I want to make an indicator for Pro real time based on range of the London session the New York session and the Tokyo session from the opening and closes of their trading days and then I want to look at the previous 14 of those trading ranges so we look back at the London open and close 14 times in the past then give me the average range and then display it on the chart on over a daily 4 hour or one hour chart in a box in over the left or right hand corner showing the figures not only do I want the indicator to do that I also wanted to show me the range of the days so the last 14 Mondays average Range and then display that as a figure on the chart as well as the rest of the days of the week from Monday to Friday I want to be able to change the. I’ve looked back of those ranges from 14 to 20 to let’s say eight whatever I want to put in

     

    I have had a try code with  AI help lots of errors

    // === INPUT PARAMETERS === Range SD
    rangeLength = 14       // Lookback period (e.g., 14, 20, or 8 days)
    showTopLeft = 1        // 1 = top-left corner, 0 = top-right
    
    // === INITIALIZATION ===
    once dayRangeMonday[]  = 0
    once dayRangeTuesday[] = 0
    once dayRangeWednesday[] = 0
    once dayRangeThursday[] = 0
    once dayRangeFriday[] = 0
    
    once tyoRanges[] = 0
    once ldnRanges[] = 0
    once nycRanges[] = 0
    
    // === TIME FILTERS FOR SESSIONS (GMT) ===
    // Tokyo: 00:00 - 09:00 GMT
    inTokyoSession = (time >= 000000 and time < 090000)
    // London: 07:00 - 16:00 GMT
    inLondonSession = (time >= 070000 and time < 160000)
    // New York: 12:00 - 21:00 GMT
    inNewYorkSession = (time >= 120000 and time < 210000)
    
    // === SESSION RANGE CALCULATION ===
    if barindex > rangeLength * 24 then
        // Store daily high/low per session
        if inTokyoSession then
            tyoHigh = max(tyoHigh, high)
            tyoLow = min(tyoLow, low)
        endif
        if inLondonSession then
            ldnHigh = max(ldnHigh, high)
            ldnLow = min(ldnLow, low)
        endif
        if inNewYorkSession then
            nycHigh = max(nycHigh, high)
            nycLow = min(nycLow, low)
        endif
    
        // End of day (at 23:00 GMT) – commit range and reset
        if time = 230000 then
            // Session Ranges
            if tyoHigh <> 0 and tyoLow <> 0 then
                tyoRanges.append(tyoHigh - tyoLow)
            endif
            if ldnHigh <> 0 and ldnLow <> 0 then
                ldnRanges.append(ldnHigh - ldnLow)
            endif
            if nycHigh <> 0 and nycLow <> 0 then
                nycRanges.append(nycHigh - nycLow)
            endif
    
            // Weekday Ranges
            dayRange = high - low
            select dayofweek
                case 1
                    dayRangeMonday.append(dayRange)
                case 2
                    dayRangeTuesday.append(dayRange)
                case 3
                    dayRangeWednesday.append(dayRange)
                case 4
                    dayRangeThursday.append(dayRange)
                case 5
                    dayRangeFriday.append(dayRange)
            endselect
    
            // Reset session high/low
            tyoHigh = 0
            tyoLow = 999999
            ldnHigh = 0
            ldnLow = 999999
            nycHigh = 0
            nycLow = 999999
        endif
    endif
    
    // === AVERAGE RANGE CALCULATION FUNCTION ===
    def calcAverage(array, length)
        sum = 0
        count = min(length, array.size)
        for i = 0 to count - 1 do
            sum = sum + array[i]
        next
        if count > 0 then
            result = sum / count
        else
            result = 0
        endif
        return result
    enddef
    
    // === COMPUTE AVERAGES ===
    avgTyo = calcAverage(tyoRanges, rangeLength)
    avgLdn = calcAverage(ldnRanges, rangeLength)
    avgNyc = calcAverage(nycRanges, rangeLength)
    
    avgMon = calcAverage(dayRangeMonday, rangeLength)
    avgTue = calcAverage(dayRangeTuesday, rangeLength)
    avgWed = calcAverage(dayRangeWednesday, rangeLength)
    avgThu = calcAverage(dayRangeThursday, rangeLength)
    avgFri = calcAverage(dayRangeFriday, rangeLength)
    
    // === DISPLAY TEXT OUTPUT ===
    xOffset = 10
    yOffset = 20
    if showTopLeft then
        posX = barindex - xOffset
    else
        posX = barindex + xOffset
    endif
    
    drawtext("TYO R " + round(avgTyo), posX, high + yOffset, dialog, "Arial", 12, standard, showTopLeft)
    drawtext("LND R " + round(avgLdn), posX, high + yOffset - 10, dialog, "Arial", 12, standard, showTopLeft)
    drawtext("NYC R " + round(avgNyc), posX, high + yOffset - 20, dialog, "Arial", 12, standard, showTopLeft)
    
    drawtext("M   " + round(avgMon), posX, high + yOffset - 40, dialog, "Arial", 12, standard, showTopLeft)
    drawtext("T   " + round(avgTue), posX, high + yOffset - 50, dialog, "Arial", 12, standard, showTopLeft)
    drawtext("W   " + round(avgWed), posX, high + yOffset - 60, dialog, "Arial", 12, standard, showTopLeft)
    drawtext("T   " + round(avgThu), posX, high + yOffset - 70, dialog, "Arial", 12, standard, showTopLeft)
    drawtext("F   " + round(avgFri), posX, high + yOffset - 80, dialog, "Arial", 12, standard, showTopLeft)
    #247506 quote
    robertogozzi
    Moderator
    Master

    I just deleted the other topic in the wrong forum 🙂

    Patrick K Templar thanked this post
    #247550 quote
    Patrick K Templar
    Participant
    Average

    Hello  Roberto        Just wondering,,, trying not to be rude and being patience is virtue is there a long waiting time at the moment sorry to ask

    #247553 quote
    Iván González
    Moderator
    Master

    Hi. I think the best way is working with arrays. You can start working with this example (London):

    defparam drawonlastbaronly=true
    //----------------------------------------------//
    //-----INPUTS-----------------------------------//
    //----------------------------------------------//
    openLO=080000
    closeLO=110000
    limitday=180000
    rangelookback=5
    atr=averagetruerange[14](close)
    if gettimeframe<=3600 then
    //----------------------------------------------//
    //-----London Zone------------------------------//
    //----------------------------------------------//
    once maxHighLO=high
    once minLowLO=low
    if opentime>=openLO and opentime<=closeLO then
    barLO=barLO+1
    if high>=maxHighLO then
    maxHighLO=high
    else
    maxHighLO=maxHighLO
    endif
    if low<=minLowLO then
    minLowLO=low
    else
    minLowLO=minLowLO
    endif
    endif
    if opentime=closeLO then
    //---------------------------------------//
    // Create Arrays to store information
    //---------------------------------------//
    $minLowLO[n+1]=minLowLO
    $maxhighLo[n+1]=maxHighLO
    $dailyrange[n+1]=maxHighLO-minLowLO
    $barStart[n+1]=barindex[barLO]
    $barEnd[n+1]=barindex
    n=n+1
    //---------------------------------------//
    prevLowLO=minLowLO
    prevHighLO=maxHighLO
    previdxLO=barindex
    barLO=0
    minLowLO=high*100
    maxHighLO=0
    endif
    
    //---------------------------------------//
    // Use information stored in Arrays
    //---------------------------------------//
    if islastbarupdate then
    cumrange=0
    numrange=0
    for i=n downto n-rangelookback do
    cumrange=cumrange+$dailyrange[i]
    numrange=numrange+1
    dailyRange=$dailyrange[i]
    drawtext("Range:#dailyRange#",$barStart[i],$maxhighLo[i]+atr)
    drawrectangle($barStart[i],$minLowLO[i],$barEnd[i],$maxhighLo[i])coloured("red")fillcolor("red",30)
    next
    avgrange=round(cumrange/numrange,3)
    drawtext("AvgRange=#avgrange#",-100,-100)anchor(topright,xshift,yshift)
    
    endif
    else
    drawtext("Change timeframe to 1hr or less",0,0,SansSerif,bold,34)anchor(middle,xshift,yshift)
    endif
    return
    #247564 quote
    Patrick K Templar
    Participant
    Average

    Ok thank you very very much I have been playing about with it playing with the settings working out what does what and it’s perfect it’s exactly correct and from this I can go do some war stuff that would do like the Monday Tuesday Wednesday Thursday Friday bars might need your help with that though I’ll give it a now the question is when I do the other New York Times do I add that into the same coding or do I do it separately and have it as a separate indicator or put it all together as one what would be better   thank you thank you  

    #247600 quote
    Iván González
    Moderator
    Master

    Hi. You can code in the same indicator. Just changing the name for the variables.
    You can take as an example this indicator: https://www.prorealcode.com/prorealtime-indicators/ict-killzones-and-pivots/

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

range trading session and days (Range SD)


ProBuilder: Indicators & Custom Tools

New Reply
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Iván González
8 months, 2 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/22/2025
Status: Active
Attachments: 2 files
Logo Logo
Loading...