Williams Fractal Trailing Stops

SimpleCryptoLife Premium Telah dikemaskini   
Unlike the built-in version, you can configure how many bars it takes to confirm a fractal . This indicator plots all Williams high and low fractals, and a stop line that trails the fractals up and down. Includes long and short stop alerts. You can choose whether the trail flips long-short based on the price being exceeded within a candle or on candle close. This indicator deals only with fractals and doesn't get into the Alligator or anything else.
I've commented it extensively, so that it might be useful for people learning Pinescript. Enjoy!
Catatan Pelepasan: Removed a stray unnecessary input to the f_flip function.
Added comment to f_trail function to make it more portable.
Catatan Pelepasan: Fixed description of the _longTrail and _shortTrail variables.
Fixed edge cases where a wick causes us to try to flip both long and short.
Catatan Pelepasan: Small fix to display the current stop price at the level of the stop itself, not just under or above the bar.
Catatan Pelepasan: NEW FEATURE: This is a major change to how the indicator works. Previously, the Williams Range field covered the entire range. So for example, if the range was 5, it would look 2 candles before the current one and 2 ahead, for 5 in total (including the current one). The assumption was that the current candle would always be in the middle of the range.
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.
Catatan Pelepasan: Minor improvement: Suppress fractals if the previous bar was a fractal. This will take care of the edge case where you have two bars closing at the exact same price in a row (which can happen at very low timeframes). If you have many bars closing at the exact same price you will still see repeated fractals, but I think that's ok.

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.

Skrip sumber terbuka

Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.


Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.

Ingin menggunakan skrip ini pada carta?