> For the complete documentation index, see [llms.txt](https://xtblock.gitbook.io/share-stock-cfds-trading-bot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xtblock.gitbook.io/share-stock-cfds-trading-bot/guides/share-stock-cfd-trading-bot-configuration/dca-calculation.md).

# DCA Calculation

% Unrealized PnL = UPNL in %\
Position Size = PS\
1st input value = A in %\
2nd input value = B in %

* DCA: \
  New position size: PS+ (B \* PS)\
  new UPNL = UPNL \* PS/ (PS+ (B \* PS)) \* 100
* Reverse DCA: \
  New position size: PS- (B \* PS)\
  % UPNL is same
* A-DCA: \
  New position size: PS\* (100 - B) + PS\* B \* (100 + UPNL)\
  new UPNL = PS\* (100 - B) \* B / (PS\* (100 - B) + PS\* B \* (100 + UPNL))

The above calculations exclude the exchange fees and the price discrepancy of market transactions at the trade execution time.\
\
Trigger conditions:\
if UPNL < 0 the condition needs to match (UPNL <= A)\
if UPNL > 0 the condition needs to match (A <= UPNL)
