mortdiggiddy

Adaptive ATR-ADX Trend V2

// Constructs the trailing ATR stop above or below the price, and switches
// directions when the source price breaks the ATR stop. Uses the Average
// Directional Index ( ADX ) to switch between ATR multipliers. The higher
// multiplier is used when the ADX is rising, and the lower ATR multiplier
// is used with the ADX is falling. This ADX criteria further widens the gap
// between the source price and the trailing ATR stop when the price is trending,
// and lessens the gap between the ATR and the price when then price is not
// trending.
//
// The ATR-ADX stop is effectively a double adapative stop that trails the price,
// by both adapting to the true range of the price, and the average directional
// change. When the stop is below the price (long trade) the value never decreases
// until the price intersects the stop, and it reverses to being above the price
// (short trade). When the stop is above the price it will never increase until
// it is intersected by the price. As the true range and ADX change, the stop
// will move more quickly or more slowly.
//
// Version 2 adds four additional utilities.
//
// First, if the 'Above Threshold' box is checked,the falling (smaller) multiplier
// will be used regardless once the ADX rises above a certain threshold (default > 30).
// The ATR will effectively rise faster once the price enters 'very trendy' mode.
// Typically, ADX > 20/25 is used in classic ADX trading (which I have found
// unprofitable through backtesting). The idea behind this extra multiplier criteria
// is that once the price starts trending 'very' well, a top/bottom is likely near,
// and when that top comes the price will quickly rebound. Experienced traders know
// exactly what I am describing. Play around with an ADX /DI indicator using this
// stop system in tandem and it will be found that many successful trades are entered
// when the market is not trending (i.e. < ADX < 25), and exited once/if the price
// enters 'very trendy' mode above 30 and the ATR changes (stopped out).
//
// Second, heiken-ashi bars can be introduced to the ATR stop system. This is the same
// thing as just switching the chart to Heiken Ashi mode, but without having to change
// the plotting type. I find this useful, so that things like pivot lines can be
// preserved to their correct calculations, while the benefit of heiken ashi bars can
// still be enjoyed. Be advised that with each tinkering that extends the life of the
// ATR trend, the odds of that same trend changing near the top/bottom are reduced,
// so as always there is a trade-off to maximize the time spend in a trade and nailing
// a top or bottom.
//
// Third, Different source prices can be used. I have found that HLC3 is best because
// it keeps the price from being stopped out in very key areas, set as the default.
//
// Fourth, alert conditions are introduced so that the trader can be warned when the
// ATR-ADX changes. These can be used by right clicking the strategy and clicking
// "Add Alert...". Reference the bottom of the script for the names of the alert
// conditions.
//
// See also: http://www.fxtsp.com/1287-doubly-adaptiv...

To show the difference between checking the "Use falling ATR Multiplier if ADX > Threshold" box I have plotted two instances of the Adaptive ATR Indicator using the same settings, except one checks this box and one doesn't. Obviously no two tickers and no two time frames are the same, so it will require some tinkering to get it right. 3.5 Rising and 1.75 Falling seem to be good starting points based on the article link and my own tests.

Cheers.
Catatan Pelepasan: Added multi-timeframe aspect to the script. Input your desired interval (15, 60, 240, D, W, M, 3M, 12M, etc) to view the indicator on an interval that is independent of the chart.

No repainting.
Catatan Pelepasan: Added back in trend change alert conditions.
Catatan Pelepasan: Updated to version 3.

Forced a positive (green) band to be the ceiling of the nearest pip/tick. Forced a negative (red) band to be the floor of the nearest pip/tick. This helps with rounding and intersections.

Added a pip/tick band around the stop for more resistance/support threshold visualizations.
Catatan Pelepasan: Removed unused portions of script.
Catatan Pelepasan: Fixed security function issue.
Catatan Pelepasan: Added alert conditions for trend change up/down. Added alert condition for ATR-ADX stop retests.
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 Rumah. Anda boleh menyukai skrip ini untuk menggunakannya pada carta.

Ingin menggunakan skrip ini pada carta?

Komen

If you would be interested, I would like to pay you to create this script for the Gekko bot!
+13 Balas
Can this script be used with the cryptocurrency signal finder tool here on tradingview? If so, how?
+9 Balas
This is one of the best and most useful indicators ever. The best way is to use it at trend change downtrend to uptrend and versa as the best results and outcome is and the most important it is the safest that way, the profit almost guaranted but don't get too greedy? Good work.
+8 Balas
Hey! Can you explain the logic of the line 54 ? How can : nz(sTR) - nz(sTR) be different of 0 ?
+3 Balas
@tofu00, I was wondering the same thing!
Balas
@tofu00, I don't understand your question.
Balas
tofu00 mortdiggiddy
@mortdiggiddy, on line 54, you set the sTR variable equal to `nz(sTR) - nz(sTR) / adxLen + tr`, but this part of the assignment : `nz(sTR) - nz(sTR)` can only be 0. As 5-5=0 or 99-99=0. I hope I was clear enough.
EDIT: The code i'm writing into the comment is partially removed by the comment engine. What I'm talking about is the substract of line 54 in the indicator code.
Balas
tofu00 mortdiggiddy
@mortdiggiddy, After some tests, it seems that TV is not respecting the order of operations. When you do this : `nz(sTR) - nz(sTR) / adxLen + tr` TV is doing this `(sTR - (sTR / adxLen)) + tr`

So what is the expected behavious of this line ?

Ref: https://www.tradingview.com/pine-script-docs/en/v3/language/Operators.html#priority-of-operators
+1 Balas
@tofu00, `nz(sTR) - nz(sTR) / adxLen + tr` TV is doing this `(sTR - (sTR / adxLen)) + tr`
_
Those are identical statements, you just wrapped them in parenthesis.
Balas
tofu00 mortdiggiddy
@mortdiggiddy, yes, this is was not obvious. So is `(sTR - (sTR / adxLen)) + tr` the expected behaviour in the context of your indicator ?
Balas
Laman Utama Penyaring Saham Penyaring Forex Penyaring Kripto Kalendar Ekonomi Mengenai Ciri-ciri Carta Harga Rujuk rakan Peraturan Dalaman Pusat Bantuan Laman web dan Penyelesaian Broker Widget Penyelesaian Pencartaan Perpustakaan Pencartaan yang Ringan Blog & Berita Twitter
Profil Tetapan Profil Akaun dan Pengebilan Kawan-kawan yang dirujuk Coin Tiket Sokongan Saya Pusat Bantuan Mesej Peribadi Sembang Daftar Keluar