Pine Script v5 · Strategy
3Commas Visible DCA Strategy
A Pine Script v5 strategy built on SMA or EMA (close, 5) and Crossover or Crossunder (Long_Moving_Average_Line). It has 5 order rules, 2 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays 0.01% commission. 15 settings; defaults include Strategy Long, Profit currency Quote (USDT) and Base order Size 10.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does 3Commas Visible DCA Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 17 of 17 trades.
- How did 3Commas Visible DCA Strategy do on BTCUSDT 1D with default settings?
- +2.62%
- From 26 Jan 2024 to 21 Oct 2026, over 63 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does 3Commas Visible DCA Strategy run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 63 before, 63 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does 3Commas Visible DCA Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 115, 116.
- Does 3Commas Visible DCA Strategy run in Zeal Terminal?
- Yes
- It compiles in 133 ms and runs 1,000 bars in 438 ms, in the browser.
BTCUSDT · 1D · default settings
- Short MA
- Long MA
- Safety order1
- Safety order2
- Safety order3
- Safety order4
- Safety order5
- Safety order6
- Safety order7
- Safety order8
- Safety order9
- Safety order10
- Take Profit
- Safety
- Winning trade
- Losing trade
- Net profit
- +2.62%
- $233.17
- Buy and hold
- +102.5%
- same period
- Closed trades
- 63
- 40 won · 23 lost
- Profitable
- 63.5%
- of closed trades
- Profit factor
- 6.63
- gross profit ÷ gross loss
- Max drawdown
- 1.98%
- −$176.95
One run with the author's default settings, $8,913 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
The “Over” option calculates CROSSOVER line 54
Choosing Over in “Entry at Cross Over / Under” runs ta.crossover, not ta.over. Anyone picking Over gets a different average from the one they asked for.
Triger_Type == 'Over' ? ta.crossover(Triger_Type == 'Over' ? ta.over( -
Likely bug
The “HMA” option calculates SMA line 46
Choosing HMA in “Short Moving Average” runs ta.sma, not ta.hma. Anyone picking HMA gets a different average from the one they asked for.
Short_Moving_Average == 'HMA' ? ta.sma(Short_Moving_Average == 'HMA' ? ta.hma( -
Likely bug
The “HMA” option calculates SMA line 50
Choosing HMA in “Long Moving Average” runs ta.sma, not ta.hma. Anyone picking HMA gets a different average from the one they asked for.
Long_Moving_Average == 'HMA' ? ta.sma(Long_Moving_Average == 'HMA' ? ta.hma( -
Check
1 setting does nothing
“Strategy” is declared but never read.
-
Note
1 setting has no label
In the settings dialog Strategy (line 4) shows an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 105, 109, 114. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Strategy | |||
| Strategy (no label in the script)Long bots profit when asset prices rise, Short bots profit when asset prices fall' + '\n\n' + 'Please note: to run a Short bot on a spot exchange account, you need to own the asset you want to trade. The bot will sell the asset at the current chart price and buy it back at a lower price - the profit made is actually trapped equity released from an asset you own that is declining in value. | Long | string · options ['Long'] | unused |
| Profit currency | Quote (USDT) | string · options ['Quote (USDT)', 'Quote (BTC)', 'Quote (BUSD)'] | currency |
| Base order SizeThe Base Order is the first order the bot will create when starting a new deal. | 10 | int | entry Base order exit TP/SL line 119 line 120 line 121 line 122 line 123 line 124 line 125 line 126 line 127 line 128 |
| Safety order SizeEnter the amount of funds your Safety Orders will use to Average the cost of the asset being traded, this can help your bot to close deals faster with more profit. Safety Orders are also known as Dollar Cost Averaging and help when prices moves in the opposite direction to your bot's take profit target. | 20 | int | line 85 |
| Deal start condition > Trading View custom signal | |||
| Entry at Cross Over / UnderDeal start condition decision | Over | string · options ['Over', 'Under'] | Base_order_Condition |
| Short Moving Average | SMA | string · options ["SMA", "EMA", "HMA"] | Short_Moving_Average_Line |
| Period | 5 | int | Short_Moving_Average_Line |
| Long Moving Average | HMA | string · options ["SMA", "EMA", "HMA"] | Long_Moving_Average_Line |
| Period | 50 | int | Long_Moving_Average_Line |
| Take profit / Stop Loss | |||
| Target profit (%) | 1.5 | float · step 0.05 | TP_line |
| Stop Loss (%)This is the percentage that price needs to move in the opposite direction to your take profit target, at which point the bot will execute a Market Order on the exchange account to close the deal for a smaller loss than keeping the deal open.' + '\n' + 'Please note, the Stop Loss is calculated from the price the Safety Order at on the exchange account and not the Dollar Cost Average price. | 15 | int | SL_line |
| Safety orders | |||
| Max safety trades count | 10 | int · max 10 | SL_line bot_use bot_dev Safety order1 Safety order2 Safety order3 Safety order4 Safety order5 Safety order6 Safety order7 Safety order8 Safety order9 Safety order10 line 107 line 112 |
| Price deviation to open safety orders (% from initial order) | 0.4 | float · step 0.01 | pd line 55 |
| Safety order volume scale | 1.8 | float · step 0.01 | line 85 |
| Safety order step scale | 1.19 | float · step 0.01 | ss line 55 |
What it calculates
- SMA / EMAclose, Period (5) · chosen by Short Moving Average
Short_Moving_Average_Line · line 45 - SMA / EMAclose, Period (50) · chosen by Long Moving Average
Long_Moving_Average_Line · line 49 - Crossover / CrossunderShort_Moving_Average_Line, Long_Moving_Average_Line · chosen by Entry at Cross Over / Under
Base_order_Condition · line 54
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Base order long | Base_order_Condition and strategy.opentrades == 0 | On | 105 |
| Open 'Safety order' + i_s long | (strategy.opentrades <= i) and strategy.position_size > 0 and not(strategy.position_size == 0) | On | 109 |
| cancel 'Safety order' + i_s | status_nonestrategy.position_size == 0 | On | 114 |
| Exit TP/SL stop and limit | every bar | On | 115 |
| Exit TP/SL stop and limit | every bar | On | 116 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2.6% | +102.5% | 63 | 63% | 6.63 | 2.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.5% | +5.5% | 67 | 72% | 26.60 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +2.9% | +9.8% | 57 | 67% | 6.95 | 12.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.7% | +8.4% | 56 | 80% | 20.16 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.8% | +16.7% | 58 | 57% | 9.03 | 4.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.8% | +21.5% | 84 | 65% | 10.00 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −10.7% | +148.3% | 112 | 63% | 0.34 | 15.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.4% | +17.1% | 48 | 79% | 38.55 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 27 | 67% | $85.83 |
| Sideways market | 20 | 60% | $73.14 |
| Falling market | 16 | 63% | $74.20 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.2%
The 95th percentile of the worst drawdown when the same 63 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.1% to 0.2%; the tick is what actually happened, 0.2%. Order luck alone moves it this much.
All 63 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 18 May 2024 66,915.20 | 20 May 2024 67,918.90 | 2 | $0.15 |
| long | 20 May 2024 66,274.00 | 20 May 2024 71,446.60 | 0 | $1.56 |
| long | 20 May 2024 66,274.00 | 20 May 2024 71,446.60 | 0 | $2.80 |
| long | 19 Jul 2024 66,660.00 | 21 Jul 2024 67,659.90 | 2 | $0.15 |
| long | 21 Jul 2024 66,393.40 | 21 Jul 2024 68,165.30 | 0 | $0.52 |
| long | 21 Jul 2024 66,076.10 | 21 Jul 2024 68,165.30 | 0 | $1.11 |
| long | 24 Aug 2024 64,157.00 | 29 Aug 2024 61,005.70 | 5 | −$0.49 |
| long | 26 Aug 2024 63,900.40 | 29 Aug 2024 61,005.70 | 3 | −$0.91 |
| long | 26 Aug 2024 63,595.00 | 29 Aug 2024 61,005.70 | 3 | −$1.46 |
| long | 26 Aug 2024 63,231.60 | 29 Aug 2024 61,005.70 | 3 | −$2.26 |
| long | 27 Aug 2024 62,799.10 | 29 Aug 2024 61,005.70 | 2 | −$3.35 |
| long | 27 Aug 2024 62,284.50 | 29 Aug 2024 61,005.70 | 2 | −$4.31 |
| long | 27 Aug 2024 61,672.10 | 29 Aug 2024 61,005.70 | 2 | −$4.08 |
| long | 27 Aug 2024 60,943.30 | 29 Aug 2024 61,005.70 | 2 | $0.54 |
| long | 27 Aug 2024 60,076.10 | 29 Aug 2024 61,005.70 | 2 | $17.88 |
| long | 27 Aug 2024 59,044.10 | 29 Aug 2024 61,005.70 | 2 | $68.39 |
| long | 17 Sep 2024 60,314.00 | 18 Sep 2024 61,760.00 | 1 | $0.24 |
| long | 5 Jan 2025 98,363.60 | 6 Jan 2025 102,236.00 | 1 | $0.39 |
| long | 7 Jan 2025 97,970.10 | 10 Jan 2025 94,937.60 | 3 | −$0.60 |
| long | 7 Jan 2025 97,501.90 | 10 Jan 2025 94,937.60 | 3 | −$0.91 |
| long | 7 Jan 2025 96,944.80 | 10 Jan 2025 94,937.60 | 3 | −$1.28 |
| long | 7 Jan 2025 96,281.70 | 10 Jan 2025 94,937.60 | 3 | −$1.56 |
| long | 8 Jan 2025 96,281.70 | 10 Jan 2025 94,937.60 | 2 | −$1.64 |
| long | 8 Jan 2025 95,492.70 | 10 Jan 2025 94,937.60 | 2 | −$1.24 |
| long | 8 Jan 2025 94,553.80 | 10 Jan 2025 94,937.60 | 2 | $1.42 |
| long | 8 Jan 2025 93,436.50 | 10 Jan 2025 94,937.60 | 2 | $10.40 |
| long | 9 Jan 2025 92,106.90 | 10 Jan 2025 94,937.60 | 1 | $36.22 |
| long | 17 Jan 2025 104,077.00 | 19 Jan 2025 105,639.00 | 2 | $0.15 |
| long | 19 Jan 2025 103,661.00 | 20 Jan 2025 102,495.00 | 1 | −$0.23 |
| long | 19 Jan 2025 103,166.00 | 20 Jan 2025 102,495.00 | 1 | −$0.24 |
| long | 19 Jan 2025 102,576.00 | 20 Jan 2025 102,495.00 | 1 | −$0.06 |
| long | 19 Jan 2025 101,875.00 | 20 Jan 2025 102,495.00 | 1 | $0.67 |
| long | 19 Jan 2025 101,040.00 | 20 Jan 2025 102,495.00 | 1 | $2.88 |
| long | 19 Jan 2025 100,046.00 | 20 Jan 2025 102,495.00 | 1 | $8.78 |
| long | 20 Jan 2025 100,046.00 | 20 Jan 2025 102,260.00 | 0 | $8.18 |
| long | 21 Jan 2025 102,260.00 | 21 Jan 2025 106,144.00 | 0 | $0.76 |
| long | 21 Jan 2025 102,260.00 | 21 Jan 2025 106,144.00 | 0 | $1.36 |
| long | 21 Jan 2025 102,260.00 | 21 Jan 2025 106,144.00 | 0 | $2.45 |
| long | 21 Jan 2025 101,875.00 | 21 Jan 2025 106,144.00 | 0 | $4.85 |
| long | 21 Jan 2025 101,040.00 | 21 Jan 2025 106,144.00 | 0 | $10.44 |
| long | 16 Apr 2025 84,030.40 | 19 Apr 2025 85,290.80 | 3 | $0.15 |
| long | 27 Jun 2025 107,048.00 | 30 Jun 2025 108,653.00 | 3 | $0.15 |
| long | 13 Sep 2025 115,918.00 | 16 Sep 2025 116,894.00 | 3 | $0.08 |
| long | 15 Sep 2025 115,268.00 | 16 Sep 2025 116,894.00 | 1 | $0.28 |
| long | 15 Sep 2025 114,903.00 | 16 Sep 2025 116,894.00 | 1 | $0.61 |
| long | 1 Oct 2025 118,595.00 | 2 Oct 2025 120,529.00 | 1 | $0.16 |
| long | 4 Jan 2026 91,529.70 | 5 Jan 2026 93,859.70 | 1 | $0.25 |
| long | 16 Mar 2026 74,884.70 | 20 Mar 2026 71,182.90 | 4 | −$0.50 |
| long | 18 Mar 2026 73,909.40 | 20 Mar 2026 71,182.90 | 2 | −$0.74 |
| long | 18 Mar 2026 73,909.40 | 20 Mar 2026 71,182.90 | 2 | −$1.34 |
| long | 18 Mar 2026 73,804.50 | 20 Mar 2026 71,182.90 | 2 | −$2.31 |
| long | 18 Mar 2026 73,299.70 | 20 Mar 2026 71,182.90 | 2 | −$3.36 |
| long | 18 Mar 2026 72,699.10 | 20 Mar 2026 71,182.90 | 2 | −$4.35 |
| long | 18 Mar 2026 71,984.30 | 20 Mar 2026 71,182.90 | 2 | −$4.17 |
| long | 18 Mar 2026 71,133.60 | 20 Mar 2026 71,182.90 | 2 | $0.32 |
| long | 19 Mar 2026 70,121.40 | 20 Mar 2026 71,182.90 | 1 | $18.00 |
| long | 19 Mar 2026 68,916.80 | 20 Mar 2026 71,182.90 | 1 | $69.67 |
| long | 7 Apr 2026 71,924.20 | 9 Apr 2026 73,003.10 | 2 | $0.15 |
| long | 9 Apr 2026 71,069.90 | 10 Apr 2026 72,036.30 | 1 | $0.27 |
| long | 9 Apr 2026 71,069.90 | 10 Apr 2026 72,036.30 | 1 | $0.48 |
| long | 9 Apr 2026 70,886.80 | 10 Apr 2026 72,036.30 | 1 | $1.04 |
| long | 17 Jul 2026 63,931.70 | 19 Jul 2026 64,890.70 | 2 | $0.15 |
| long | 19 Aug 2026 69,334.80 | 20 Aug 2026 73,025.10 | 1 | $0.53 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| 3Commas Visible DCA Strategy this page | — | v5 strategy | +2.6% | 63 | 2.0% |
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| 4X EMA and volume strategy by SoftKill21 | ema sma | v4 strategy | +1.8% | 3 | 25.8% |
| Simple Momentum Strategy Based on SMA, EMA and Volume by slip_stream | sma ema | v4 strategy | +7.4% | 18 | 27.4% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 3 strategy calls use the when = argument (line 105, 109, 114). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 63 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 105: when = Base_order_Condition and strategy.opentrades == 0 → if block
- Line 109: when = (strategy.opentrades <= i) and strategy.position_size > 0 and not(strategy.position_size == 0) → if block
- Line 114: when = status_none → if block
⋯if Base_order_Condition- strategy.entry('Base order', strategy.long, qty=Base_order_size/close, when=Base_order_Condition and strategy.opentrades == 0,- comment='BO' + ' - ' + str.tostring(Base_order_size) + str.tostring(currency))+ if Base_order_Condition and strategy.opentrades == 0+ strategy.entry('Base order', strategy.long, qty=Base_order_size/close,+ comment='BO' + ' - ' + str.tostring(Base_order_size) + str.tostring(currency))for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i)- strategy.entry('Safety order' + i_s, strategy.long, qty=safety_order_size(i)/close,- limit=Safe_order_line(i), when=(strategy.opentrades <= i) and strategy.position_size > 0 and not(strategy.position_size == 0), - comment='SO' + i_s + ' - ' + str.tostring(safety_order_size(i)) + str.tostring(currency))+ if (strategy.opentrades <= i) and strategy.position_size > 0 and not(strategy.position_size == 0)+ strategy.entry('Safety order' + i_s, strategy.long, qty=safety_order_size(i)/close,+ limit=Safe_order_line(i), + comment='SO' + i_s + ' - ' + str.tostring(safety_order_size(i)) + str.tostring(currency))for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i)- strategy.cancel('Safety order' + i_s, when=status_none)+ if status_none+ strategy.cancel('Safety order' + i_s) strategy.exit('TP/SL','Base order', limit=TP_line, stop=SL_line, comment = Safe_order_line(100) > close ? 'SL' + i_s + ' - ' + str.tostring(Base_order_size) + str.tostring(currency) : 'TP' + i_s + ' - ' + str.tostring(Base_order_size) + str.tostring(currency)) ⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 63 before, 63 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © MGTG-//@version=5+//@version=6Strategy = input.string('Long', options=['Long'], group='Strategy', inline='1',⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 133 ms | Yes 1,000 bars in 438 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © MGTG//@version=5Strategy = input.string('Long', options=['Long'], group='Strategy', inline='1', tooltip='Long bots profit when asset prices rise, Short bots profit when asset prices fall' + '\n\n' + 'Please note: to run a Short bot on a spot exchange account, you need to own the asset you want to trade. The bot will sell the asset at the current chart price and buy it back at a lower price - the profit made is actually trapped equity released from an asset you own that is declining in value.')Profit_currency = input.string('Quote (USDT)', 'Profit currency', options=['Quote (USDT)', 'Quote (BTC)', 'Quote (BUSD)'], group='Strategy', inline='1')Base_order_size = input.int(10, 'Base order Size', group='Strategy', inline='2', tooltip='The Base Order is the first order the bot will create when starting a new deal.')Safety_order_size = input.int(20, 'Safety order Size', group='Strategy', inline='2', tooltip="Enter the amount of funds your Safety Orders will use to Average the cost of the asset being traded, this can help your bot to close deals faster with more profit. Safety Orders are also known as Dollar Cost Averaging and help when prices moves in the opposite direction to your bot's take profit target.")Triger_Type = input.string('Over', 'Entry at Cross Over / Under', options=['Over', 'Under'], group='Deal start condition > Trading View custom signal', inline='1', tooltip='Deal start condition decision')Short_Moving_Average = input.string('SMA', 'Short Moving Average', group='Deal start condition > Trading View custom signal', inline='2', options=["SMA", "EMA", "HMA"])Short_Period = input.int(5, 'Period', group='Deal start condition > Trading View custom signal', inline='2')Long_Moving_Average = input.string('HMA', 'Long Moving Average', group='Deal start condition > Trading View custom signal', inline='3', options=["SMA", "EMA", "HMA"])Long_Period = input.int(50, 'Period', group='Deal start condition > Trading View custom signal', inline='3')Target_profit = input.float(1.5, 'Target profit (%)', step=0.05, group='Take profit / Stop Loss', inline='1') * 0.01Stop_Loss = input.int(15, 'Stop Loss (%)', group='Take profit / Stop Loss', inline='1', tooltip='This is the percentage that price needs to move in the opposite direction to your take profit target, at which point the bot will execute a Market Order on the exchange account to close the deal for a smaller loss than keeping the deal open.' + '\n' + 'Please note, the Stop Loss is calculated from the price the Safety Order at on the exchange account and not the Dollar Cost Average price.') * 0.01Max_safety_trades_count = input.int(10, 'Max safety trades count', maxval=10, group='Safety orders', inline='1')Price_deviation = input.float(0.4, 'Price deviation to open safety orders (% from initial order)', step=0.01, group='Safety orders', inline='2') * 0.01Safety_order_volume_scale = input.float(1.8, 'Safety order volume scale', step=0.01, group='Safety orders', inline='3')Safety_order_step_scale = input.float(1.19, 'Safety order step scale', step=0.01, group='Safety orders', inline='3')initial_capital = 8913strategy( title='3Commas Visible DCA Strategy', overlay=true, initial_capital=initial_capital, pyramiding=11, process_orders_on_close=true, commission_type=strategy.commission.percent, commission_value=0.01, max_bars_back=5000, max_labels_count=50)// Positionstatus_none = strategy.position_size == 0status_long = strategy.position_size[1] == 0 and strategy.position_size > 0status_long_offset = strategy.position_size[2] == 0 and strategy.position_size[1] > 0status_short = strategy.position_size[1] == 0 and strategy.position_size < 0status_increase = strategy.opentrades[1] < strategy.opentradesShort_Moving_Average_Line = Short_Moving_Average == 'SMA' ? ta.sma(close, Short_Period) : Short_Moving_Average == 'EMA' ? ta.ema(close, Short_Period) : Short_Moving_Average == 'HMA' ? ta.sma(close, Short_Period) : naLong_Moving_Average_Line = Long_Moving_Average == 'SMA' ? ta.sma(close, Long_Period) : Long_Moving_Average == 'EMA' ? ta.ema(close, Long_Period) : Long_Moving_Average == 'HMA' ? ta.sma(close, Long_Period) : na Base_order_Condition = Triger_Type == "Over" ? ta.crossover(Short_Moving_Average_Line, Long_Moving_Average_Line) : ta.crossunder(Short_Moving_Average_Line, Long_Moving_Average_Line) // Buy when close crossing lower bandsafety_order_deviation(index) => Price_deviation * math.pow(Safety_order_step_scale, index - 1)pd = Price_deviationss = Safety_order_step_scalestep(i) => i == 1 ? pd : i == 2 ? pd + pd * ss : i == 3 ? pd + (pd + pd * ss) * ss : i == 4 ? pd + (pd + (pd + pd * ss) * ss) * ss : i == 5 ? pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss : i == 6 ? pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss : i == 7 ? pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss : i == 8 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 9 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 10 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : nalong_line(i) => close[1] - close[1] * (step(i))Safe_order_line(i) => i == 0 ? ta.valuewhen(status_long, long_line(0), 0) : i == 1 ? ta.valuewhen(status_long, long_line(1), 0) : i == 2 ? ta.valuewhen(status_long, long_line(2), 0) : i == 3 ? ta.valuewhen(status_long, long_line(3), 0) : i == 4 ? ta.valuewhen(status_long, long_line(4), 0) : i == 5 ? ta.valuewhen(status_long, long_line(5), 0) : i == 6 ? ta.valuewhen(status_long, long_line(6), 0) : i == 7 ? ta.valuewhen(status_long, long_line(7), 0) : i == 8 ? ta.valuewhen(status_long, long_line(8), 0) : i == 9 ? ta.valuewhen(status_long, long_line(9), 0) : i == 10 ? ta.valuewhen(status_long, long_line(10), 0) : naTP_line = strategy.position_avg_price * (1 + Target_profit) SL_line = Safe_order_line(Max_safety_trades_count) * (1 - Stop_Loss)safety_order_size(i) => Safety_order_size * math.pow(Safety_order_volume_scale, i - 1)plot(Short_Moving_Average_Line, 'Short MA', color=color.new(color.white, 0), style=plot.style_line)plot(Long_Moving_Average_Line, 'Long MA', color=color.new(color.green, 0), style=plot.style_line)plot(strategy.position_size > 0 and Max_safety_trades_count >= 1 ? Safe_order_line(1) : na, 'Safety order1', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 2 ? Safe_order_line(2) : na, 'Safety order2', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 3 ? Safe_order_line(3) : na, 'Safety order3', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 4 ? Safe_order_line(4) : na, 'Safety order4', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 5 ? Safe_order_line(5) : na, 'Safety order5', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 6 ? Safe_order_line(6) : na, 'Safety order6', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 7 ? Safe_order_line(7) : na, 'Safety order7', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 8 ? Safe_order_line(8) : na, 'Safety order8', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 9 ? Safe_order_line(9) : na, 'Safety order9', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 and Max_safety_trades_count >= 10 ? Safe_order_line(10) : na, 'Safety order10', color=color.new(#009688, 0), style=plot.style_linebr)plot(strategy.position_size > 0 ? TP_line : na, 'Take Profit', color=color.new(color.orange, 0), style=plot.style_linebr)plot(strategy.position_size > 0 ? SL_line : na, 'Safety', color=color.new(color.aqua, 0), style=plot.style_linebr)currency = Profit_currency == 'Quote (USDT)' ? ' USDT' : Profit_currency == 'Quote (BTC)' ? ' BTC' : Profit_currency == 'Quote (BUSD)' ? ' BUSD' : naif Base_order_Condition strategy.entry('Base order', strategy.long, qty=Base_order_size/close, when=Base_order_Condition and strategy.opentrades == 0, comment='BO' + ' - ' + str.tostring(Base_order_size) + str.tostring(currency))for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i) strategy.entry('Safety order' + i_s, strategy.long, qty=safety_order_size(i)/close, limit=Safe_order_line(i), when=(strategy.opentrades <= i) and strategy.position_size > 0 and not(strategy.position_size == 0), comment='SO' + i_s + ' - ' + str.tostring(safety_order_size(i)) + str.tostring(currency))for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i) strategy.cancel('Safety order' + i_s, when=status_none) strategy.exit('TP/SL','Base order', limit=TP_line, stop=SL_line, comment = Safe_order_line(100) > close ? 'SL' + i_s + ' - ' + str.tostring(Base_order_size) + str.tostring(currency) : 'TP' + i_s + ' - ' + str.tostring(Base_order_size) + str.tostring(currency)) strategy.exit('TP/SL','Safety order' + i_s, limit=TP_line, stop=SL_line, comment = Safe_order_line(100) > close ? 'SL' + i_s + ' - ' + str.tostring(safety_order_size(i)) + str.tostring(currency) : 'TP' + i_s + ' - ' + str.tostring(safety_order_size(i)) + str.tostring(currency)) bot_usage(i) => i == 1 ? Base_order_size + safety_order_size(1) : i == 2 ? Base_order_size + safety_order_size(1) + safety_order_size(2) : i == 3 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) : i == 4 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) : i == 5 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) : i == 6 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) : i == 7 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) : i == 8 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) + safety_order_size(8) : i == 9 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) + safety_order_size(8) + safety_order_size(9) : i == 10 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) + safety_order_size(8) + safety_order_size(9) + safety_order_size(10) : naequity = strategy.equitybot_use = bot_usage(Max_safety_trades_count)bot_dev = float(step(Max_safety_trades_count)) * 100bot_ava = (bot_use / equity) * 100string label = 'Balance : ' + str.tostring(math.round(equity, 0), '###,###,###,###') + ' USDT' + '\n' + 'Max amount for bot usage : ' + str.tostring(math.round(bot_use, 0), '###,###,###,###') + ' USDT' + '\n' + 'Max safety order price deviation : ' + str.tostring(math.round(bot_dev, 0), '##.##') + ' %' + '\n' + '% of available balance : ' + str.tostring(math.round(bot_ava, 0), '###,###,###,###') + ' %' + (bot_ava > 100 ? '\n \n' + '⚠ Warning! Bot will use amount greater than you have on exchange' : na) if status_long day_label = label.new( x=time[1], y=high * 1.03, text=label, xloc=xloc.bar_time, yloc=yloc.price, color=bot_ava > 100 ? color.new(color.yellow, 0) : color.new(color.black, 50), style=label.style_label_lower_right, textcolor=bot_ava > 100 ? color.new(color.red, 0) : color.new(color.silver, 0), size=size.normal, textalign=text.align_left)