millerrh

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.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Comments

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.

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

//RSI
rsi = rsi(close, length)

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

buySignal = trigResistance >= dcUpper

to

buySignal = rsi > ob
Reply
Richkierich millerrh
@millerrh, dude thanks much! respect!
Reply
repainting?
Reply
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 Reply
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!
Reply
@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.
Reply
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!
Reply
@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.
Reply
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!
Reply