Hi Nicolas, I have a simple query. for example: For i=0 to 10 do how do I write a code that adds up bars with close>open only (i.e. adds up green bars only)? regards, Walid
If you want to use FOR…NEXT you may write:
BullCount = 0
FOR i = 0 TO 10 DO
IF close[i] > open[i] THEN
BullCount = BullCount + 1
ENDIF
NEXT
but there is a more elegant, fast and efficient way:
BullCount = summation[11](close > open)
Roberto
Hi Roberto,
Thank you for your reply. Perhaps I was not clear enough in my query.
BullCount = summation [11](close > open) will return the number of bars that meet the condition close > open in the last 11 bars. Let’s say for example it returned BullCount = 5 (i.e. there were 5 bars with close > open)
What I am after is how I would then add the closes of these 5 bars together?
Walid
BullSum = summation[11](close (close > open)) //sum of CLOSing price of last BULLish bars
BullSum = summation[11](range * (close > open)) //sum of RANGE of last BULLish bars
This example multiplies CLOSE by the logical/boolean value 0 (when the condition is false) or 1 (when true), so if there are 5 bullish bars their CLOSing price will be summed up.
To adapt this to BEARish bars you just need to change the condition to “close < open”.