I want to code a indicator that counts x number of occurrences of a given pattern. I don't want this to be based on num bars but by the last X number of patterns, with pattern #X rolling off upon the trigger of a new pattern.
For example:
I want to count the last 15 instances where (c crosses over Bollinger Band Upper (+1)OR c crosses under Bollinger Band Lower (-1)) and where number of bars back is not a criteria. My goal is to sum the instances.
How do I code this rolling counter?
Thank you,
masber2000
Can you help answer these questions from other members on futures io?
Normally Houston TX but currently travelling a lot
Experience: Advanced
Platform: TT and Stellar
Broker: Primary Advantage Futures. Also ED&F and Tradestation
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Posts: 4,747 since Dec 2013
Thanks: 4,063 given,
9,563
received
Create indicator that has your +1,0,-1 value. Create an array of length 15. Track which element of the array you need to update next. When indicator != 0 update array. Sum of the array is the answer you want.
Create indicator that has your +1,0,-1 value. Write a loop that looks backwards until it finds 15 indicator values != 0. Keep a running total as this is the answer you want.