Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Chirag Strategy SMA with StopLoss

A Pine Script v4 strategy built on Crossover or SMA (close, 10, close, 13). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 2 settings; defaults include Long Stop Loss (%) 1 and Short Stop Loss (%) 1.

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 Chirag Strategy SMA with StopLoss repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 34 of 34 trades.
How did Chirag Strategy SMA with StopLoss do on BTCUSDT 1D with default settings?
−19.36%
From 26 Jan 2024 to 21 Oct 2026, over 91 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Chirag Strategy SMA with StopLoss be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Chirag Strategy SMA with StopLoss use a stop loss?
Yes
strategy.exit sets a stop on line 23, 25.
Does Chirag Strategy SMA with StopLoss run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 25 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Long StopLoss
  • Short StopLoss
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$80,635$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. Lines are what the script plots.
Net profit
−19.36%
−$19,360.40
Buy and hold
+102.5%
same period
Closed trades
91
14 won · 77 lost
Profitable
15.4%
of closed trades
Profit factor
0.80
gross profit ÷ gross loss
Max drawdown
42.76%
−$48,201.30

One run with the author's default settings, $100,000 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.

  • Check

    No commission

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

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

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 sma → ta.sma, crossover → ta.crossover.

v4 → v5

VerifiedDownload the v5 script

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

  • Line 3: //@version=4 → //@version=5
  • Line 5: sma → ta.sma
  • Line 6: sma → ta.sma
  • Line 7: crossover → ta.crossover
  • Line 7: sma → ta.sma
  • Line 7: sma → ta.sma
5 more edits
  • Line 8: crossover → ta.crossover
  • Line 8: sma → ta.sma
  • Line 8: sma → ta.sma
  • Line 10: input(type = input.float) → input.float()
  • Line 11: input(type = input.float) → input.float()
⋯// © chiragchopra91-//@version=4+//@version=5strategy(title='Chirag Strategy SMA', shorttitle='CHIRAGSMA', overlay=true)-plot(sma(close,10), color=color.green, linewidth=2)+plot(ta.sma(close,10), color=color.green, linewidth=2)-plot(sma(close,13), color=color.red, linewidth=2)+plot(ta.sma(close,13), color=color.red, linewidth=2)-longCondition = crossover(sma(close, 10), sma(close, 13))+longCondition = ta.crossover(ta.sma(close, 10), ta.sma(close, 13))-shortCondition = crossover(sma(close, 13), sma(close, 10))+shortCondition = ta.crossover(ta.sma(close, 13), ta.sma(close, 10))// Set stop loss level with input options-longLossPerc = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01+longLossPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=1) * 0.01-shortLossPerc = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01+shortLossPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=1) * 0.01longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)⋯

Clean v5

Verified

Nothing to change.

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: 91 before, 78 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.

⋯// © chiragchopra91-//@version=5+//@version=6strategy(title='Chirag Strategy SMA', shorttitle='CHIRAGSMA', overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
Long Stop Loss (%)1float · min 0.0 · step 0.1longStopPrice
Short Stop Loss (%)1float · min 0.0 · step 0.1shortStopPrice

What it calculates

  • Crossover / SMA (crossover, ta.crossover in v5)sma(close, 10), sma(close, 13)longCondition · line 7
  • Crossover / SMA (crossover, ta.crossover in v5)sma(close, 13), sma(close, 10)shortCondition · line 8

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 datalongLossPercLong Stop Loss (%)setting · 1shortLossPercShort Stop Loss (%)setting · 1longConditionCrossover / SMA→ longConditionshortConditionCrossover / SMA→ shortConditionlongStopPricelongStopPricevalueshortStopPriceshortStopPricevalueclose:ShortClose Shortstrategy.closeentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryexit:LONG SLexit LONG SLstrategy.exitexit:SHORT SLexit SHORT SLstrategy.exitplot:5plotplotplot:6plotplotplot:28Long StopLossplotplot:29Short StopLossplot

Order rules

OrderFires whenBy defaultLine
Close Shortstrategy.position_size < 0On16
Open Long longlongConditionOn17
Close Longstrategy.position_size > 0On20
Open Short shortshortConditionOn21
Exit LONG SL stopstrategy.position_size > 0On23
Exit SHORT SL stopstrategy.position_size < 0On25

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.

34/34trades 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−19.4%+102.5%9115%0.8042.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7.6%+5.5%9527%1.1811.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.1%+9.8%11215%1.021.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.3%+8.4%10126%0.800.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%10215%0.730.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%9923%0.650.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.2%+148.3%10421%0.770.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%9329%1.010.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 market339%−$27,078.70
Sideways market2924%$14,521.10
Falling market2914%−$6,802.71

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

How bad could the drawdown be?

48.8%

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

