Dear Comunity,
I created an indicator that takes “1” if a certain level is reached and “0” if not. Over a number of available bars (e.g. 100) it will show a number of “1” (e.g. 43). What I like to do do is to count this number of “1”.
Therfore I tried this and some modifications of it, where “indicator” is my indicator that takes 1 or 0.
count = 0
FOR i = 0 TO 99
IF (BarIndex - 1 - i) >= 0 THEN
IF indicator[BarIndex - 1 - i] = 1 THEN
count = count + 1
ENDIF
ENDIF
NEXT
Problem is, that it counts all the 1 over 100 bars but starting from the first available bar, that is the oldest (2015 or so) but I need the youngest.
Can someone solve the problem?
Thanks a lot!
defparam drawonlastbaronly = true
level = 19500
LB = 100 // lookback
if close >= level then
count = 1
else
count=0
endif
countLB = summation[LB](count)
if islastbarupdate then
drawVline(barindex[LB-1])coloured("violet",100)style(dottedline,1)
endif
return count coloured("red") as"count", countLB coloured("lime")style(dottedline,1) as"countLB"
Thanks a lot druby!
Almost perfect. But the summation function seems to count up and down. But I need the accumulated sum: 1+0+0+1+1+1 = 4 an only increasing line?
Die vertikale Linie stellt den Anfang der letzten 100 Balken dar.
Wenn ein Balken endet, wird eine Variable historisiert und der nächste Balken beginnt neu.
Auf vorherige Werte einer Variablen wird mit [n] zugegriffen.
‘SUMMATION’ verwendet die letzten [100] Balken von (COUNT) und summiert alle vorherigen Werte aus den 100 Balken.
ZÄHLB = [100]+[99]+[98]+…. [2]+[1].
Da die gespeicherten Werte in COUNT[n] entweder 1 oder 0 sind, werden diese summiert.
‘ZÄHLB’ = 1+0+1+…+0+1.
Im Bild ist die grüne 58 der summierte Wert von “1” aus den letzten 100 Balken.
Das 100-Balken-Fenster bewegt sich mit jedem neuen Balken.
Wenn eine neue Stange hinzugefügt wird, fällt eine vom anderen Ende ab.
Wenn sowohl neu als auch alt identisch sind, ändert sich die Anzahl nicht.
Wenn beide unterschiedlich sind, wird die Zählung nach oben oder unten gehen, je nachdem, ob eine “1” gewonnen oder verloren wird.
Die rote Linie stellt die 1 oder 0 jedes Balkens dar, die durch die Bedingung IF/ELSE? ENDIF-Anweisung.
Wenn Sie etwas anderes in meinem hatten, folge ich nicht.
Ja du hast recht, es ist genau richtig. Habe von Hand nachgezählt. Ich war nur total verwirrt vom auf-und-ab.
Vielen Dank für deine sehr schnelle Hilfe! 🙂