OPEN-SOURCE SCRIPT

Period Dollar Cost Average Backtester

Here is a simple script to calculate the profits and other dollar cost average strategy statistics. This strategy was created to avoid asset price volatility, so the pump and dump scheme does not affect the portfolio. By dividing the investment amount into periods, the investor doesn’t need to analyze the market, fundamental analysis, or anything. The goal is to increase the asset holdings and avoid fast and robust price movements.

This indicator has some configurations.
  • Amount to buy: the amount to buy at each time
  • Broker fee %: the fee percentage that the broker has for spot trade
  • Frequency: the frequency of the investments. Example: 1 Day means that every day, it will buy an amount of the asset
  • Starting Date: when the indicator will start the investment simulation
  • Ending Date: when the indicator will end the investment simulation
  • InfoCell With/Height: it relates to the panel for view purposes. Change the values to fit better on your screen.


This indicator has three lines:
  • Total Invested (green): total amount invested at the end of the period
  • Total Net Profit (pink): total profit by converting the amount of the asset bought at the latest closing price
  • Holding Profits (yellow): the amount that would be in the portfolio if the investor had invested all the capital in a signal trade at the beginning of the period.


The statistics panel has some information to help you understand buying the asset in one or more trades. So, besides those three lines that were mentioned above, here are the other statistics:
  • Entry Price: The price of the asset when the first investment was made
  • Gross Profit: Total amount of profit, not excluding the losses
  • Gross Losses: Total amount of losses, not excluding the profits
  • Profit Factor: The Gross Profit divided by the Gross Loss. A value above 1 means it’s profitable.
  • Profit/Trades: Net profit per trade. This includes the broker fees.
  • Recovery Factor: The Net profit divided by the relative drawdown. The higher the recovery factor, the faster the recovery of a loss
  • Total Asset Bought: The amount of the asset that was bought at the end of the investment plan
  • Absolute Drawdown: The total amount of losses that made the account balance go below its initial value
  • Relative Drawdown: The max drawdown that occurred, no matter the account balance amount
  • Total Trades: number of times the investment was made in the selected period
  • Total Fee: total Fee that was spent on the total investment
  • Total Winning Trades: the total amount of winning trades. A trade is considered a winner if the net profit is up compared with the latest investment.
  • Total Losing Trades: the total amount of losing trades. A trade is considered a loser if the net profit is down compared to the latest investment.
  • Max consecutive wins: the max amount of consecutive winning trades
  • Max consecutive losses: the max amount of consecutive losing trades

    The chart above uses the default configuration of the indicator. Placed on the BTCUSD market, taking the time range of January 1st, 2018 to January 1st, 2022, 4 years. Buying a BTC amount with 10 USDT every day in that period would generate a more than 500% profit. Compared to the profit amount by just holding the count, which was close to 350% profit, the dollar cost average by period would be much more profitable.
CryptocurrencydollarcostaverageinvestmentinvestmentideainvestmentmanagementinvestmentplanMoving AveragesportfolioPortfolio management

Script de código abierto

Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

¿Quiere utilizar este script en un gráfico?


También en:

Exención de responsabilidad