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 .
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 an alert when price crosses the trailing ATR.
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.
The code is clearer but you should notice no other difference.
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.
This allows you to run the script on a different timeframe to the chart.
By default, it takes the same timeframe as the chart.
ברוח TradingView אמיתית, מחבר סקריפט זה פרסם אותו עם קוד פתוח, כך שסוחרים יוכלו להבין ולאמת זאת. הידד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום הנו בכפוף ל כללי הבית . אתה יכול להגדירו כמועדף ולהשתמש בו בגרף.
⭐️ Pro scripts: https://simplecrypto.life/pro-scripts/
📗 Articles: https://simplecrypto.life/articles/
🙋Get help with Pinescript: https://simplecrypto.life/get-help-with-pinescript/
Awesome script, I like the option to flip on wick.
There is a "but" of course :) In some situations, script stops working and plots a long horizontal line.
Settings are 11 and 1.8
here is a closer look
BTW, if you compare the stop line to other ATR scripts using identical parameters, lines wont match. Your are a lot further away. I am not sure, is your correct and the other one wrong or the other way around.
Both use 19 and 3.6
There is a formula for the range of a candle, which is just the difference between High and Low. Then a slightly more complex one for True Range, which additionally accounts for inter-day gaps that you get not so much in crypto but in stocks. So True Range you can say is calculated correctly or incorrectly. Then you apply a moving average of some kind to get Average True Range. Classically, it's a Rolling Moving Average (RMA) of 14 periods. In the latest version of my script, you can choose other moving average calculations.
Finally, there is the trailing part. Mine trails very simply and intuitively. Looking at the screenshot you posted, I would have to guess that the green line there is using a different trailing calculation. See how it trails strongly up when price is falling? It's doing some extra calculations to adapt a bit more dynamically. I might look at doing something like that in the future, but then you're moving away from just ATR and into your own proprietary ideas about how trailing stops could be set.