TradingView
sergeyen
6 дек 2023 г., 00:48

Donchian Quest Research 

Bitcoin all time history indexINDEX

Описание

// =================================

Trend following strategy.

// =================================

Strategy uses two channels. One channel - for opening trades. Second channel - for closing.

Channel is similar to Donchian channel, but uses Close prices (not High/Low). That helps don't react to wicks of volatile candles (“stop hunting”). In most cases openings occur earlier than in Donchian channel. Closings occur only for real breakout.

// =================================

Strategy waits for beginning of trend - when price breakout of channel. Default length of both channels = 50 candles.

Conditions of trading:

- Open Long: If last Close = max Close for 50 closes.
- Close Long: If last Close = min Close for 50 closes.
- Open Short: If last Close = min Close for 50 closes.
- Close Short: If last Close = max Close for 50 closes.

// =================================

Color of lines:

- black - channel for opening trade.
- red - channel for closing trade.
- yellow - entry price.
- fuchsia - stoploss and breakeven.
- vertical green - go Long.
- vertical red - go Short.
- vertical gray - close in end, don't trade anymore.

// =================================

Order size calculated with ATR and volatility.

You can't trade 1 contract in BTC and 1 contract in XRP - for example. They have different price and volatility, so 1 contract BTC not equal 1 contract XRP.

Script uses universal calculation for every market. It is based on:
- Risk - USD sum you ready to loss in one trade. It calculated as percent of Equity.
- ATR indicator - measurement of volatility.

With default setting your stoploss = 0.5 percent of equity:

- If initial capital is 1000 USD and used parameter "Permit stop" - loss will be 5 USD (0.5 % of equity).
- If your Equity rises to 2000 USD and used parameter "Permit stop"- loss will be 10 USD (0.5 % of Equity).

// =================================

This Risk works only if you enable “Permit stop” parameter in Settings.

If this parameter disabled - strategy works as reversal strategy:
⁃ If close Long - channel border works as stoploss and momentarily go Short.
⁃ If close Short - channel border works as stoploss and momentarily go Long.

Channel borders changed dynamically. So sometime your loss will be greater than ‘Risk %’. Sometime - less than ‘Risk %’.

If this parameter enabled - maximum loss always equal to 'Risk %'. This parameter also include breakeven: if profit % = Risk %, then move stoploss to entry price.

// =================================

Like all trend following strategies - it works only in trend conditions. If no trend - slowly bleeding. There is no special additional indicator to filter trend/notrend. You need to trade every signal of strategy.

Strategy gives many losses:
⁃ 30 % of trades will close with profit.
⁃ 70 % of trades will close with loss.
⁃ But profit from 30% will be much greater than loss from 70 %.

Your task - patiently wait for it and don't use risky setting for position sizing.

// =================================

Recommended timeframe - Daily.

// =================================

Trend can vary in lengths. Selecting length of channels determine which trend you will be hunting:
⁃ 20/10 - from several days to several weeks.
⁃ 20/20 or 50/20 - from several weeks to several months.
⁃ 50/50 or 100/50 or 100/100 - from several months to several years.

// =================================

Inputs (Settings):

- Length: length of channel for trade opening/closing. You can choose 20/10, 20/20, 50/20, 50/50, 100/50, 100/100. Default value: 50/50.

- Permit Long / Permit short: Longs are most profitable for this strategy. You can disable Shorts and enable Longs only. Default value: permit all directions.

- Risk % of Equity: for position sizing used Equity percent. Don't use values greater than 5 % - it's risky. Default value: 0.5%.

⁃ ATR multiplier: this multiplier moves stoploss up or down. Big multiplier = small size of order, small profit, stoploss far from entry, low chance of stoploss. Small multiplier = big size of order, big profit, stop near entry, high chance of stoploss. Default value: 2.

- ATR length: number of candles to calculate ATR indicator. It used for order size and stoploss. Default value: 20.

