Indicator: Mini window for multi-timeframe charts

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #265287 quote
    drubydruby
    Participant
    Junior

    Been AWOL from PRT & PRC for a while and now looking at what i was last working on.

    The idea of the Mini Window was motivated because my low res laptop wasn’t practicable when multiple visible charts open for multiple time frames.

    This code is an early version which was a proof of concept and made possible with the DRAW – ANCHOR option of fixed pixel drawing. It allowed the last ‘n’ bars could be displayed while the main chart was scrolled etc, or a different time frame if enough bars there to calculate. I initially used several modified code files for different time frames with offset of drawing positions.

    The project turned into solving or getting around problems by adding different features in later versions, which I’ll post as i look through them. As i recalled I worked on config variables to aid if multiple indicator used, adding basic indicator’s and avoiding issues thrown up by the developed.

    Hopefully it may be of use, I don’t know much about the web and mobile versions but monitoring several time frames at the same time was helpful option to me for a quick way to monitor different time frames without changing the main chart or polling different charts windows.

    Regards.


    defparam drawonlastbaronly = true
    
    //timeframe(15minutes)
    if islastbarupdate then  // skip historic bars
    
    
    LB = 40             // lookback ( no. of mini window candles +1 )
    winX = (5*(LB+4))   // width of window in pixels
    winY =  250         // height of window in pixels
    
    loRef= min(lowest[LB](low),low)    // lowest from LB bars
    HiRef= max(highest[LB](high),high) // highest from LB bars
    hiLoRng = HiRef-LoRef              // range over LB bars
    ref = (winY-20)/hilorng            // y axis scale multiplier
    // ------------------------------------------ rectangle
    
    
    // ------------------ absolute (a)
    ax1 = 40  // offset from LHS of chart frame
    ax2 = ax1 + winX// 300
    
    ay1 = -40  // offset ftom top of chart frame
    ay2 = ay1 - winY//-300
    
    
    // ------------------------------------------ mini window rectangle box
    x1 = 0 + ax1      // position left inc offset
    x2 = x1 + winX    // position from left to right
    
    y1 = 0 + ay2      // position top inc offset
    y2 = y1 + winY    // position from top to bottom
    
    drawrectangle(x1,y1,x2,y2)anchor(topleft,xshift,yshift) // mini window box border
    /*
    drawtext("x1y1",x1,y1)coloured("red")anchor(topleft,xshift,yshift) // ref: box corner coordinate's
    drawtext("x2y2",x2,y2)coloured("red")anchor(topleft,xshift,yshift) // "
    drawtext("x1y2",x1,y2)coloured("red")anchor(topleft,xshift,yshift) // "
    drawtext("x2y1",x2,y1)coloured("red")anchor(topleft,xshift,yshift) // "
    */
    
    // ------------------------------------------- candle construction
    
    t = LB
    for i = 0 to LB
    os = 10
    start = ax1+os  // offset from chart left edge
    width = 3       // candle width
    gap = 5         // gap between candles, may be senter's
    
    
    op =  os+ay2+((open [t-i]-loref)*ref)
    hi =  os+ay2+((high [t-i]-loref)*ref)
    lo =  os+ay2+((low  [t-i]-loref)*ref)
    cl =  os+ay2+((close[t-i]-loref)*ref)
    
    
    x1 = (gap * i) + start
    x2 = x1 + width
    
    y1 = op
    y2 = cl
    
    if op>cl then // bear candle body
    drawrectangle(x1,y1,x2,y2)anchor(topLeft,xshift,yshift)coloured(255,0,0,155)bordercolor(255,255,255,100)
    else // bull candle body
    drawrectangle(x1,y1,x2,y2)anchor(topLeft,xshift,yshift)coloured(0,255,0,155)bordercolor(255,255,255,100)
    endif
    // candle wicks
    drawsegment(x1 + 1,hi,x1+1, lo)anchor(topLeft,xshift,yshift)coloured(255,255,255,155)
    
    next
    
    endif // skip historic bars
    
    return
    
    Nicolas, RicLg, Iván González and Bernard13 thanked this post
    #265291 quote
    NicolasNicolas
    Keymaster
    Legend

    Hi Druby,

    Thanks for sharing this code, very useful. Do you have any screenshot of how it looks on your chart?

    #265293 quote
    drubydruby
    Participant
    Junior

    Hi Nicolas, I realised that when i posted and when used the EDIT feature to add a image, on SUBMIT, the post vanished from the editor and after wondering what had happened I noticed a label that the subject had been treated as SPAM.


    

    #265295 quote
    drubydruby
    Participant
    Junior

    Both post have had the image copied into the text frame, either directly or with edit and images do not appear. Not sure why, maybe there’s been a change.

    Screenshot-2026-09-23-151452.png Screenshot-2026-09-23-151452.png
    #265300 quote
    drubydruby
    Participant
    Junior

    I don’t have my original PRT account so I’m having to build back manually with the ‘Export my personal data’ files. I abandoned development and here’s a image from the last version which showed some added indicators, used several CALL’ed file’s, multiple instances. So I’m hoping to continue when I’m back up to date and understood how it works.

    Nicolas and RicLg thanked this post
    Screenshot-2026-09-23-164117.png Screenshot-2026-09-23-164117.png
    #265303 quote
    NicolasNicolas
    Keymaster
    Legend

    Wow, it looks great, very well done! 🙂

    RicLg thanked this post
    #265307 quote
    drubydruby
    Participant
    Junior

    Now the mini window shows the candles, the next step is to add the indicators you may have on a full chart to aid reference of the bars. Here I take a Simple Moving Average and add to the window.

    The main structure stay similar barring some variable names and equation changes, but the major change is the determining the higher high and lower low elements in the window..

    In the prior version, this was done with the candle high and low, but, ‘indicator(s)’ could be higher and/or lower than the candles. Two arrays hold the value from each element to be displayed, and there is an extra section to find the highest and lowest from them. Though open and close are not needed, I’m treating them all as if there were indicator outputs.

    There is a section to draw the indicator line using segments, which is from the bar centrers of the previous point to the new point.

    Also note, most of code is inside a isLastBarUpdate block but the ‘Average’ keyword is outside. The OHLC values are embedded constants in PRT so when using inside isLastBarUpdate, (to skip historic bars,) all there values exist for each bar. But for Average , this is not the same and its output values are calculated on each bar. So, though code could be written to look back at the appropriate close values to get the Average LB bar output values, they would have to be stored in an array for later use. Here the simple solution is to put it outside the isLastBarUpdate and assume that the performance difference between the stock Average code running on all bars is faster than a custom code on a select number of bars.. Keeping it simple also allows stock/custom indicators to be usable and avoid re-inventing the wheel for each indicator/type.


    defparam drawonlastbaronly = true
    
    //timeframe(15minutes)
    
    avg = average[50](close)  // got to be outside of islastbarupdate
    // to populate prior bar values
    
    if islastbarupdate then
    
    LB = 40-1                       // lookback bars 0-39
    sizeBar = 5                   // frame bar size pixels
    winX =  max(sizeBar*LB,250)   // width of frame
    winy =  min(winX,350)         // height of frame
    
    // ------------------ absolute coords
    ax1 = 40            // indent from left chart edge to left frame edge
    ax2 = ax1 + winX    // right frame edge
    
    ay1 = -40           // indent from top chart edge to top frame edge
    ay2 = ay1 - winY    // bottom frame edge
    
    
    // ------------------OHLC
    // ------------------ lowest & highest over LB bars
    $indL[0] = min(lowest[LB](open),open)    // max of open
    $indH[0] = max(highest[LB](open),open)   // min of open
    $indL[1] = min(lowest[LB](low),low)      // max of low
    $indH[1] = max(highest[LB](low),low)     // min of low
    $indL[2] = min(lowest[LB](high),high)    // max of high
    $indH[2] = max(highest[LB](high),high)   // min of high
    $indL[3] = min(lowest[LB](close),close)  // max of close
    $indH[3] = max(highest[LB](close),close) // min of close
    
    
    // ------------------ indicators
    $indL[4] = min(lowest[LB](avg),avg)    // max of close
    $indH[4] = max(highest[LB](avg),avg)   // min of close
    
    // ---------------------------------------------------------------- candle range
    // find the HH/LL of all items, $indL[] and $indH[].
    
    for i = 0 to lastset($indH)
    
    if i = 0 then
    LL = $indL[i]              // start at a default, 1st in list!
    HH = $indH[i]
    elsif $indL[i] < LL then      //  further LL
    LL = $indL[i]
    elsif $indH[i] > HH then      // further HH
    HH = $indH[i]
    endif
    
    next
    
    loRef= LL   // lowest low from LB bars of $indL[]
    HiRef= HH   // highest high from LB bars of $indH[]
    
    hiLoRng = HiRef-LoRef                // vertical range over LB bars
    ref = (winY)/hilorng                 // point to pixels conversion constant
    
    // ---------------------------------------------------------------- candle display
    
    for i = 0 to LB
    
    xref = ax1 + (sizeBar * i) // reference to center of bar
    
    op =  ay2+((open [LB-i]-loref)*ref) // pixel conversions
    hi =  ay2+((high [LB-i]-loref)*ref) // take the difference between the current ohlc values
    lo =  ay2+((low  [LB-i]-loref)*ref) // and the lowest low. LB-1 reverses the index to i.
    cl =  ay2+((close[LB-i]-loref)*ref) // multiply by constant. reference all to frame bottom edge.
    
    
    x1 = xref
    x2 = xref
    
    y1 = op
    y2 = cl
    
    // ------------------------------------------------ draw candles body
    if op>cl then // bear candle
    drawrectangle(x1-1,y1,x2+1,y2)anchor(topLeft,xshift,yshift)coloured("red",155)bordercolor("white",100)
    else // bull candle
    drawrectangle(x1-1,y1,x2+1,y2)anchor(topLeft,xshift,yshift)coloured("lime",155)bordercolor("white",100)
    endif
    // ------------------------------------------------ draw candles wicks
    y1 = hi
    y2 = lo
    drawsegment(x1,y1,x2,y2)anchor(topLeft,xshift,yshift)coloured("white",155)
    next
     
    // ---------------------------------------------------------------- draw line
    
    for i = 0 to LB
    xref = ax1 + (sizeBar * i) // reference to center of bar
    
    av =   ay2+((avg[LB-i]  -loref)*ref)
    av1 =  ay2+((avg[LB-i+1]-loref)*ref) // +1 for prior position
    
    x1 = xref-5 // -5 is so the segment is draw from the last position to the new position
    x2 = xref
    
    
    y1 = av1
    y2 = av
    drawsegment(x1,y1,x2,y2)anchor(topLeft,xshift,yshift)coloured("yellow",255)
    next
    
    // ---------------------------------------------------------------- rectangle border
    
    indent = 10 // outside of frame
    
    x1 = ax1 - indent
    x2 = ax1 + (LB*sizeBar ) +indent   // max left width
    
    y1 = 0 + ay2 - indent            // max top height
    y2 = y1 + winY + (2 * indent)
    
    drawrectangle(x1,y1,x2,y2)anchor(topleft,xshift,yshift)style(dottedline,1)
    // corner references
    a=100
    drawtext("x1y1",x1,y1)coloured("red",a)anchor(topleft,xshift,yshift)
    drawtext("x2y2",x2,y2)coloured("red",a)anchor(topleft,xshift,yshift)
    drawtext("x1y2",x1,y2)coloured("red",a)anchor(topleft,xshift,yshift)
    drawtext("x2y1",x2,y1)coloured("red",a)anchor(topleft,xshift,yshift)
    
    
    endif // skip historic bars
    
    return
    
    Iván González, Bernard13 and RicLg thanked this post
    Screenshot-2026-09-24-080324.png Screenshot-2026-09-24-080324.png
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Indicator: Mini window for multi-timeframe charts


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
druby @druby Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by drubydruby
15 hours, 46 minutes ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/23/2026
Status: Active
Attachments: 3 files
ProRealCode ProRealCode
Loading...