The medium stripe increases in length as the count to 13 starts (each time a bar closes below the low 2 bars ago the counter is incremented).
When the count reaches 13 the signal is printed (thickest stripe).
For simplicity I've zeroed all the counts once the signal prints, strictly speaking the count may continue higher before the low or high is reached. I've also arbitrarily added a rule that if the signal hasn't printed 40 bars from the setup the whole thing should abort. The chart looks cleaner that way.
This is the first script I've written in Pine; I know it could be improved, this was a quick attempt at getting something working.