Donchian Breakout Strategy

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.
Release Notes: 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.
Skript med en öppen källkod

I sann TradingView-anda har författaren till detta skript publicerat det som öppen källkod, så att handlare kan förstå och verifiera det. Skål för författaren! Du kan använda den gratis men återanvändning av den här koden i en publikation regleras av våra Ordningsregler. Du kan göra den till favorit för att använda den i ett diagram.

Vill du använda det här skriptet i ett diagram?


Hi this is fantastic! Thanks for putting this up!

Is there a way I can change the entry criteria to trigger an entry when the RSI crosses above 60? But the trailing conditions maintained as yours? Tried all day but keep getting errors because I have totally zero knowledge in scripting. Would appreciate heaps if you can help me! Turning desperate with all the losses the past weeks, so sad.

length = input(14, title="RSI length")
ob = input(60, title="Overbought level")

rsi = rsi(close, length)

buy = rsi > ob
millerrh Richkierich
@Richkierich, yes you would just put those lines of code in that you have there and change

buySignal = trigResistance >= dcUpper


buySignal = rsi > ob
Richkierich millerrh
@millerrh, dude thanks much! respect!
millerrh arose033
@arose033, It does not look into the future, so that's not the case. but it will trigger/change on the current candle as it changes.
+1 Svara
Hi Millerrh - sorry to trouble - quick one - the D Channel lines are showing but not the signals for 'long' and 'close entry' as shown on your example chart. Are those supposed to be there with the script, or you added to the example above for illustration?
Many thanks!
@HKTOM, They should be showing. These are the default buy/sell markers provided by TradingView within their strategy scripts whenever the conditions are met. I bet what is happening is that whatever your settings are isn't actually triggering any trades. Look in the "List of Trades" section of the "Strategy Tester" tab at the bottom. Do you see any trades there? if not, that is what is going on.

This strategy only buys when the upper channel is broken. Do you see any instances on your chart where the price goes above that upper channel? If so, one of these buy arrows should appear. If price action is contained within the channel, then you are not triggering any trades.
HKTOM millerrh
@millerrh, Thanks for responding - yes I can see spots where the price goes above. But no arrows on chart, and no trades showing up in the strategy tester...any ideas/ suggestions on settings ? Many thanks!
@HKTOM, Trades are not triggering for some reason. I have built in a number of optional filters in the settings, so my guess is that it is something about those filters being active. Check out the date ranges filter and the ignoring trades under the SMA filter and make sure you're not operating outside of those filters.
Hey Millerrh, I agree with Jordan, can you make this work for taking shorts as well? I'd like to use it on forex and crypto markets. Thank you! Great script!