SimpleCryptoLife

ATR + Trailing Stops

SimpleCryptoLife Actualizado   
Simple visualisation of Average True Range in Pinescript V4.

The script has two modes: Running and Trailing.
In Running mode, it continuously displays the ATR above and below the price. Specifically, it displays the High and Low price plus and minus the ATR times a user-supplied multiplier. This can be helpful for visualising volatility.
In Trailing mode, it displays the same ATR line, except the line trails until price crosses it. When price crosses it, it flips from long to short or vice-versa.

You could use trailing ATR as a stop loss. Adjust the multiplier and lookback period for your asset and preference.
Notas de prensa:
Added consistent description.
Added an alert when price crosses the trailing ATR.
Notas de prensa:
Added better description of the settings.
Added the option to choose which moving average is used for smoothing.
Added options to weight the candle wicks vs the candle bodies in the ATR calculation. I haven't seen this anywhere else, but I think it's interesting, especially for spiky assets.
These new options are advanced and will probably not be touched by most users. If you do your own Pinescripting, though, the code for the calculation of wick ATR might be interesting. And the concept that you can apply different smoothing mechanisms is an important one for deconstructing "ATR" as a thing.
Notas de prensa:
Bug fix. Rewrote the flipping logic so that we cannot be both long and short (after the initial period where we don't have an ATR flip yet).
The code is clearer but you should notice no other difference.
Notas de prensa:
Adopted @Pinecoders pine coding conventions (definitely check those out if you are writing your own indicators).
Made all variable names unique to this script.
Replaced the trailing calculations with functions.
Removed global variables from functions.
Fixed the alert conditions to take the flip input into account.
Made the stop lines prettier.
Notas de prensa:
Made the flipping logic more robust.
Notas de prensa:
Adding the new resolution parameter to the study options as requested by Caesar.
This allows you to run the script on a different timeframe to the chart.
By default, it takes the same timeframe as the chart.
Notas de prensa:
Updated to Pinescript V5
Notas de prensa:
Replaced the single alert with two alerts: one for long and one for short.
Left the debug for these in - you can uncomment it if you want to see where an alert would have fired on historical bars.

Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?