Zigzag Code does not update automatically

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #216565 quote
    GustavoL.O
    Participant
    New

    Hello,

    I need to fix a problem I have with this code. The cumulative Histogram does not update the zigzag, to update I have to reset the indicator on the Intraday chart.

    Thank you very much, waiting for an answer.

     

    //PRC_CumulativeVolume ZigZag | indicator

    // — parameters
    percentVariation = 0.04

    zz = ZigZag[percentVariation](close)

    peak = zz<zz[1] and zz[1]>zz[2]
    tough = zz>zz[1] and zz[1]<zz[2]

    cumV = cumV+volume

    if peak then
    text = cumV/1000
    //drawtext(“#text#K”,barindex[1],cumV[1]+0.17*cumV[1],Dialog,Bold,12) coloured(0,200,0)
    //drawsegment(barindex[1],cumV[1]+0.20*cumV[1],previousX,previousY)
    cumV = Volume
    color = -1
    previousX = barindex[1]
    previousY = cumV[1]+0.20*cumV[1]
    elsif tough then
    text = cumV/1000
    //drawtext(“#text#K”,barindex[1],cumV[1]+0.23*cumV[1],Dialog,Bold,12) coloured(200,0,0)
    //drawsegment(barindex[1],cumV[1]+0.20*cumV[1],previousX,previousY)
    cumV = Volume
    color = 1
    previousX = barindex[1]
    previousY = cumV[1]+0.20*cumV[1]
    endif

    return cumV coloured by color

    #216577 quote
    robertogozzi
    Moderator
    Master

    Try increasing the units on the graph, 1000 or more.

    #216626 quote
    GustavoL.O
    Participant
    New

    Thanks! But it’s already at 10k. Zigzag does not update, it continues with a normal histogram, but when I apply the indicator again in modify indicator yes, then it resumes the correct zig zag calculation

    #216631 quote
    robertogozzi
    Moderator
    Master

    Sorry, I can’t figure out why.

    GustavoL.O thanked this post
    #216649 quote
    Nicolas
    Keymaster
    Master

    Because the zigzag is repainting, you want the indicator calculated upon it to recalculate the past datas also. With that code, it is not possible, that would need a complete rewrite of it.

    GustavoL.O thanked this post
    #216655 quote
    GustavoL.O
    Participant
    New

    Hi Nicolas, thanks for the reply. (I guess the code is not strange for you right = ) ..) By the way, your indicators are great, they are amazing, thanks for sharing.
    The code works very well, I like it a lot, it’s very useful for me. Only that, on intraday I often (not always) have to enter “Modify indicator” and click on “Apply to…” so that the indicator “updates” the calculation. This often plots a different current histogram than it was…

    What is the path, what should I do, how would this rewrite be possible?

    best regards,
    Gustavo

    #216657 quote
    GustavoL.O
    Participant
    New

    Here are two examples, in the second screenshot after I entered Modify Incadtor and clicked Apply to… the indicator plotted the corrected cumulative histogram

    #216771 quote
    Nicolas
    Keymaster
    Master

    Ok, so the below version will plot all the volumes accumulation from any top or bottom of the zigzag variation of “percentVariation”, from the current candle in the past of the chart, so it will repaint the whole indicator on each tick and therefore no need to reload it from time to time.

    I introduced a setting “BarsLimit” to fix how many volumes bars to be plotted in the past.

    //PRC_CumulativeVolume ZigZag | indicator
    
    defparam drawonlastbaronly=true
    
    // — parameters
    percentVariation = 0.04
    BarsLimit = 200 //how many historgram to draw?
    // -----
    
    zz = ZigZag[percentVariation](close)
    
    peak = zz<zz[1] and zz[1]>zz[2]
    tough = zz>zz[1] and zz[1]<zz[2]
    
    cumV = cumV+volume
    
    $barvol[barindex]=cumv //store in an array the current volume for that bar 
    $barcolor[barindex]=color //color of current trend 
    
    if peak then
    cumV = Volume
    color = -1
    elsif tough then
    cumV = Volume
    color = 1
    endif
    
    if islastbarupdate then 
    a = 0 
    for i = barindex downto barindex-barslimit do 
    r=255
    g=0
    if $barcolor[i]>0 then 
    r=0
    g=155
    endif 
    drawrectangle(barindex[a],$barvol[i],barindex[a],0) coloured(r,g,0)
    a=a+1
    next
    endif 
    
    return cumV coloured(0,0,0,0)
    #216779 quote
    Nicolas
    Keymaster
    Master

    For reference, just added the indicator into the library: Cumulative Volume ZigZag (live version)

    GustavoL.O thanked this post
    #218173 quote
    GustavoL.O
    Participant
    New

    Hello Nicolas,

    thank you very much!!! I will test this! Tks!

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

Zigzag Code does not update automatically


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by GustavoL.O
2 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/21/2023
Status: Active
Attachments: 4 files
Logo Logo
Loading...