Problems using drawonlastbaronly parameter

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #221018 quote
    micky_red
    Participant
    New

    Hello, this code draws two things. On the one hand, a vertical line at 8 in the morning. And on the other hand, a line with the maximum value of the price the previous day, said line has a text that has to be displayed on the right side of the graph.
    The problem I have is that the text I put on the line, which says “Maximum PD”, so that it appears at the end of the line (to the far right), I must activate “defparam drawonlastbaronly=true”, and when I do That’s it, the vertical bar disappears.
    I have tried disabling “defparam drawonlastbaronly=true” but then the text does not appear correctly.

    How can I get both things to appear correctly? Can you help me?

    Note: For me it is important that the text always appears on the right side, since by testing, I managed to put it on the left, but that solution does not work for me.

    Thank you.

    // defparam drawonlastbaronly=true
    
    if time = 080100 then
    drawvline(barindex) coloured(0,153,255,255)
    endif
    
    if IntradayBarIndex=0 then
    // Maximum price of the previous day
    initialbar = BarIndex
    mpd=DHigh(1)
    ENDIF 
    
    locationtext = mpd +6
    DRAWTEXT ("Maximum PD", BarIndex ,locationtext)  COLOURED(192,192,192)
    DrawSegment(initialbar,mpd,BarIndex,mpd) COLOURED(192,192,192) style(Line,2)
    
    RETURN
    #221022 quote
    Nicolas
    Keymaster
    Master

    Yes because 080100 bar is in the past, and not the current BARINDEX anymore, and that’s what you want draw on last barindex only.

    So the workaround is to store the number of the 08:01:00 barindex and plot it in the past:

    defparam drawonlastbaronly=true
    
    if time = 080100 then
    mybar=barindex
    endif
    
    if IntradayBarIndex=0 then
    // Maximum price of the previous day
    initialbar = BarIndex
    mpd=DHigh(1)
    ENDIF
    
    locationtext = mpd +6
    DRAWTEXT ("Maximum PD", BarIndex ,locationtext)  COLOURED(192,192,192)
    DrawSegment(initialbar,mpd,BarIndex,mpd) COLOURED(192,192,192) style(Line,2)
    
    drawvline(mybar) coloured(0,153,255,255)
    
    RETURN
    #221065 quote
    micky_red
    Participant
    New

    Thanks for the response, but it doesn’t solve the problem.

    With the code you suggested, I only see the elements drawn in the last session and that is not what I want. What I want is for the different elements to be seen correctly for each session, that is, for them to be drawn every day.

    I take a couple of screenshots, one with the parameter activated and another deactivated.

    How could we fix it, so that all elements look correct every day?

    Thanks for your help.

    #221085 quote
    Nicolas
    Keymaster
    Master

    With the code you suggested, I only see the elements drawn in the last session and that is not what I want. What I want is for the different elements to be seen correctly for each session, that is, for them to be drawn every day.

    I have fixed the code you provided, to be shown correctly on the current day. You did not asked it to be plot over all history 🙂

    But anyway, if you don’t want objects to be drawn continuously on each single bar, then you have to plot them only one time and from the current bar only. So in order to do that, we have to store all coordinates of all objects of history, and that’s easy with an array:

    The below version should make you happy, I hope so! 😉

    defparam drawonlastbaronly=true //we will draw only from the current bar, but in the past 
    
    if IntradayBarIndex=0 then
    aa=aa+1
    // Maximum price of the previous day
    $initialbar[aa] = BarIndex
    $mpd[aa]=DHigh(1)
    ENDIF
    
    if time = 080100 then
    $mybar[aa]=barindex
    endif
    
    if islastbarupdate then 
    for i = aa downto 1 do 
    locationtext = $mpd[i] +6*pointsize 
    DRAWTEXT ("Maximum PD", $initialbar[i] ,locationtext)  COLOURED(192,192,192)
    if i = aa then
    DrawSegment($initialbar[i],$mpd[i],barindex,$mpd[i]) COLOURED(192,192,192) style(Line,2)
    else
    DrawSegment($initialbar[i],$mpd[i],$initialbar[i+1],$mpd[i]) COLOURED(192,192,192) style(Line,2)
    endif 
    
    drawvline($mybar[i]) coloured(0,153,255,255)
    next
    endif 
    
    RETURN
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Problems using drawonlastbaronly parameter


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
micky_red @micky_red Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Nicolas
2 years, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/14/2023
Status: Active
Attachments: 3 files
Logo Logo
Loading...