DCA - ArsenAbazian/CryptoTradingFramework GitHub Wiki

DCA In Action

OK DCA is the not correct abbreviature for crypto trading :). DCA is the Dollar Cost Averaging. So, in this case, it should be a Crypto Cost Averaging strategy :). OK, and even in this case, it may be not the same thing, which happens in TaSimpleStrategy algorithm. So, what is this? When the strategy opens a long position, it expects (and you too) that price will go up. But sometimes, OK, often, happens strongly opposite thing - the price goes down. And in this case sometimes is better to close position and lose some of your deposit, and sometimes is better to open additional positions at lower prices and decrease the summary price of your opened positions. When this can happen? For example, when the strategy receives BreakDown signal, it calculates trendline's probably bottom and opens a long position when the price reaches this level (often the previous resistance or support level). The strategy excepts that trendline will not break the next support/resistance level and changes its direction. But sometimes it continues to go down to the next bottom. And then it will change the direction. And in this case, the better way is to open additional positions on the way to the next bottom. So this algorithm is controlled by 3 parameters:

  • DCAStartPercent - specifies the price down change in percent, from the price when the long position was open. When the price reaches this value, the strategy will open the first additional position.
  • DCAEndPercent - specifies the lower bound of price change in percent, from the price when the long position was open. This is the last level when the strategy will open an additional position.
  • DCAStartAmountFraction - specifies the fraction from DCA deposit for start level.
  • DCAEndAmountFraction - specifies the fraction from DCA deposit for end level.
  • DCALevelCount - specifies maximum additional position's count.

On the picture above you can see three orange lines on the chart. These are DCA levels. As you can see price after opening the long position went down and reaches the first DCA level, and strategy opens an additional long position with an amount of 20% of DCA deposit. Then the price went down more and reaches the second DCA level. And strategy opens one more long position with an amount of 33 of DCA deposit. And then trendline changes and the price went up and strategy closes the main long position and two DCA positions. You may ask why strategy spend 20% of DCA deposit on the first line and 33% on the second line, and what is the DCA deposit amount equal?

In the current version, the total amount of DCA deposit is always equal the amount of opened long position, i.e. if strategy receives BreakDown signal and opens a long position for $200 it will spend up to $200 for DCA if needed. Now, how DCA split its deposit between DCA levels: the algorithm is controlled by DCAStartAmountFraction and DCAEndAmountFraction and DCALevelCount. Having these values, the algorithm first calculates fractions for all lines and then normalizes fraction values.

DCA calculation example

  • DCA Deposit = 00
  • DCAStartAmountFraction = 30
  • DCAEndAmountFraction = 90
  • DCALevelCount = 3

So will be three DCA lines:

  1. with 30% of the deposit amount
  2. with 60% of the deposit amount (interpolated)
  3. with 90% of the deposit amount

Normalization:

  1. first line amount = 30% / (30% + 60% + 90%) * 100% = 16.7%
  2. second line amount = 60% / (30% + 60% + 90%) * 100% = 33.3%
  3. third line amount = 90% / (30% + 60% + 90%) * 100% = 50.0%

So DCA will spend 16.7% of DCA deposit when the price reaches the first DCA line, 33.3% when the prices reach the second line and 50% when the price reach the last line.