- Close in end - to close active trade in the end (and don't trade anymore) or leave it open. You can see difference in Strategy Tester. Default value: don’t close.

- Permit stop: use stop or go reversal. Default value: without stop, reversal strategy.

// =================================

Properties (Settings):

- Initial capital - 1000 USD.
- Script don't uses 'Order size' - you need to change 'Risk %' in Inputs instead.
- Script don't uses 'Pyramiding'.
- 'Commission' 0.055 % and 'Slippage' 0 - this parameters are for crypto exchanges with perpetual contracts (for example Bybit). If use on other markets - set it accordingly to your exchange parameters.

// =================================

Big dataset used for chart - 'BITCOIN ALL TIME HISTORY INDEX'. It gives enough trades to understand logic of script. It have several good trends.

// =================================

Информация о релизе

Added trailing (fuchsia line) to parameter 'Permit stop'.

Информация о релизе

Added Montly Table (parameter 'Show Monthly Table' in Settings (Inputs)).

Информация о релизе

Added different variants for parameter 'Permit stop' (fuchsia line):

- No stop:
No stop.

- Fixed stop:
Set stop one time and never change it.

- Trailing:
Initial stop = fixed stop.
If channel border cross entry price: move stop to channel border.

- Breakeven, trailing:
Initial stop = fixed stop.
If profit > risk: move stop to entry price (breakeven).
If channel border cross entry price: move stop to channel border.

Информация о релизе

Added another variant for parameter 'Permit stop' (fuchsia line):

- Breakeven:
Initial stop = fixed stop.
If profit > risk: move stop to entry price.

Информация о релизе

Added:
- setting 'Show Qty label'. Info for qty calculation: Equity, Atr. Default: Disabled.
- setting 'Use 2 orders'. It divide initial qty to 2 orders. If setting 'Risk' = 0.5%, then risk of each order will be 0.25%. First order opens as usual. Second order opens if first order is profitable. If no trend - loss from first order will be 0.25% (not 0.5%). Default: Enabled.

Removed:
- setting 'Performance table' - not very useful and helping.
- setting 'Stop Breakeven, Trailing' - too complicated.

Corrected:
- small error in ATR calculation.
- 'Fixed stop' renamed to 'Fixed'.

Информация о релизе

Small correction in cancelling.

Информация о релизе

Small correction in qty calculation:

Now script works with 'Total Market Cap' charts: TOTAL, TOTAL2, TOTAL3.
This is for info purposes only.

For example, setting '20/20' shows general picture - phases of cycle:
- up, down, up, down, up, down to end of Sep 2023 - accumulation.
- end of Sep 2023 - uptrend.
- mid-Jan - mid-Feb - small correction of uptrend.
- mid-Feb - uptrend continues.

Информация о релизе

Added small channels: 10/5 and 10/10.

Информация о релизе

Added two more orders - now possible to choose from 1 to 4 orders.
Idea from the book "Way of the Turtle" by Curtis M. Faith.

Информация о релизе

Correction of trailing calculation.

Информация о релизе

Added parameter 'Use additional orders?':
If trade is profitable - use additional orders to increase position size.

Added tooltips - information circles with description - to each parameter.

Информация о релизе

Small error in trailing calculation.

Информация о релизе

Little change in add orders.

Информация о релизе

'Cost %' changed to 3.

Информация о релизе

Fixed small error in cancelling.
Комментарии
sergeyen
The big problem for crypto is the correlation, the strong connection between Bitcoin and altcoins.

For example, now Bitcoin has stopped its growth, many traders are taking profits and closing trades. Therefore, many altcoins are slowly starting to bleed.

If you are trading a short-term trend (parameter “Length” = 20/10) or a medium-term trend (parameter “Length” = 20/20), many altcoins are now giving a SHORT signal at the same time.

If the price rises, all such trades will simultaneously turn out to be unprofitable.

If the price falls, all such trades will simultaneously turn out to be profitable.

There is no simple way in crypto to avoid this correlation (for professionals there are hedging and delta-neutral trading).

So use basic rules of any strategies:
- don’t try to predict the future,
- trade what you have now,
- use risk management,
- ALWAYS use stop loss and/or isolated margin.
sergeyen
@sergeyen, correlation with BTC continues. Now some of this altcoin SHORTS - in little profit, some - in little loss. Summary UPNL - in little profit. Patiently waiting.
sergeyen
@sergeyen, More and more altcoin shorts are becoming profitable. Many have already reached breakeven level - move stop order to entry price. Patiently waiting.
Pipsluger76
I Like it .. Wery simple. Donchian allways been wery simple you made it simpler. Salute.
sergeyen
@Pipsluger76, I like quote from the book "Way of turtle" about trend following:
"Trade with an edge, manage risk, be consistent, and KEEP IT SIMPLE. The entire Turtle training, and indeed the basis for all successful trading, can be summed up in these four core principles".
:-)
sergeyen
I want to test this strategy in real trading.
I will use new perpetual DEX - Hyperliquid.
I will publish some trades on Twitter.
Link to Twitter - in my profile.
Description of experiment - in pinned thread.
sergeyen
Another example of many trades with loss and one trade with profit - BTC:

- If you trade short term trends (parameter 'Length' = 20/10) - today was signal to close Long.
- If you trade middle term trends (20/20 or 50/20) - maybe in near time will be signal to close Long.
- If you trade long term trends (50/50 or 100/50 or 100/100) - Long is far from closing.

Choosing parameter 'Length' depends of your patience - how long you ready to wait, how frequently you want to trade.
ThousandX_Trader
Question: have you tried this on other assets? I'm guessing Koulajian and Czkwianianc aren't primarily trading BTC...
sergeyen
@ThousandX_Trader, You can trade any assets that may have a trend: stocks, indexes, bonds, forex, crypto.

If there is no trend, there is no profit.

Below in the comments you can see an example of 1000BONK crypto.

I chose BTC because TradingView requires big history. In rules of script publishing:

“Select a dataset that will generate a number of trades producing a sufficient sample size, ideally more than 100 trades.”
ThousandX_Trader
Nice work Sergeyen! I've loaded the script and am checking it out now. Looks very promising. Nice work.
Ещё