Smaller Timeframe drawline/rectangle issues

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #75715 quote
    kastin
    Participant
    New

    Hello, i have a piece of code that i have assembled/Frankensteined, it works well on hourly and above, but when i swap down to lower timeframes something odd happens,

    the problem is with the drawing the lines and rectangle, when i move to a smaller timeframe they either dont draw, or the vertical axis is way out?

    I apologize for the messy code, i am no professional

    defparam drawonlastbaronly=true
     
    ATRperiod = 20
    
     
    dTR = 0
    for i = 0 to ATRperiod
    dTR=dTR+max(abs(Dhigh(i)-Dlow(i)),max(abs(Dhigh(i)-Dclose(i+1)),abs(Dlow(i)-Dclose(i+1))))
    next
     
    avg = dTR/ATRperiod
    converted = round(avg/pointsize*10)/10
    
    //TimeRange = ( Time < 130100 AND Time > 135959 )
    IF time = 150000 THEN
    
    begin=BarIndex
    daysopen = close
    
    else
    //backwards = barindex-begin
    //daysopen = close[backwards]
    ENDIF
    
    //bindex = IntradayBarIndex
    bindex = BarIndex
    IF bindex-begin < 1 THEN
    Ddhigh = highest[1](high)
    Ddlow = lowest[1](low)
    daysopen = close[1]
    ELSE
    bsince = (bindex-(begin))
    Ddhigh = highest[bsince](high)
    Ddlow = lowest[bsince](low)
    daysopen = close[bsince]
    ENDIF
    
    //Ddhigh = highest[bsince](high)
    
    htr = Ddlow+avg[1]
    ltr = Ddhigh-avg[1]
    
    bhtr = daysopen+(.3*avg[1])
    bltr = daysopen-(.3*avg[1])
    
    
    //just for calculation of text
    bounce = (.3*avg[1])
    
    
    drawsegment(begin,htr,bindex,htr) coloured(200,100,0)
    drawtext("#htr# - (D1atr: #converted#)",bindex,htr+10*pointsize,Dialog,Bold,10) coloured(200,100,0)
    drawsegment(begin,ltr,bindex,ltr) coloured(200,100,0)
    drawtext("#ltr# - (D1atr: #converted#)",bindex,ltr-10*pointsize,Dialog,Bold,10) coloured(200,100,0)
     
    
    
    drawsegment(begin,bhtr,bindex,bhtr) coloured(255,255,0)
    drawtext("#bhtr# - (Short openers area: #bounce#)",bindex,bhtr+10*pointsize,Dialog,Bold,15) coloured(200,200,0)
    
    
    // DRAWRECTANGLE (x1, y1, x2, y2) COLOURED (R, V, B, a)
    DRAWRECTANGLE (begin, daysopen+bounce, bindex, daysopen) coloured(150,150,150)
    //just to see if BLTR had anumber on smaller tf drawtext("#bltr# - (Long openers area: -#bounce#)",bindex,ddhigh-10*pointsize,Dialog,Bold,15) coloured(200,200,0)
    
    drawsegment(begin,bltr,bindex,bltr) coloured(255,255,0)
    drawtext("#bltr# - (Long openers area: -#bounce#)",bindex,bltr-10*pointsize,Dialog,Bold,15) coloured(200,200,0)
    
    drawsegment(begin,daysopen,bindex,daysopen) coloured(0,0,255)
    
    drawsegment(begin,ddhigh,bindex,ddhigh) coloured(0,50,0)
    drawsegment(begin,ddlow,bindex,ddlow) coloured(0,50,0)
    
    return
    #75721 quote
    Nicolas
    Keymaster
    Master

    Because Y coordinates are in price format, you have to adapt them (automatically?) in order to get them properly displayed right where you want them to be (close to these lines I guess).

    #75724 quote
    kastin
    Participant
    New

    Hi,

    Thanks for your quick reply, can you elaborate a bit i thought they were in price? or know of any example code i can decipher?

    #75728 quote
    Nicolas
    Keymaster
    Master

    In this line you are adding text 10 points away from the “bltr” line:

    drawtext("#bltr# - (Long openers area: -#bounce#)",bindex,bltr-10*pointsize,Dialog,Bold,15) coloured(200,200,0)

    While it is close to the line on a larger timeframe, it could be far away on a very small one (or if you zoom in on the chart).

    A rough solution could be to adapt this spread automatically with an indicator value in points, like the ATR for instance:

    atr=averagetruerange[14]
    drawtext("#bltr# - (Long openers area: -#bounce#)",bindex,bltr-atr/2,Dialog,Bold,15) coloured(200,200,0)
    #75732 quote
    kastin
    Participant
    New

    Ok i see what you mean,

    but all that did was change the text position on the hourly, it had no effect on smaller timeframes,

    i think the problem lies with not calculating the “daysopen” (the open price at 1600 which is pretty close to close price at 1500) on smaller timeframes.

    How would you normally draw a rectangle that starts at a specific time, then +/- percentage of price?

    #75741 quote
    Nicolas
    Keymaster
    Master

    Since you are calculating daily ATR of 20 periods, sufficient bars units are also necessary to compute it correctly. For example, in a 1 minute timeframe, at least 28.800 bars are needed.

    #75746 quote
    kastin
    Participant
    New

    Ahhh now we are onto it, that seems to work thanks!,

    i don’t suppose there is an easy way to get past this? rather than loading 10000 bars in a smaller timeframe?

    it seems amibroker AFL is much easier to code with,

    #75747 quote
    Nicolas
    Keymaster
    Master

    That’s how it goes since we don’t have any multi timeframe capabilities with ProBuilder. To get higher timeframes OHLC, we must load sufficient data in the current timeframe.

    #75749 quote
    kastin
    Participant
    New

    Thankyou for your help 🙂

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

Smaller Timeframe drawline/rectangle issues


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
kastin @kastin Participant
Summary

This topic contains 8 replies,
has 2 voices, and was last updated by kastin
7 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/10/2018
Status: Active
Attachments: 2 files
Logo Logo
Loading...