0%56%
All 91 trades
SideEntryExitBarsP&L
short22 Mar 2024 65,501.3024 Mar 2024 66,156.302−$655.02
long30 Mar 2024 69,850.501 Apr 2024 69,152.002−$698.51
short6 Apr 2024 67,820.607 Apr 2024 68,896.001−$1,075.37
long13 Apr 2024 67,116.5014 Apr 2024 63,924.501−$3,192.00
short17 Apr 2024 63,793.4019 Apr 2024 64,431.302−$637.94
long26 Apr 2024 64,498.3027 Apr 2024 63,770.001−$728.33
short2 May 2024 58,365.003 May 2024 59,060.601−$695.63
long12 May 2024 60,826.0016 May 2024 66,206.504$5,380.52
short16 May 2024 66,206.5017 May 2024 66,868.601−$662.07
long19 May 2024 66,915.2020 May 2024 66,246.001−$669.16
short1 Jun 2024 67,540.002 Jun 2024 68,215.401−$675.41
long8 Jun 2024 69,355.6011 Jun 2024 68,662.003−$693.56
short15 Jun 2024 66,044.0016 Jun 2024 66,704.401−$660.44
long16 Jul 2024 64,724.1017 Jul 2024 64,076.801−$647.25
short1 Aug 2024 64,628.002 Aug 2024 65,354.001−$726.01
long16 Aug 2024 57,541.1020 Aug 2024 59,438.504$1,897.45
short20 Aug 2024 59,438.5021 Aug 2024 60,032.901−$594.39
long24 Aug 2024 64,037.2026 Aug 2024 63,396.902−$640.38
short3 Sep 2024 59,132.1013 Sep 2024 59,723.4010−$591.33
long16 Sep 2024 59,132.0017 Sep 2024 58,214.001−$918.01
short5 Oct 2024 62,086.006 Oct 2024 62,706.901−$620.86
long13 Oct 2024 63,206.2014 Oct 2024 62,574.201−$632.07
short3 Dec 2024 95,840.604 Dec 2024 96,799.001−$958.41
long7 Dec 2024 99,740.808 Dec 2024 98,743.401−$997.41
short24 Dec 2024 94,881.5025 Dec 2024 98,663.601−$3,782.11
long8 Jan 2025 96,954.609 Jan 2025 95,060.601−$1,893.99
short14 Jan 2025 94,536.1015 Jan 2025 96,560.901−$2,024.74
long20 Jan 2025 101,332.0021 Jan 2025 100,318.001−$1,013.32
short2 Feb 2025 100,636.003 Feb 2025 101,642.001−$1,006.36
long18 Feb 2025 95,780.0023 Feb 2025 96,551.005$771.00
short23 Feb 2025 96,551.0010 Mar 2025 80,734.5015$15,816.50
long10 Mar 2025 80,734.5011 Mar 2025 78,595.901−$2,138.62
short13 Mar 2025 83,680.1014 Mar 2025 84,516.901−$836.81
long21 Mar 2025 84,223.4029 Mar 2025 83,381.108−$842.24
short4 Apr 2025 83,213.105 Apr 2025 84,045.201−$832.14
long17 Apr 2025 84,030.402 Jun 2025 105,643.0046$21,612.50
short2 Jun 2025 105,643.003 Jun 2025 106,699.001−$1,056.43
long11 Jun 2025 110,274.0012 Jun 2025 108,645.001−$1,629.26
short20 Jun 2025 104,659.0023 Jun 2025 105,705.003−$1,046.59
long30 Jun 2025 108,357.001 Jul 2025 107,147.001−$1,210.42
short25 Jul 2025 118,341.0027 Jul 2025 119,524.002−$1,183.41
long31 Jul 2025 117,840.001 Aug 2025 115,764.001−$2,076.22
short2 Aug 2025 113,298.003 Aug 2025 114,431.001−$1,132.98
long12 Aug 2025 118,686.0014 Aug 2025 117,499.002−$1,186.86
short22 Aug 2025 112,500.0023 Aug 2025 116,936.001−$4,436.00
long10 Sep 2025 111,546.0024 Sep 2025 111,999.0014$452.42
short24 Sep 2025 111,999.0025 Sep 2025 113,307.001−$1,308.21
long4 Oct 2025 122,232.007 Oct 2025 121,010.003−$1,222.33
short14 Oct 2025 115,166.0027 Oct 2025 116,318.0013−$1,151.66
long28 Oct 2025 114,108.0029 Oct 2025 112,898.001−$1,209.21
short5 Nov 2025 101,497.006 Nov 2025 103,885.001−$2,387.93
long2 Dec 2025 86,286.009 Dec 2025 90,634.407$4,348.34
short9 Dec 2025 90,634.4010 Dec 2025 92,678.801−$2,044.46
long11 Dec 2025 92,015.4012 Dec 2025 91,095.201−$920.16
short15 Dec 2025 88,172.2017 Dec 2025 89,053.902−$881.73
long18 Dec 2025 86,243.2019 Dec 2025 85,516.401−$726.82
short19 Dec 2025 85,516.4020 Dec 2025 88,136.901−$2,620.54
long27 Dec 2025 87,369.601 Jan 2026 87,648.205$278.65
short1 Jan 2026 87,648.202 Jan 2026 88,839.101−$1,190.84
long4 Jan 2026 90,628.008 Jan 2026 89,721.704−$906.29
short17 Jan 2026 95,550.9018 Jan 2026 95,147.801$403.17
long18 Jan 2026 95,147.8019 Jan 2026 93,673.101−$1,474.63
short25 Jan 2026 89,225.3028 Jan 2026 90,117.603−$892.26
long18 Feb 2026 67,503.5019 Feb 2026 66,461.001−$1,042.52
short19 Feb 2026 66,461.0020 Feb 2026 67,125.601−$664.61
long23 Feb 2026 67,643.4024 Feb 2026 64,656.001−$2,987.38
short25 Feb 2026 64,058.2026 Feb 2026 67,988.001−$3,929.89
long6 Mar 2026 70,891.007 Mar 2026 68,114.001−$2,777.00
short15 Mar 2026 71,211.9016 Mar 2026 72,815.301−$1,603.30
long18 Mar 2026 73,909.4019 Mar 2026 71,246.601−$2,662.82
short26 Mar 2026 71,336.507 Apr 2026 72,049.9012−$713.37
long8 Apr 2026 71,924.209 Apr 2026 71,069.901−$854.29
short4 May 2026 78,568.605 May 2026 79,861.001−$1,292.43
long6 May 2026 80,905.507 May 2026 80,096.501−$809.06
short17 May 2026 78,148.1016 Jun 2026 66,328.7030$11,819.30
long16 Jun 2026 66,328.7017 Jun 2026 65,665.401−$663.29
short25 Jun 2026 61,078.002 Jul 2026 61,688.807−$610.78
long7 Jul 2026 64,042.908 Jul 2026 63,364.001−$678.93
short31 Jul 2026 64,780.009 Aug 2026 64,962.609−$182.57
long9 Aug 2026 64,962.6010 Aug 2026 64,901.601−$61.01
short10 Aug 2026 64,901.6011 Aug 2026 63,970.001$931.58
long11 Aug 2026 63,970.0012 Aug 2026 63,330.301−$639.71
short16 Aug 2026 63,086.0017 Aug 2026 63,716.901−$630.87
long21 Aug 2026 73,027.006 Sep 2026 79,831.8016$6,804.73
short6 Sep 2026 79,831.809 Sep 2026 78,455.803$1,375.95
long9 Sep 2026 78,455.8010 Sep 2026 77,671.201−$784.56
short14 Sep 2026 76,842.0015 Sep 2026 78,189.201−$1,347.19
long21 Sep 2026 81,178.003 Oct 2026 84,518.0012$3,339.99
short3 Oct 2026 84,518.004 Oct 2026 85,363.201−$845.18
long6 Oct 2026 85,766.907 Oct 2026 84,909.201−$857.67
short13 Oct 2026 81,850.0014 Oct 2026 83,169.001−$1,319.00

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
Chirag Strategy SMA with StopLoss this page—v4 strategy−19.4%9142.8%
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 15 msYes 1,000 bars in 25 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.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © chiragchopra91//@version=4strategy(title='Chirag Strategy SMA', shorttitle='CHIRAGSMA', overlay=true)plot(sma(close,10), color=color.green, linewidth=2)plot(sma(close,13), color=color.red, linewidth=2)longCondition = crossover(sma(close, 10), sma(close, 13))shortCondition = crossover(sma(close, 13), sma(close, 10))// Set stop loss level with input optionslongLossPerc = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01shortLossPerc = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1) * 0.01longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)if longCondition    if strategy.position_size < 0        strategy.close('Short', comment="SHORT EXIT")    strategy.entry('Long', strategy.long, comment="BUY")if shortCondition    if strategy.position_size > 0        strategy.close('Long', comment="BUY EXIT")    strategy.entry('Short', strategy.short, comment="SHORT")if strategy.position_size > 0    strategy.exit('LONG SL', stop=longStopPrice, comment="LONG SL EXIT")if strategy.position_size < 0    strategy.exit('SHORT SL', stop=shortStopPrice, comment="SHORT SL EXIT")        plot(longStopPrice, title="Long StopLoss", color=color.red)plot(shortStopPrice, title="Short StopLoss", color=color.red)