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
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 🙂
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……?
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
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
Si, però devi verificare:
- che MESE+1 non superi 12, se lo supera devi ripartire dal mese 1 ed incrementare l’anno
- 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 🙂