TradingView
SimpleCryptoLife
2019년 8월 15일 오후 2시 48분

ATR + Trailing Stops 

Bitcoin / EuroCoinbase

설명

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.

릴리즈 노트

Added consistent description.
Added an alert when price crosses the trailing ATR.

릴리즈 노트

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.

릴리즈 노트

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.

릴리즈 노트

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.

릴리즈 노트

Made the flipping logic more robust.

릴리즈 노트

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.

릴리즈 노트

Updated to Pinescript V5

릴리즈 노트

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.
코멘트
rassom
Great script. Thank you so much!

One small request: Would you make it an option that the ATR lines drawn are based on Low rather than Close
SimpleCryptoLife
@rassom, Thanks very much! I'm not going to be updating this script except if there are bugs. But I am planning a new trailing ATR script with different (so, has to be a new script) and better functionality.
Actually I realised that even though your request sounds simple, I don't really understand it. The ATR kind of has to be calculated the way it is. Then the lines are plotted based on low-ATR and high+ATR. And the trigger, if set to Wick, uses Low for long stops already. So, what exactly would you be looking to change?
rassom
@SimpleCryptoLife, Ah, yes. It's already plotting it from the low. So all good 😃 Sorry! 😬😊
SimpleCryptoLife
@rassom, Phew! Thanks again
LegendaryMike
Great Indicator I am actually building an indicator very similar to this that will pretty much automate trading. I admit I hit a wall, I would love to show it to you and get some advice if you are up for it and it may give you ideas if you haven't already though of them that is.
SimpleCryptoLife
@LegendaryMike, No offence but I can't be sure you're for real ;-) Publish some scripts and then we can talk.
LegendaryMike
@SimpleCryptoLife, None taken I honestly Just learned how to code not even a week ago up until now I been trading mainly using indicators, but now I want to put together my own strategy so this is the first script I'm working on. I will update my profile and put my social medias on here to show that I'm real if that helps
SimpleCryptoLife
@LegendaryMike, Ok you sound like a real person. So quite honestly I found I just don't have time to give both free scripts and free advice (I chose scripts because I think it can help more people overall), but I do know people who do. There is a section Get Help with Pinescript in my signature just above the comments section here that has different resources in that might be useful. Best of luck.
LegendaryMike
@SimpleCryptoLife, Ok cool thank you I appreciate the help
Bart_
Whoa, thanks for taking the time to code this so neatly and well-explained!
And yes, we need more cake!
더보기