Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (15)
Balance Balance Balance Balance Balance Balance Balance Balance Balance Balance Balance Balance Balance Balance Balance 40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,146$18,051Equity from $8,913
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
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.

SettingDefaultType and rangeFeeds
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.Longstring · options ['Long']unused
Profit currencyQuote (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.10intentry 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.20intline 85
Deal start condition > Trading View custom signal
Entry at Cross Over / UnderDeal start condition decisionOverstring · options ['Over', 'Under']Base_order_Condition
Short Moving AverageSMAstring · options ["SMA", "EMA", "HMA"]Short_Moving_Average_Line
Period5intShort_Moving_Average_Line
Long Moving AverageHMAstring · options ["SMA", "EMA", "HMA"]Long_Moving_Average_Line
Period50intLong_Moving_Average_Line
Take profit / Stop Loss
Target profit (%)1.5float · step 0.05TP_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.15intSL_line
Safety orders
Max safety trades count10int · max 10SL_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.4float · step 0.01pd line 55
Safety order volume scale1.8float · step 0.01line 85
Safety order step scale1.19float · step 0.01ss line 55

What it calculates

  • SMA / EMAclose, Period (5) · chosen by Short Moving AverageShort_Moving_Average_Line · line 45
  • SMA / EMAclose, Period (50) · chosen by Long Moving AverageLong_Moving_Average_Line · line 49
  • Crossover / CrossunderShort_Moving_Average_Line, Long_Moving_Average_Line · chosen by Entry at Cross Over / UnderBase_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.

closecloseprice dataShort_Moving_AverageShort Moving Averagesetting · SMAShort_PeriodPeriodsetting · 5Long_Moving_AverageLong Moving Averagesetting · HMALong_PeriodPeriodsetting · 50Triger_TypeEntry at Cross Over / U…setting · OverPrice_deviationPrice deviation to open…setting · 0.4Safety_order_step_scaleSafety order step scalesetting · 1.19Target_profitTarget profit (%)setting · 1.5Max_safety_trades_countMax safety trades countsetting · 10Stop_LossStop Loss (%)setting · 15Profit_currencyProfit currencysetting · Quote (USDT)highhighprice datatimetimeprice dataShort_Moving_Average_LineSMA / EMA→ Short_Moving_Average_Line ·…Long_Moving_Average_LineSMA / EMA→ Long_Moving_Average_Line · …Base_order_ConditionCrossover / Crossunder→ Base_order_Condition · by E…pdpdvaluessssvalueTP_lineTP_linevalueSL_lineSL_linevaluecurrencycurrencyvaluei_s, equityi_s · equity2 valuesbot_use, bot_devbot_use · bot_dev2 valuesbot_avabot_avavaluelabellabelvaluestatus_nonestatus_noneconditionstatus_long, status_long_offset, status_short, status_increasestatus_long · status_lo…4 conditionsday_labelColourday_labelentry:Base orderOpen Base orderstrategy.entryentry:'Safety order' + i_sOpen 'Safety order' + i…strategy.entrycancel:'Safety order' + i_scancel 'Safety order' +…strategy.cancelexit:TP/SLexit TP/SLstrategy.exitplot:86Short MAplotplot:87Long MAplotplot:88Safety order1plotplot:89Safety order2plotplot:90Safety order3plotplot:91Safety order4plotplot:92Safety order5plotplot:93Safety order6plotplot:94Safety order7plotplot:95Safety order8plotplot:96Safety order9plotplot:97Safety order10plotplot:98Take Profitplotplot:99Safetyplot

Order rules

OrderFires whenBy defaultLine
Open Base order longBase_order_Condition and strategy.opentrades == 0On105
Open 'Safety order' + i_s long(strategy.opentrades <= i) and strategy.position_size > 0 and not(strategy.position_size == 0)On109
cancel 'Safety order' + i_sstatus_nonestrategy.position_size == 0On114
Exit TP/SL stop and limitevery barOn115
Exit TP/SL stop and limitevery barOn116

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.

17/17trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+2.6%+102.5%6363%6.632.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.5%+5.5%6772%26.600.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+2.9%+9.8%5767%6.9512.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.7%+8.4%5680%20.160.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+3.8%+16.7%5857%9.034.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.8%+21.5%8465%10.000.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−10.7%+148.3%11263%0.3415.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.4%+17.1%4879%38.550.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 barsTradesWonP&L
Rising market2767%$85.83
Sideways market2060%$73.14
Falling market1663%$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.

0%1%
All 63 trades
SideEntryExitBarsP&L
long18 May 2024 66,915.2020 May 2024 67,918.902$0.15
long20 May 2024 66,274.0020 May 2024 71,446.600$1.56
long20 May 2024 66,274.0020 May 2024 71,446.600$2.80
long19 Jul 2024 66,660.0021 Jul 2024 67,659.902$0.15
long21 Jul 2024 66,393.4021 Jul 2024 68,165.300$0.52
long21 Jul 2024 66,076.1021 Jul 2024 68,165.300$1.11
long24 Aug 2024 64,157.0029 Aug 2024 61,005.705−$0.49
long26 Aug 2024 63,900.4029 Aug 2024 61,005.703−$0.91
long26 Aug 2024 63,595.0029 Aug 2024 61,005.703−$1.46
long26 Aug 2024 63,231.6029 Aug 2024 61,005.703−$2.26
long27 Aug 2024 62,799.1029 Aug 2024 61,005.702−$3.35
long27 Aug 2024 62,284.5029 Aug 2024 61,005.702−$4.31
long27 Aug 2024 61,672.1029 Aug 2024 61,005.702−$4.08
long27 Aug 2024 60,943.3029 Aug 2024 61,005.702$0.54
long27 Aug 2024 60,076.1029 Aug 2024 61,005.702$17.88
long27 Aug 2024 59,044.1029 Aug 2024 61,005.702$68.39
long17 Sep 2024 60,314.0018 Sep 2024 61,760.001$0.24
long5 Jan 2025 98,363.606 Jan 2025 102,236.001$0.39
long7 Jan 2025 97,970.1010 Jan 2025 94,937.603−$0.60
long7 Jan 2025 97,501.9010 Jan 2025 94,937.603−$0.91
long7 Jan 2025 96,944.8010 Jan 2025 94,937.603−$1.28
long7 Jan 2025 96,281.7010 Jan 2025 94,937.603−$1.56
long8 Jan 2025 96,281.7010 Jan 2025 94,937.602−$1.64
long8 Jan 2025 95,492.7010 Jan 2025 94,937.602−$1.24
long8 Jan 2025 94,553.8010 Jan 2025 94,937.602$1.42
long8 Jan 2025 93,436.5010 Jan 2025 94,937.602$10.40
long9 Jan 2025 92,106.9010 Jan 2025 94,937.601$36.22
long17 Jan 2025 104,077.0019 Jan 2025 105,639.002$0.15
long19 Jan 2025 103,661.0020 Jan 2025 102,495.001−$0.23
long19 Jan 2025 103,166.0020 Jan 2025 102,495.001−$0.24
long19 Jan 2025 102,576.0020 Jan 2025 102,495.001−$0.06
long19 Jan 2025 101,875.0020 Jan 2025 102,495.001$0.67
long19 Jan 2025 101,040.0020 Jan 2025 102,495.001$2.88
long19 Jan 2025 100,046.0020 Jan 2025 102,495.001$8.78
long20 Jan 2025 100,046.0020 Jan 2025 102,260.000$8.18
long21 Jan 2025 102,260.0021 Jan 2025 106,144.000$0.76
long21 Jan 2025 102,260.0021 Jan 2025 106,144.000$1.36
long21 Jan 2025 102,260.0021 Jan 2025 106,144.000$2.45
long21 Jan 2025 101,875.0021 Jan 2025 106,144.000$4.85
long21 Jan 2025 101,040.0021 Jan 2025 106,144.000$10.44
long16 Apr 2025 84,030.4019 Apr 2025 85,290.803$0.15
long27 Jun 2025 107,048.0030 Jun 2025 108,653.003$0.15
long13 Sep 2025 115,918.0016 Sep 2025 116,894.003$0.08
long15 Sep 2025 115,268.0016 Sep 2025 116,894.001$0.28
long15 Sep 2025 114,903.0016 Sep 2025 116,894.001$0.61
long1 Oct 2025 118,595.002 Oct 2025 120,529.001$0.16
long4 Jan 2026 91,529.705 Jan 2026 93,859.701$0.25
long16 Mar 2026 74,884.7020 Mar 2026 71,182.904−$0.50
long18 Mar 2026 73,909.4020 Mar 2026 71,182.902−$0.74
long18 Mar 2026 73,909.4020 Mar 2026 71,182.902−$1.34
long18 Mar 2026 73,804.5020 Mar 2026 71,182.902−$2.31
long18 Mar 2026 73,299.7020 Mar 2026 71,182.902−$3.36
long18 Mar 2026 72,699.1020 Mar 2026 71,182.902−$4.35
long18 Mar 2026 71,984.3020 Mar 2026 71,182.902−$4.17
long18 Mar 2026 71,133.6020 Mar 2026 71,182.902$0.32
long19 Mar 2026 70,121.4020 Mar 2026 71,182.901$18.00
long19 Mar 2026 68,916.8020 Mar 2026 71,182.901$69.67
long7 Apr 2026 71,924.209 Apr 2026 73,003.102$0.15
long9 Apr 2026 71,069.9010 Apr 2026 72,036.301$0.27
long9 Apr 2026 71,069.9010 Apr 2026 72,036.301$0.48
long9 Apr 2026 70,886.8010 Apr 2026 72,036.301$1.04
long17 Jul 2026 63,931.7019 Jul 2026 64,890.702$0.15
long19 Aug 2026 69,334.8020 Aug 2026 73,025.101$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.

ScriptSharesTypeNetTradesMax drawdown
3Commas Visible DCA Strategy this page—v5 strategy+2.6%632.0%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 133 msYes 1,000 bars in 438 msNot measured
PineTSNot testedNot testedNot 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)