Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Strategy Template[Benson]

A Pine Script v4 strategy built on Crossunder or SMA (close,7, close,14) and Crossover or SMA (close,7, close,14). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays no commission. 13 settings; defaults include backtest_year 2019, backtest_month 01 and backtest_day 01.

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 Strategy Template[Benson] repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 25 of 25 trades.
How did Strategy Template[Benson] do on BTCUSDT 1D with default settings?
+31.83%
From 26 Jan 2024 to 21 Oct 2026, over 84 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Strategy Template[Benson] be converted to Pine Script v5?
No
The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
Does Strategy Template[Benson] use a stop loss?
Yes
strategy.exit sets a stop on line 24, 27.
Does Strategy Template[Benson] run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 46 ms, in the browser.

BTCUSDT · 1D · default settings

  • Net Profit
  • Winning trade
  • Losing trade
  • Exit at a stop or limit price
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctStop exit at 67,820.60Stop exit at 63,420.00Stop exit at 60,672.00Stop exit at 61,577.50Stop exit at 65,235.20Limit exit at 67,540.00Stop exit at 66,773.00Stop exit at 61,498.30Limit exit at 59,013.80Stop exit at 94,545.10Limit exit at 104,723.00Limit exit at 96,644.40Stop exit at 96,182.00Stop exit at 80,734.50Stop exit at 82,550.00Stop exit at 104,887.00Stop exit at 117,951.00Stop exit at 112,873.00Limit exit at 111,999.00Stop exit at 106,583.00Stop exit at 86,432.10Limit exit at 87,237.10Stop exit at 87,648.20Stop exit at 89,559.70Stop exit at 77,457.70Stop exit at 62,734.60Limit exit at 63,915.00Stop exit at 63,043.60Stop exit at 77,225.70Stop exit at 82,988.40Net Profit$129,108$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits, and squares exits filled at a stop or limit price. Lines are what the script plots.
Net profit
+31.83%
$31,825.90
Buy and hold
+102.5%
same period
Closed trades
84
34 won · 50 lost
Profitable
40.5%
of closed trades
Profit factor
1.15
gross profit ÷ gross loss
Max drawdown
42.86%
−$42,864.20

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 22, 23, 25, 26. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 29

    transp = on line 29. v5 folds the transparency into the colour with color.new(c, transp).

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames crossunder → ta.crossunder, sma → ta.sma, crossover → ta.crossover.
  • 4 strategy calls use the when = argument (line 22, 23, 25, 26). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Differs

Trades differ: 84 before, 84 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 1: //@version=4 → //@version=5
  • Line 5: input(type = input.integer) → input.int()
  • Line 6: input(type = input.integer) → input.int()
  • Line 7: input(type = input.integer) → input.int()
  • Line 9: input(type = input.bool) → input.bool()
  • Line 10: input(type = input.bool) → input.bool()
