OPEN-SOURCE SCRIPT

DCA Strategy

1 013
This strategy makes it easy for you to backtest and automate the DCA strategy based on 2 triggers:
  1. Day of the week
  2. Every X candles

This way you can set up your DCA strategy the way you like and automate on any exchange or even a DEX, which offers an API.

The strategy is auto selling on the last candle, otherwise you won't see any performance numbers because all positions will still be open (non conclusive).

Settings
Start Date & End Date
Use those dates to help you with your backtest period. It also helps when automating, to start at a specific time to mimic what you have already done on your own portfolio and thus be in sync in TV as well.

Capital to invest per trade
Set how capital to use per DCA buy signal. Hover over the tooltip to understand, which currency is used.

Close All on last candle
When backtesting, you must close open positions, otherwise the Strategy Tester won't show you any numbers. This is why the strategy automatically closes all positions on the last candle for your convenience (ON per default).
BUT, when automating, you cannot have this checked because it would sell all of your asset on every candle open. So turn this OFF when automating.

Use Day of Week Mode
This checkbox switches between the "Day of Week" mode or the "Every X Candles" mode.

Day of Week
Opens a long position at the start of the weekday you have set it to.
Hover over the tooltip to understand, which number to use for the day of the week you need.

Every X Candles
Opens a long position after every x candles. Always at the start of every such candle.
On the daily chart, this number represents "1 day", on the 1h chart, it's "1 hour" and so on.

Properties
Initial Capital
DCA has a special quirk and that is that it invests more and more and more funds the longer it runs. But TradingView takes the Initial Capital number to calculate Net Profit, thus the Initial Capital number has to grow with every additional dollar (money) that is being invested over time, otherwise the Net Profit number will be wrong.

Sadly PineScript does not allow to set the Initial Capital number dynamically. So you have to set it manually.

To that end, this strategy shows a Label on the last candle, which shows the Invested Capital. You must take that number and put it into the Initial Capital input and click Ok.
If you don't do this, your Net Profit Number will be totally wrong!

The label must show green.
If it shows red it means you need to change the Initial Capital number before looking at the performance numbers.
istantanea
After every timeframe or settings change, you must adapt the Initial Capital, otherwise you will get wrong numbers.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.