Draw Monthly Segment

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #233609 quote
    abel1986
    Participant
    New

    Hello, I would like to modify the following indicator to draw the segment exactly till the end of each month, and not limiting it to the current barindex.
    Any idea?
    many thanks in advance

    Ciao, vorrei modificare il seguente indicatore per disegnare il segmento esattamente fino alla fine di ogni mese e non limitarlo al barindex corrente.
    Qualche idea?
    Molte grazie in anticipo

    defparam drawonlastbaronly = true
    once lastmonthBarIndex = 0

    if barindex>0 then
    If month<>month[1] then
    hi=high
    lo=low
    lastmonthBarIndex = BarIndex
    Endif
    endif

    hi = max(hi,high)
    lo = min(lo,low)

    DRAWSEGMENT(lastMonthBarIndex,hi,barindex,hi )
    DRAWSEGMENT(lastMonthBarIndex,lo,barindex,lo )

    return

    #233659 quote
    robertogozzi
    Moderator
    Master

    Eccolo:

    defparam drawonlastbaronly = true
    once lastmonthBarIndex = 0
    
    if barindex>0 then
       If month<>month[1] then
          hi=high
          lo=low
          lastmonthBarIndex = BarIndex
       Endif
    endif
    
    hi = max(hi,high)
    lo = min(lo,low)
    
    // Predisporre la data di fine mese corrente
    Anno     = OpenYear  * 10000
    Mese     = OpenMonth
    // determinare l'ultimo giorno del mese
    Giorni   = 31
    IF (Mese = 4) OR (Mese = 6) OR (Mese = 9) OR (Mese = 11) THEN
       Giorni = 30
    ELSIF (Mese = 2) THEN
       Giorni = 28
       // verificare quando Febbraio è bisestile
       IF OpenYear MOD 4 = 0 THEN
          IF OpenYear MOD 100 = 0 THEN
             IF OpenYear MOD 400 = 0 THEN
                Giorni = 29
             ENDIF
          ELSE
             Giorni = 29
          ENDIF
       ENDIF
    ENDIF
    FineMese = Anno + (Mese * 100) + Giorni
    
    // usare la data calcolate con DATETOBARINDEX per stampare fino all'ultimo giorno
    DRAWSEGMENT(lastMonthBarIndex,hi,DateToBarindex(FineMese),hi)
    DRAWSEGMENT(lastMonthBarIndex,lo,DateToBarindex(FineMese),lo)
    
    return

    Pubblica solo nella lingua del forum in cui stai postando. Ad esempio solo l’inglese nei forum di lingua inglese e il francese solo nei forum di lingua francese. Grazie 🙂

    abel1986 thanked this post
    #233663 quote
    abel1986
    Participant
    New

    Grande Roberto, grazie mille, funziona perfettamente!
    Se volessi invece applicarlo anche ai trimestri 0 semplicemente all’anno? Purtroppo non riesco ad adattare il codice, abbi pazienza 🙂

    TRIMESTRE:
    if barindex>0 then
    If month<>month[1] then
    if month=4 or month=7 or month=10 or month= 1 then
    hi=high
    lo=low
    lastQuarterBarIndex = BarIndex
    Endif
    endif
    endif…..?

    grazie ancora, gentilissimo

    ANNO:
    if barindex>0 then
    If year<>year[1] then
    hi=high
    lo=low
    lastYearBarIndex = BarIndex
    Endif
    endif……?

    #233674 quote
    robertogozzi
    Moderator
    Master

    Questo è quello Trimestrale (il trimestre inizia quando il MESE diviso per 3 da come resto 1):

    defparam drawonlastbaronly = true
    once LastTrimBarIndex = 0
    
    if barindex>0 then
    If (OpenMonth<>OpenMonth[1]) AND ((OpenMonth MOD 3) = 1) then
    hi=high
    lo=low
    LastTrimBarIndex = BarIndex
    // Predisporre la data di fine mese corrente
    Anno   = OpenYear  * 10000
    Mese   = OpenMonth
    Giorni = 31
    IF (Mese = 1) THEN
    Mese   = 3
    ELSIF (Mese = 10) THEN
    Mese   = 12
    ELSIF (Mese = 7) THEN
    Mese   = 9
    Giorni = 30
    ELSIF (Mese = 4) THEN
    Mese   = 6
    Giorni = 30
    ENDIF
    // determinare l'ultimo giorno dell'ultimo mese del trimestre
    FineMese = Anno + (Mese * 100) + Giorni
    Endif
    endif
    
    hi = max(hi,high)
    lo = min(lo,low)
    
    // usare la data calcolate con DATETOBARINDEX per stampare fino all'ultimo giorno
    DRAWSEGMENT(LastTrimBarIndex,hi,DateToBarindex(FineMese),hi)
    DRAWSEGMENT(LastTrimBarIndex,lo,DateToBarindex(FineMese),lo)
    
    return

    e questo è quello ANNUALE:

    defparam drawonlastbaronly = true
    once LastBarIndex = 0
    
    if barindex>0 then
    If (OpenYear<>OpenYear[1]) THEN
    hi=high
    lo=low
    LastBarIndex = BarIndex
    Anno   = OpenYear
    // determinare l'ultimo giorno dell'ultimo mese del trimestre
    FineMese = (Anno * 10000) + 1231
    Endif
    endif
    
    hi = max(hi,high)
    lo = min(lo,low)
    
    // usare la data calcolate con DATETOBARINDEX per stampare fino all'ultimo giorno
    DRAWSEGMENT(LastBarIndex,hi,DateToBarindex(FineMese),hi)
    DRAWSEGMENT(LastBarIndex,lo,DateToBarindex(FineMese),lo)
    
    return
    abel1986 thanked this post
    #233682 quote
    abel1986
    Participant
    New

    Grazie ancora Roberto!

    #233765 quote
    abel1986
    Participant
    New

    Roberto, ultima domanda: impostare una data di inizio prossimo mese e fine prossimo mese e disegnarci poi il segmento rimane comunque possibile?
    Questo codice mi da errore:

    InPrMe = Anno + ((Mese+1) * 100) + 1
    FiPrMe = Anno + ((Mese+1) * 100) + Giorni

    Grazie di nuovo

    #233799 quote
    robertogozzi
    Moderator
    Master

    Si, però devi verificare:

    1. che MESE+1 non superi 12, se lo supera devi ripartire dal mese 1 ed incrementare l’anno
    2. che la formula con +GIORNI non ecceda la fine del mese, altrimenti devi incrementare il MESE (in tal caso vedi quanto detto al punto precedente)  e calcolare qual’è il GIORNO del nuovo mese.

    Le operazioni sulle date sono un pò lunghe e macchinose, si sbaglia facilmente 🙂

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

Draw Monthly Segment


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
abel1986 @abel1986 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by robertogozzi
1 year, 9 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 06/07/2024
Status: Active
Attachments: No files
Logo Logo
Loading...