15 more edits
  • Line 11: input(type = input.float) → input.float()
  • Line 12: input(type = input.float) → input.float()
  • Line 13: input(type = input.float) → input.float()
  • Line 14: input(type = input.float) → input.float()
  • Line 15: input(type = input.float) → input.float()
  • Line 16: input(type = input.float) → input.float()
  • Line 17: input(type = input.float) → input.float()
  • Line 18: input(type = input.float) → input.float()
  • Line 20: crossunder → ta.crossunder
  • Line 20: sma → ta.sma
  • Line 20: sma → ta.sma
  • Line 21: crossover → ta.crossover
  • Line 21: sma → ta.sma
  • Line 21: sma → ta.sma
  • Line 29: transp = 50 → color.new(net_profit >= 0 ? #26A69A : color.red, 50)
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯strategy("Strategy Template[Benson]", pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)-backtest_year = input(2019, type=input.integer, title='backtest_year')+backtest_year = input.int(2019, title='backtest_year')-backtest_month = input(01, type=input.integer, title='backtest_month', minval=1, maxval=12)+backtest_month = input.int(01, title='backtest_month', minval=1, maxval=12)-backtest_day = input(01, type=input.integer, title='backtest_day', minval=1, maxval=31)+backtest_day = input.int(01, title='backtest_day', minval=1, maxval=31)start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00)-stop_loss_and_tp = input(title="Enable Stop Loss and Take Profit", type=input.bool, defval=true)+stop_loss_and_tp = input.bool(title="Enable Stop Loss and Take Profit", defval=true)-trail_stop = input(title="Enable Trail Stop", type=input.bool, defval=true)+trail_stop = input.bool(title="Enable Trail Stop", defval=true)-buy_stop_loss = input(0.2, type=input.float, title='buy_stop_loss')+buy_stop_loss = input.float(0.2, title='buy_stop_loss')-sell_stop_loss = input(0.1, type=input.float, title='sell_stop_loss')+sell_stop_loss = input.float(0.1, title='sell_stop_loss')-buy_tp = input(0.4, type=input.float, title='buy_tp')+buy_tp = input.float(0.4, title='buy_tp')-sell_tp =input(0.2, type=input.float, title='sell_tp')+sell_tp =input.float(0.2, title='sell_tp')-trail_stop_long = input(1.1, type=input.float, title='trail_stop_long')+trail_stop_long = input.float(1.1, title='trail_stop_long')-trail_stop_short = input(0.9, type=input.float, title='trail_stop_short')+trail_stop_short = input.float(0.9, title='trail_stop_short')-trail_stop_long_offset = input(0.05, type=input.float, title='trail_stop_long_offset')+trail_stop_long_offset = input.float(0.05, title='trail_stop_long_offset')-trail_stop_short_offset = input(0.05, type=input.float, title='trail_stop_short_offset')+trail_stop_short_offset = input.float(0.05, title='trail_stop_short_offset')// you can set your own logic here-shortCondition = crossunder(sma(close,7),sma(close,14))+shortCondition = ta.crossunder(ta.sma(close,7),ta.sma(close,14))-longCondition = crossover(sma(close,7),sma(close,14))+longCondition = ta.crossover(ta.sma(close,7),ta.sma(close,14))strategy.entry("Buy", strategy.long, when=longCondition and time >= start_time )⋯net_profit = strategy.netprofit + strategy.openprofit-plot(net_profit, title="Net Profit", linewidth=2, style=plot.style_area, transp=50, color=net_profit >= 0 ? #26A69A : color.red)+plot(net_profit, title="Net Profit", linewidth=2, style=plot.style_area, color=color.new(net_profit >= 0 ? #26A69A : color.red, 50))

Clean v5

Verified

Same 84 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 22: when = longCondition and time >= start_time → if block
  • Line 23: when = shortCondition → if block
  • Line 25: when = shortCondition and time>=start_time → if block
  • Line 26: when = longCondition → if block
