fiddlah

DCA Bot Long/Short

Thanks to @TheTradingParrot for the inspiration and knowledge shared.
Thanks to @ericlin0122 for the original DCA Bot Emulator which is the backbone of this strategy.
The script simulates DCA strategy with parameters used in 3commas DCA bots for futures trading. Experiment with parameters
to find your trading setup.
Beware how large your total leveraged position is and how far can market go before you get liquidated!
Do that with the help of futures liquidation calculators you can find online!

I`ve added:

1) an internal average price and profit calculating, instead of TV`s native one, which is subject to severe slippage.
2) I`ve built a graphic interface, so levels are clearly visible and back-test analyzing made easier.
3) now both Long & Short direction of the strategy exist.
4) trailing TP which was featured in the initial script has been removed because TV`s execution model makes
it impossible to know how the real world trailing would have unfolded.
5) the table is self explanatory, and it is there to help you discover what happened and where.
6) vertical colored lines appear when the new maximum deviation from the original price has
been reached
All the trading happens with total account capital, and all order sizes inputs are expressed in percent.


Known issues:

When deviation is small, and the same candle triggers safety AND the close order, the initial orders are closed, but a
new one opens on the next candle. This is "resolved" by closing the unwanted trade forcefully on the next candle, affecting
profit calculating minimally and guaranteeing that what should be closed has been closed.

The code could be improved through use of arrays, making the table flexible so the number of rows should be dynamic depending
on the number of SOs.


!!!!! IMPORTANT!!!!!

This strategy script is made to receive a signal from an exterior study script, which should plot +100 for long or -100 for short
entry (that is by default - values can be changed in the strategy settings menu). That plot should be found in "Enter Trigger" input
dropdown menu at the bottom of strategy settings menu. Removing the "and trigger == long/short_trigger" condition from strategy entry
conditions makes the strategy open trades ASAP.

Cheers!
Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.

Хотите использовать этот скрипт на графике?