millerrh

Donchian Breakout Strategy

millerrh Telah dikemas kini   
This strategy buys when the Donchian Channel is broken to the upside and uses the lower Donchian Channel line as a trailing stop. You can also choose to use a moving average as a filter to keep you out of trades that are counter trend.

You can also configure which dates you want to backtest, so you can see how this behaves over specific time frames and market cycles.
Nota Keluaran:
Added the ability to select different lookback periods for upper and lower bands. Results seem to be better with higher numbers for the upper band and lower numbers (tighter stops) for the lower band.
Nota Keluaran:
Made the following changes:
  • Update to Pine v5
  • Cleaned up code
  • Added a high time frame moving average filter (so you can choose to focus only on the strongest stocks with longer term uptrends).
  • Added a table showing the Average Daily Range (ADR - which is equivalent to the Monthly Volatility indicator in the stock screener) to help you see how much a stock moves around on average.
  • Added the ability to filter out trades that are outside of a user-defined percentage outside of the ADR to focus on better risk/reward trades.
Nota Keluaran:
The old adage is: "Cut your losers quick and let your winners run." So I figured a good tweak to this strategy would be to use a tighter Donchian channel as your initial stop until you are in profit, then use a larger channel to give the trade more room to breathe after that. So now this is an option that you can chose (but not the default).
Nota Keluaran:
I discovered that when you have calculated colors in a script, it disables the ability for the user to change any colors on anything (even non-calculated colors). The ADR table uses calculated colors, so to bring back the ability for the user to control the display better, I've brought user controls for the colors for everything else (Donchian Channels, Moving Averages). I also upped the initial capital to 100k so that trades will appear on expensive instruments and futures.
Nota Keluaran:
Added a new filter: If a moving average is sloping downward, it can ignore breaks of the DC Channel.

Note, it has a bug currently - it remembers the value of the DC channel the previous time the filter was true and will make a trade based on this previous (higher) value instead of resetting. Publishing this buggy version to seek help with fixing this and to be able to reset this value when the filter turns false.
Nota Keluaran:
  • Removed barmerge.lookahead_on from ADR calculation
  • Remove resting stop order once buy conditions are no longer met. Previously this was retaining old DC levels as stop orders even when the filters were used and price went below them.
Nota Keluaran:
Accidentally left an unrelated indicator visible on the previous upload screen shot.
Nota Keluaran:
Bug fix:
Previously, I had the Donchian channel set to the previous bar's value so that the current bar would react based on the historical bars' data. But it was causing some odd entries and exits that I didn't expect. Using the Replay feature, I realized that the historical bars don't actually update the Donchian Channel values for the current bar until it is finished (unlike in live markets where you'll see the Donchian Channel update in real time). So I've updated this code to refer to current value for the Donchian Channel instead of previous bar value. It should make the historical testing accurate to your settings now.
Nota Keluaran:
Fixed a bug where choosing to take the trades on close was not showing up. This is because if you wait until the bar is closed before taking trades, it will never show up because the Donchian Channel is reset with the new high/low of that bar. This fix looks at the previous bars' values to determine if it breaks it or not.

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.

Penafian

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?