⋯longCondition = ta.crossover(ta.sma(close,7),ta.sma(close,14))-strategy.entry("Buy", strategy.long, when=longCondition and time >= start_time )+if longCondition and time >= start_time+    strategy.entry("Buy", strategy.long )-strategy.close("Buy", when=shortCondition)+if shortCondition+    strategy.close("Buy")strategy.exit("Close Buy","Buy", limit= stop_loss_and_tp?strategy.position_avg_price * (1+buy_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1-buy_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_long:na,trail_offset=trail_stop?-strategy.position_avg_price *trail_stop_long_offset:na)-strategy.entry("Sell", strategy.short, when=shortCondition and time>=start_time)+if shortCondition and time>=start_time+    strategy.entry("Sell", strategy.short)-strategy.close("Sell", when=longCondition)+if longCondition+    strategy.close("Sell")strategy.exit("Close Sell","Sell", limit= stop_loss_and_tp?strategy.position_avg_price * (1-sell_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1+sell_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_short:na,trail_offset=trail_stop?strategy.position_avg_price *trail_stop_short_offset:na)⋯

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: 84 before, 65 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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
backtest_year2019int (written input.integer)start_time
backtest_month01int (written input.integer) · min 1 · max 12start_time
backtest_day01int (written input.integer) · min 1 · max 31start_time
Enable Stop Loss and Take Profittrueboolexit Close Buy exit Close Sell
Enable Trail Stoptrueboolexit Close Buy exit Close Sell
buy_stop_loss0.2floatexit Close Buy
sell_stop_loss0.1floatexit Close Sell
buy_tp0.4floatexit Close Buy
sell_tp0.2floatexit Close Sell
trail_stop_long1.1floatexit Close Buy
trail_stop_short0.9floatexit Close Sell
trail_stop_long_offset0.05floatexit Close Buy
trail_stop_short_offset0.05floatexit Close Sell

What it calculates

  • Crossunder / SMA (crossunder, ta.crossunder in v5)sma(close,7), sma(close,14)shortCondition · line 20
  • Crossover / SMA (crossover, ta.crossover in v5)sma(close,7), sma(close,14)longCondition · line 21

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 databacktest_yearbacktest_yearsetting · 2019backtest_monthbacktest_monthsetting · 01backtest_daybacktest_daysetting · 01timetimeprice datashortConditionCrossunder / SMA→ shortConditionlongConditionCrossover / SMA→ longConditionstart_timestart_timevaluenet_profitnet_profitvalueentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeexit:Close Buyexit Close Buystrategy.exitentry:SellOpen Sellstrategy.entryclose:SellClose Sellstrategy.closeexit:Close Sellexit Close Sellstrategy.exitplot:29Net Profitplot

Order rules

OrderFires whenBy defaultLine
Open Buy longlongCondition and time >= start_timeOn22
Close BuyshortConditionOn23
Exit Close Buy stop and limitevery barOn24
Open Sell shortshortCondition and time>=start_timeOn25
Close SelllongConditionOn26
Exit Close Sell stop and limitevery barOn27

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.

25/25trades 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 timingOrders fill at the next bar's open, after the signal bar has closed.

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+31.8%+102.5%8440%1.1542.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−3.8%+5.5%7937%0.9522.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−40.1%+9.8%8341%0.8469.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−17.2%+8.4%8532%0.8441.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+110.2%+16.7%8152%1.2941.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+16.6%+21.5%7337%1.1333.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+21.7%+148.3%7646%1.1154.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+16.3%+17.1%7132%1.259.6%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 market3327%−$47,486.70
Sideways market3355%$55,521.80
Falling market1839%$23,790.80

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

54.4%

The 95th percentile of the worst drawdown when the same 84 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 27.7% to 54.4%; the tick is what actually happened, 42.2%. Order luck alone moves it this much.

0%63%
All 84 trades
SideEntryExitBarsP&L
short20 Mar 2024 61,937.4021 Mar 2024 68,131.201−$10,000.00
long29 Mar 2024 70,780.606 Apr 2024 67,820.60 stop8−$3,763.70
short6 Apr 2024 67,820.6011 Apr 2024 70,631.105−$3,573.58
long11 Apr 2024 70,631.1016 Apr 2024 63,420.00 stop5−$8,439.46
short16 Apr 2024 63,420.0016 Apr 2024 63,455.300−$41.34
long26 Apr 2024 64,498.301 May 2024 60,672.00 stop5−$4,400.79
short1 May 2024 60,672.001 May 2024 56,585.100$4,700.54
long10 May 2024 63,074.0015 May 2024 61,577.50 stop5−$1,767.17
short15 May 2024 61,577.5016 May 2024 66,206.501−$5,466.23
long16 May 2024 66,206.5017 May 2024 65,235.20 stop1−$986.58
short17 May 2024 65,235.2018 May 2024 67,024.001−$1,816.94
long18 May 2024 67,024.001 Jun 2024 67,540.00 limit14$496.15
short1 Jun 2024 67,540.006 Jun 2024 71,108.005−$3,430.68
long6 Jun 2024 71,108.0014 Jun 2024 66,773.00 stop8−$3,749.87
short14 Jun 2024 66,773.0024 Jun 2024 58,435.4010$7,212.25
long16 Jul 2024 64,724.103 Aug 2024 61,498.30 stop18−$3,238.10
short3 Aug 2024 61,498.305 Aug 2024 49,198.702$12,346.90
long15 Aug 2024 58,683.4021 Aug 2024 59,013.80 limit6$417.11
short21 Aug 2024 59,013.8023 Aug 2024 60,375.802−$1,719.41
long23 Aug 2024 60,375.8023 Aug 2024 64,944.700$5,507.46
short1 Sep 2024 58,974.006 Sep 2024 52,579.505$8,488.55
long15 Sep 2024 59,993.0027 Sep 2024 66,022.3012$8,720.90
short4 Oct 2024 60,752.7014 Oct 2024 62,870.0010−$3,328.14
long14 Oct 2024 62,870.0020 Oct 2024 69,188.506$9,262.87
short28 Oct 2024 68,021.7030 Oct 2024 72,736.402−$7,030.36
long30 Oct 2024 72,736.4011 Nov 2024 80,370.0012$9,907.20
short2 Dec 2024 97,185.204 Dec 2024 95,849.702$1,433.35
long4 Dec 2024 95,849.7017 Dec 2024 106,059.0013$11,262.50
short23 Dec 2024 95,186.306 Jan 2025 98,363.6014−$3,905.59
long6 Jan 2025 98,363.6013 Jan 2025 94,545.10 stop7−$4,390.53
short13 Jan 2025 94,545.1017 Jan 2025 104,000.004−$10,870.70
long18 Jan 2025 104,077.0031 Jan 2025 104,723.00 limit13$606.76
short31 Jan 2025 104,723.003 Feb 2025 91,283.403$12,633.70
long19 Feb 2025 95,671.7020 Feb 2025 96,644.40 limit1$1,129.24
short20 Feb 2025 96,644.4021 Feb 2025 98,305.001−$1,928.04
long21 Feb 2025 98,305.0022 Feb 2025 96,182.00 stop1−$2,381.60
short22 Feb 2025 96,182.0025 Feb 2025 86,099.103$11,311.00
long9 Mar 2025 86,222.5010 Mar 2025 80,734.50 stop1−$7,587.45
short10 Mar 2025 80,734.5010 Mar 2025 77,503.000$4,467.68
long21 Mar 2025 84,223.401 Apr 2025 82,550.00 stop11−$2,306.47
short1 Apr 2025 82,550.0016 Apr 2025 83,644.0015−$1,507.88
long16 Apr 2025 83,644.0023 Apr 2025 93,443.007$13,153.00
short1 Jun 2025 104,592.0011 Jun 2025 110,274.0010−$6,814.46
long11 Jun 2025 110,274.0019 Jun 2025 104,887.00 stop8−$5,794.94
short19 Jun 2025 104,887.0028 Jun 2025 107,048.009−$2,324.16
long28 Jun 2025 107,048.0011 Jul 2025 117,806.0013$11,104.50
short25 Jul 2025 118,341.0028 Jul 2025 119,416.003−$1,104.15
long28 Jul 2025 119,416.0030 Jul 2025 117,951.00 stop2−$1,478.03
short30 Jul 2025 117,951.0011 Aug 2025 119,294.0012−$1,355.64
long11 Aug 2025 119,294.0020 Aug 2025 112,873.00 stop9−$6,333.35
short20 Aug 2025 112,873.008 Sep 2025 111,137.0019$1,711.82
long8 Sep 2025 111,137.0024 Sep 2025 111,999.00 limit16$876.18
short24 Sep 2025 111,999.003 Oct 2025 120,529.009−$8,676.44
long3 Oct 2025 120,529.003 Oct 2025 123,255.000$2,379.57
short13 Oct 2025 114,959.0027 Oct 2025 114,559.0014$373.89
long27 Oct 2025 114,559.004 Nov 2025 106,583.00 stop8−$7,519.04
short4 Nov 2025 106,583.004 Nov 2025 99,001.600$7,146.73
long1 Dec 2025 90,360.0016 Dec 2025 86,432.10 stop15−$4,678.17
short16 Dec 2025 86,432.1026 Dec 2025 87,225.3010−$944.69
long26 Dec 2025 87,225.3030 Dec 2025 87,237.10 limit4$13.87
short30 Dec 2025 87,237.1031 Dec 2025 88,485.501−$1,459.77
long31 Dec 2025 88,485.501 Jan 2026 87,648.20 stop1−$951.45
short1 Jan 2026 87,648.203 Jan 2026 89,995.102−$2,666.92
long3 Jan 2026 89,995.1023 Jan 2026 89,559.70 stop20−$469.02
short23 Jan 2026 89,559.7031 Jan 2026 75,764.708$14,858.30
long4 Mar 2026 68,338.0017 Mar 2026 75,206.0013$11,187.80
short24 Mar 2026 70,906.408 Apr 2026 71,924.2015−$1,758.45
long8 Apr 2026 71,924.2022 Apr 2026 79,152.6014$12,135.40
short4 May 2026 78,568.606 May 2026 80,905.502−$3,952.56
long6 May 2026 80,905.5018 May 2026 77,457.70 stop12−$5,494.60
short18 May 2026 77,457.702 Jun 2026 66,231.7015$17,889.90
long16 Jun 2026 66,328.7024 Jun 2026 62,734.60 stop8−$7,658.20
short24 Jun 2026 62,734.6024 Jun 2026 59,135.900$7,667.87
long6 Jul 2026 63,650.0029 Jul 2026 63,915.00 limit23$588.42
short29 Jul 2026 63,915.009 Aug 2026 64,962.6011−$2,326.25
long9 Aug 2026 64,962.6015 Aug 2026 63,043.60 stop6−$4,123.89
short15 Aug 2026 63,043.6019 Aug 2026 69,347.904−$13,547.70
long20 Aug 2026 69,334.8022 Aug 2026 78,338.002$15,832.70
short4 Sep 2026 81,270.405 Sep 2026 79,660.801$2,728.43
long5 Sep 2026 79,660.8012 Sep 2026 77,225.70 stop7−$4,294.48
short12 Sep 2026 77,225.7021 Sep 2026 81,178.009−$6,970.29
long21 Sep 2026 81,178.0022 Sep 2026 86,620.001$8,662.98
short4 Oct 2026 84,753.606 Oct 2026 85,766.902−$1,648.57
long6 Oct 2026 85,766.9011 Oct 2026 82,988.40 stop5−$4,413.64

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
Strategy Template[Benson] this page—v4 strategy+31.8%8442.9%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msYes 1,000 bars in 46 msNot measured
PineTSNo v5 and v6 only—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. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © bensonsuntwstrategy("Strategy Template[Benson]", pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)backtest_year = input(2019, type=input.integer, title='backtest_year')backtest_month = input(01, type=input.integer, title='backtest_month', minval=1, maxval=12)backtest_day = input(01, type=input.integer, title='backtest_day', minval=1, maxval=31)start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00)stop_loss_and_tp = input(title="Enable Stop Loss and Take Profit", type=input.bool, defval=true)trail_stop = input(title="Enable Trail Stop", type=input.bool, defval=true)buy_stop_loss = input(0.2, type=input.float, title='buy_stop_loss')sell_stop_loss = input(0.1, type=input.float, title='sell_stop_loss')buy_tp = input(0.4, type=input.float, title='buy_tp')sell_tp =input(0.2, type=input.float, title='sell_tp')trail_stop_long = input(1.1, type=input.float, title='trail_stop_long')trail_stop_short = input(0.9, type=input.float, title='trail_stop_short')trail_stop_long_offset = input(0.05, type=input.float, title='trail_stop_long_offset')trail_stop_short_offset = input(0.05, type=input.float, title='trail_stop_short_offset')// you can set your own logic hereshortCondition = crossunder(sma(close,7),sma(close,14))longCondition = crossover(sma(close,7),sma(close,14))strategy.entry("Buy", strategy.long, when=longCondition and time >= start_time )strategy.close("Buy", when=shortCondition)strategy.exit("Close Buy","Buy", limit= stop_loss_and_tp?strategy.position_avg_price * (1+buy_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1-buy_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_long:na,trail_offset=trail_stop?-strategy.position_avg_price *trail_stop_long_offset:na)strategy.entry("Sell", strategy.short, when=shortCondition and time>=start_time)strategy.close("Sell", when=longCondition)strategy.exit("Close Sell","Sell", limit= stop_loss_and_tp?strategy.position_avg_price * (1-sell_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1+sell_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_short:na,trail_offset=trail_stop?strategy.position_avg_price *trail_stop_short_offset:na)net_profit = strategy.netprofit + strategy.openprofitplot(net_profit, title="Net Profit", linewidth=2, style=plot.style_area, transp=50, color=net_profit >= 0 ? #26A69A : color.red)