TD Sequential (Setup and Countdown)

There are several variations on the classic TD Sequential indicator already published so why do another one would be a fair question to ask. Personally i wasn't fully satisfied with how many of them were implemented so i decided to code my own version from the ground up guided by the rules outlined in Jason Perl's: DeMark Indicators book. Thanks to /u/glaz and /u/andyhitchman for their code that helped me start in the right direction.

Some of the potential improvements were:

Properly implemented setup trend lines
- they now represent the extreme of the beginning of the setup instead of the end

Visual clarity
- arrows appear only on setup nines and countdown thirteens
- indicator features clean simple numbers that (mostly) shrink when zoomed out

Proper and mostly complete countdown recycle and cancellation rules
- countdown is completed only when bar 13 is more extreme than bar 8, until that happens a plus sign (+) appears where 13 should have been
- countdown is cancelled if a setup is completed in the opposite direction, or the price trades through the relevant setup trend line with it's whole bar
- countdown is recycled (begins anew) if the price generates a new setup in the same direction that is greater than the previous one, but less than 1.618 it's size, or if that new setup pierces through the previous setup's true range on a closing basis

- By default setup initiation requires a price flip but if you like you can disable that requirement and recycle the setup after a nine
- You can now choose to track only buy or only sell setups or disable setups entirely
- You can display only completed nines while the rest are not showing
- Turn off or on support and/or resistance lines
- Turn off or on display of buy and/or sell countdowns
- More to come...

I coded the indicator with readability in mind hoping to make correcting and improving it easier so we can make the best Sequential indicator on TV. Efficiency wasn't too big a concern. Work is in progress and I'm planning to add more features.

Please PM me or comment below all your suggestions and requests, and especially the bugs if you find some.
リリースノート: Added risk lines for the countdown part. Still not sure where to cut them off when the market goes in your favor so they can get extended really long, will fix.

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.