Überlappende DrawText und DrawSegment in der Historie vermeiden.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #259719 quote
    RAM24
    Participant
    Junior

    Hallo zusammen,

    ich entwickle einen RBO-Indikator und habe zwei spezifische Probleme mit der Darstellung:

    1. DrawSegment: Ich möchte, dass die Projektionslinien (Segmente) nur in der aktuellen Live-Sitzung gezeichnet werden. In den Boxen der Vergangenheit sollen diese Segmente automatisch verschwinden, um den Chart sauber zu halten.
    2. DrawText (Overprinting): Mein aktueller Code schreibt die Labels (High/Low/Ps) bei jeder neuen Kerze neu. Das führt in der Historie zu “Farbflecken” (Overprinting), da hunderte Texte übereinander liegen und unleserlich werden.

    Ziel: Die Labels sollen nur einmalig pro Box gezeichnet werden (z.B. beim Abschluss der Range) und die Segmente sollen nur für die heutige Sitzung sichtbar sein.

    Wie kann ich den Code effizient filtern, damit PRT nicht bei jedem Tick die gesamte Historie neu “beschreibt”?

    Vielen Dank für eure Tipps!

    Hier ist mein aktueller Code:

    //================================================================
    // RBO
    //================================================================
    
    once NbBar = 1
    if BarIndex < NbBar + 2 then
    MyDay = openday
    dayminutes = 1440 * (MyDay - MyDay[1])
    MyHour = openhour
    hourminutes = 60 * (MyHour - MyHour[1])
    MyMin = openminute
    barminutes = abs(MyMin - MyMin[1] + hourminutes + dayminutes)
    Mybarminutes = lowest[NbBar](barminutes)[1]
    endif
    
    tfOK = 1
    if Mybarminutes = 1 then
    Frame = 480
    EndtimeA = 080100
    elsif Mybarminutes = 5 then
    Frame = 96
    EndtimeA = 080500
    elsif Mybarminutes = 10 then
    Frame = 48
    EndtimeA = 081000
    elsif Mybarminutes = 15 then
    Frame = 32
    EndtimeA = 081500
    elsif Mybarminutes = 30 then
    Frame = 16
    EndtimeA = 083000
    else
    Frame = 1
    EndtimeA = 080000
    tfOK = 0
    endif
    
    // [B2]
    once lastMax = 0
    once lastMin = 0
    once lastMid = 0
    once lastEnd = 0
    once lastPips = 0
    
    // [B3]
    if tfOK = 1 and time = EndtimeA then
    lastMax = highest[max(1, Frame)](high)
    lastMin = lowest[max(1, Frame)](low)
    lastMid = lastMin + (lastMax - lastMin) / 2
    lastEnd = barindex
    lastPips = (lastMax - lastMin) / pointsize
    
    DrawRectangle(barindex - Frame, lastMax, barindex, lastMin) coloured("firebrick", 20) bordercolor("firebrick", 100)
    DrawText("#lastPips#", barindex - round(0.5 * Frame), lastMid, SansSerif, Bold, 16) coloured("firebrick", 150)
    endif
    
    // [B4]
    if tfOK = 1 and date = today and lastMax > 0 then
    //
    DrawRectangle(lastEnd - Frame, lastMax, lastEnd, lastMin) coloured("firebrick", Transparency) bordercolor("firebrick", 255)
    if islastbarupdate then
    centerX = lastEnd - round(0.5 * Frame)
    offset = AverageTrueRange[14](close) * 0.5
    DrawText("RBO ", centerX, lastMax + offset * 3, SansSerif, Bold, 12) coloured("firebrick", 255)
    DrawText("H: #lastMax#", centerX, lastMax + offset, SansSerif, Bold, 10) coloured("firebrick", 255)
    DrawText("L: #lastMin#", centerX, lastMin - offset, SansSerif, Bold, 10) coloured("firebrick", 255)
    endif
    
    //
    if barindex >= lastEnd and time = 150000 then
    DrawSegment(lastEnd, lastMax, barindex, lastMax) coloured("firebrick", 255)
    DrawSegment(lastEnd, lastMin, barindex, lastMin) coloured("firebrick", 255)
    DrawSegment(lastEnd, lastMid, barindex, lastMid) style(dottedline3) coloured("firebrick", 180)
    endif
    endif
    
    return
    
    RangeA.itf
    #259720 quote
    Iván González
    Moderator
    Master

    Ich habe Ihren Code umstrukturiert, um beide Probleme zu beheben. Die Ursache liegt darin, dass ProRealTime beim Laden des Diagramms alles auf jedem Balken neu zeichnet, wodurch sich DrawText , DrawRectangle und DrawSegment im Verlauf ansammeln.

    1. defparam drawonlastbaronly = true — Löscht alle Zeichenobjekte bei jedem Tick und zeichnet sie neu.

    2. Speichere die Boxdaten in Arrays, wenn jeder Bereich erkannt wird (bei jedem Balken, außerhalb islastbarupdate ).

    3. Alles innerhalb von islastbarupdate neu zeichnen – historische Felder aus gespeicherten Daten, aktuelles Feld mit Beschriftungen und Projektionen


    defparam drawonlastbaronly = true
    Transparency = 100
    maxBoxes = 50  // Max historical boxes to display
    
    // === TIMEFRAME DETECTION (unchanged) ===
    once NbBar = 1
    if BarIndex  0 THEN
       myOffset = AverageTrueRange[14](close) * 0.5
       
       // --- Historical boxes (subtle) ---
       startIdx = max(0, boxCnt - maxBoxes)
       FOR i = startIdx TO boxCnt - 2 DO
          bx = $bEnd[i]
          fr = $bFrame[i]
          mx = $bMax[i]
          mini = $bMin[i]
          pp = $bPips[i]
          cx = bx - round(0.5 * fr)
          md = mini + (mx - mini) / 2
          
          DrawRectangle(bx - fr, mx, bx, mini) coloured("firebrick", 20) bordercolor("firebrick", 100)
          DrawText("#pp#", cx, md, SansSerif, Bold, 16) coloured("firebrick", 150)
       NEXT
       
       // --- Latest box (highlighted + labels + projections) ---
       DrawRectangle(lastEnd - Frame, lastMax, lastEnd, lastMin) coloured("firebrick", Transparency) bordercolor("firebrick", 255)
       
       centerX = lastEnd - round(0.5 * Frame)
       DrawText("RBO", centerX, lastMax + myOffset * 3, SansSerif, Bold, 12) coloured("firebrick", 255)
       DrawText("H: #lastMax#", centerX, lastMax + myOffset, SansSerif, Bold, 10) coloured("firebrick", 255)
       DrawText("L: #lastMin#", centerX, lastMin - myOffset, SansSerif, Bold, 10) coloured("firebrick", 255)
       DrawText("#lastPips#", centerX, lastMid, SansSerif, Bold, 16) coloured("firebrick", 255)
       
       // Projection lines (only from latest box to current bar)
       DrawSegment(lastEnd, lastMax, barindex, lastMax) coloured("firebrick", 255)
       DrawSegment(lastEnd, lastMin, barindex, lastMin) coloured("firebrick", 255)
       DrawSegment(lastEnd, lastMid, barindex, lastMid) style(dottedline3) coloured("firebrick", 180)
    ENDIF
    
    RETURN
    


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

Überlappende DrawText und DrawSegment in der Historie vermeiden.


ProBuilder: Indikatoren & Custom Tools

New Reply
Author
author-avatar
RAM24 @ram24 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
15 hours, 42 minutes ago.

Topic Details
Forum: ProBuilder: Indikatoren & Custom Tools
Language: German
Started: 03/31/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...