I've commented it extensively, so that it might be useful for people learning Pinescript. Enjoy!
Added comment to f_trail function to make it more portable.
Fixed edge cases where a wick causes us to try to flip both long and short.
Now, you can specify different periods to look back and forwards. To replicate the old behaviour, just make sure the values are the same.
Why would you choose different values? It depends on what you want to achieve.
For example, maybe you want faster confirmation of a fractal, in which case you could lower the forward range.
If you wanted to find a point of interest within a fairly consistent trend that ends in a consolidation, you might lower the backwards period but keep a reasonably long forward period.
Other minor changes: Updated inputs for new group and tooltip options. The descriptions of the settings are no longer in the script comments but in the tooltips for each setting.
Rewrote the function for testing for fractals and fixed a bug where it was confirming a fractal incorrectly.
NOTE: The last major change, to allow different lookback and look-forward values, somehow fixed an unnoticed issue where the old version was not always confirming the correct fractals. Now it works as intended. You can add on the standard TradingView Williams Fractals indicator and compare. For example, 2 forward and 2 backward on this version is equivalent to a range of 2 on the TradingView built-in indicator. You should see the same fractals confirmed.
⭐️ Pro scripts: https://simplecrypto.life/pro-scripts/
📗 Articles: https://simplecrypto.life/articles/
🙋Get help with Pinescript: https://simplecrypto.life/get-help-with-pinescript/
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.