TradingView
tedwardd
28. Mrz. 2021 14:02

3Commas Bollinger Strategy 

Bitcoin / TetherUSBinance

Beschreibung

This strategy is intended for use as a way of backtesting various parameters available on 3commas.io composite bot using a bollinger band type trading strategy. While it's primary intention is to provide users a way of backtesting bot parameters, it can also be used to trigger a deal start by either using the {{strategy.open.alert_message}} field in your alert and providing the bot details in the configuration screen for the strategy or by including the usual deal start message provided by 3commas. You can find more information about how to do this from help.3commas.io/en/articles/3108938-how-to-use-tradingview-custom-signals.



The primary inputs for the strategy are:

// USER INPUTS
Short MA Window - The length of the Short moving average
Long MA Window - The length of the Long moving average
Upper Band Offset - The offset to use for the upper bollinger offset
Lower Band Offset - The offset to use for the lower bollinger offset
Long Stop Loss % - The stop loss percentage to test
Long Take Profit % - The Take profit percentage to test
Initial SO Deviation % - The price deviation percentage required to place to first safety order
Safety Order Vol Step % - The volume scale to test
3Commas Bot ID - (self explanatory)
Bot Email Token - Found in the deal start message for your bot (see link in previous section for details)
3Commas Bot Trading Pair - The pair to include for composite bot start deals (should match format of 3commas, not TradingView IE. USDT_BTC not BTCUSDT)

Start Date, Month, Year and End Date, Month and Year all apply to the backtesting window. By default it will use as much data as it can given the current period select (there is less historical data available for periods below 1H) back as far as 2016 (there appears to be no historical data on Trading view much before this). If you would like to test a different period of time, just change these values accordingly.

Known Issues
Currently there are a couple of issues with this strategy that you should be aware of. I may fix them at some point in the future but they don't really bug me so this is more for informational purposes than a promise that they may one day be fixed.
  • Does not test trailing take profit
  • Number of safety orders and Safety Order Step Scale are currently not user configurable (must edit source code)
  • Using the user configuration to generate deal start message assumes you are triggering a composite bot, not a simple bot.

Versionshinweise

Remove some dead code, fix some comment typos, cleanup some formatting inconsistencies and remove a forgotten integer value used during some tests

Versionshinweise

Increasing the strategy default_qty_value and initial_capital values to values that work on the regular stock market where whole shares must be purchased and cost more than 100USD. Previous version required manual editing for adaptation outside of crypto trading.

Additionally, I must apologize and make a correction to the documentation. I had previously stated that you could use either {{strategy.order.alert_message}} OR the start message provided by 3commas. This is not correct. Alerts will be triggered for all strategy actions (take profit, stop loss, entry and safety orders). If you do not use {{strategy.order.alert_message}}, the message message in the alert will be incorrect and deals will be opened at incorrect times, specifically on a take profit trigger. You MUST use the strategy settings to configure the bot information and trading pair and use {{strategy.order.alert_message}} in the alert message field.

Versionshinweise

Add toggle for triggering one crossing over as well as crossing under the lower band.

Versionshinweise

* Allow customizing number of safety orders from user settings
* Automatically detect trading pair to eliminate the need for the trading pair user setting (easier alert creation)

I also received a question that I will answer here in case others have the same:

Q: How can I make alerts with this strategy? Do I need to convert it to a study first?
A: No! The alert message is generated automatically in the format needed to start a 3commas composite long bot! As long as you provide the bot ID and Email Token in the user settings for the strategy (click the gear next to the strategy on the chart), all you need to do is add an alert, select the strategy from the drop down in the alert box, and use (without quotes) "{{strategy.order.alert_message}}" as the message body text NOTHING ELSE.

Versionshinweise

This update fixes the deal entry message. The previous update to automatically detect and use the currently selected currency pair in the alert message was improperly formatted. This issue should now be fixed.

Versionshinweise

This release improves code readability as well as provides better estimates for safety order accuracy.

* Group bot settings in code together more clearly
* Allow user configurable safety step scale
* More accurately calculate safety order volume (still work in progress but should be close now)
Kommentare
abdulmajeed_1
Ill will try it out thank you for your effort
tochinoki
Thanks for the great signal. Just to let you know that the documentation mentions the alert message field should be:

{{strategy.entry.alert_message}}

But in reading the code it looks like it should be:

{{strategy.order.alert_message}}

The alert_message doesn't appear to get set in the call to strategy.entry().

Apologies if I'm incorrect.
laoowai
@tochinoki, please read the notice "Mar 29 - You MUST use the strategy settings to configure the bot information and trading pair and use {{strategy.order.alert_message}} in the alert message field."
tochinoki
@laoowai, sorry, I had them the wrong way round. I meant to write:

"Thanks for the great signal. Just to let you know that the documentation mentions the alert message field should be:

{{strategy.order.alert_message}}

But in reading the code it looks like it should be:

{{strategy.entry.alert_message}}

The alert_message doesn't appear to get set in the call to strategy.entry().

Apologies if I'm incorrect."

The Mar 29th advice doesn't work for me for the reasons above.
tedwardd
@tochinoki, Please refer to the pinescript documention for strategy.entry which I've quoted below:

alert_message (string) An optional parameter which replaces the {{strategy.order.alert_message}} placeholder when it is used in the "Create Alert" dialog box's "Message" field.

tradingview.com/pine-script-reference/
KB0006
Can someone help? With moderate settings im getting 32749061% net profit in the backtest, something is highly wrong.
Pamir35
Hi mate good job!

Can we do also SHORT ? I think this is only for LONG?
rampaige91
Hi, it realized the Base Order Size and Safety Order Size values are contract by default, not USD! This means if I enter 1000 in any of those two fields, trades would be shown in the backtesting table in contract size, not USD! Can you please change the script to take the Base Order Size and Safety Order Size values as USD, not contract size? That's why if we put 1000 in these two fields, the profit and loss percentages are high.
Satoshi-miner
Hi, great job and thanks for sharing. The deviation step is not the same on the script on tradingview and on 3commas. The settings are the same but the step deviation percentage is not... It's strange...Did you notice that?
Thank you
Mehr