Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Moving Average Crossover Strategy

A Pine Script v5 strategy built on SMA (close, 13), EMA (5) and Crossover (Fast, Slow). 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 10% of equity and pays no commission. 30 settings; defaults include Fast EMA 5, Slow SMA 10 and Trend Determining SMA 13.

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 Moving Average Crossover Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 24 of 24 trades.
How did Moving Average Crossover Strategy do on BTCUSDT 1D with default settings?
+0.02%
From 26 Jan 2024 to 21 Oct 2026, over 75 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Moving Average Crossover Strategy run in Pine Script v6?
Yes
Same 75 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Moving Average Crossover Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 139, 141.
Does Moving Average Crossover Strategy run in Zeal Terminal?
Yes
It compiles in 43 ms and runs 1,000 bars in 67 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • EMA
  • SMA
  • Crossover
  • Crossunder
  • Crossover
  • Crossunder
  • Crossover
  • Crossunder
  • ATR
  • SMA
  • 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 (30)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOctRSI$99,816$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
+0.02%
$17.92
Buy and hold
+102.5%
same period
Closed trades
75
37 won · 38 lost
Profitable
49.3%
of closed trades
Profit factor
1.00
gross profit ÷ gross loss
Max drawdown
4.30%
−$4,347.17

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.

  • Note

    4 settings have no label

    In the settings dialog usevol (line 54), useatr (line 61), usersi (line 68), rsitrhs1 (line 70) show 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.

Settings

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

SettingDefaultType and rangeFeeds
Moving Averages:
Fast EMA5int · min 1Fast
Dynamic Exponential Moving Average?Changes the source of the MA based on trendtrueboolFast
Slow SMA10int · min 1Slow
Dynamic Simple Moving Average?Changes the source of the MA based on trendfalseboolSlow
Trend Determining SMA13int · min 1Trend
Allowed Entries:
Longtrueboolgolong entry long line 130
Shorttrueboolgoshort entry short line 132
Entry Conditions:
Buy whenFast-Slow Crossingstring · options ["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"]crosslong crossshort
In trendIn trend if price is above SMA 2trueboolcrosslong
Sell whenFast-Slow Crossingstring · options ["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"]crossshort
In trendIn trend if price is below SMA 2?trueboolcrossshort
Exit Conditions:
Close long whenFast-Slow Crossingstring · options ["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"]crossexitlong
Close short whenFast-Slow Crossingstring · options ["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"]crossexitshort
Apply Filters to
Long Entriestrueboolgolong
Short Entriestrueboolgoshort
Exitstrueboolendlong endshort
Relative Volume Filter:
Usevol (no label in the script)falseboolvolumefilter
Volume >1intvolumefilter
Avg. Volume Over PeriodThe current volume must be greater than N times the M-period average volume.30int · min 1volumefilter
Volatility Filter:
Useatr (no label in the script)falseboolvolatilityfilter
ATR5int · min 1volatilityfilter
> ATRThe N-period ATR must be greater than the M-period ATR.30int · min 1volatilityfilter
Overbought/Oversold Filter:
Usersi (no label in the script)falseboolrsifilter
Rsitrhs1 (no label in the script)0int · min 0 · max 100rsifilter
< RSI (14) <RSI(14) must be in the range between N and M.100int · min 0 · max 100rsifilter
Stop Loss / Take Profit:
SLfalseboolexit sl/tp long exit sl/tp short
, %10float · min 0.0stoploss
Trailingfalseboolline 125 line 127
TPfalseboolexit sl/tp long exit sl/tp short
, %20floattakeprofit

What it calculates

  • SMAclose, Trend Determining SMA (13)Trend · line 18
  • EMAisDynamicEMA ? (close > Trend ? low : high) : close, Fast EMA (5)Fast · line 19
  • SMAisDynamicSMA ? (close > Trend ? low : high) : close, Slow SMA (10)Slow · line 20
  • CrossoverFast, Slowfscrossup · line 87
  • CrossunderFast, Slowfscrossdw · line 88
  • CrossoverFast, Trendftcrossup · line 89
  • CrossunderFast, Trendftcrossdw · line 90
  • CrossoverSlow, Trendstcrossup · line 91
  • CrossunderSlow, Trendstcrossdw · line 92
  • RSIclose, 14rsifilter · line 109
  • ATRATR (5)volatilityfilter · line 110
  • SMAvolume, Avg. Volume Over Period (30)volumefilter · line 111

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 dataSMA2Trend Determining SMAsetting · 13highhighprice datalowlowprice dataEMA1Fast EMAsetting · 5SMA1Slow SMAsetting · 10rsitrhs1Rsitrhs1setting · 0rsitrhs2< RSI (14) <setting · 100high · low · closehigh · low · closeprice datalen_atr1ATRsetting · 5len_atr2> ATRsetting · 30volumevolumeprice datarvolVolume >setting · 1len_volAvg. Volume Over Periodsetting · 30buycondBuy whensetting · Fast-Slow CrossingsellcondSell whensetting · Fast-Slow CrossingclosebuyClose long whensetting · Fast-Slow CrossingcloseshortClose short whensetting · Fast-Slow Crossingtppercent, %setting · 20slpercent, %setting · 10TrendSMA→ TrendFastEMA→ FastSlowSMA→ SlowfscrossupCrossover→ fscrossupfscrossdwCrossunder→ fscrossdwftcrossupCrossover→ ftcrossupftcrossdwCrossunder→ ftcrossdwstcrossupCrossover→ stcrossupstcrossdwCrossunder→ stcrossdwrsifilterRSI→ rsifiltervolatilityfilterATR→ volatilityfiltervolumefilterSMA→ volumefiltercrosslongcrosslongvaluecrossshortcrossshortvaluecrossexitlongcrossexitlongvaluecrossexitshortcrossexitshortvaluegolonggolongvaluegoshortgoshortvalueendlongendlongvalueendshortendshortvaluepmpmvaluetakeprofittakeprofitvaluestoplossstoplossvalueuptrend, downtrend, justCrosseduptrend · downtrend +13 conditionstotalfiltertotalfilterconditionstartpricestartpriceconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryclose:longClose longstrategy.closeclose:shortClose shortstrategy.closeexit:sl/tp longexit sl/tp longstrategy.exitexit:sl/tp shortexit sl/tp shortstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open long longgolong and islongOn131
Open short shortgoshort and isshortOn133
Close longendlongOn135
Close shortendshortOn137
Exit sl/tp long stop and limitevery barOn139
Exit sl/tp short stop and limitevery barOn141

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.

24/24trades 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+0.0%+102.5%7549%1.004.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.5%+5.5%8358%1.351.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.4%+9.8%6752%1.096.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+4.1%+8.4%8054%2.160.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+4.6%+16.7%7254%1.346.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.5%+21.5%7049%1.611.3%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−5.4%+148.3%7939%0.7110.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.5%+17.1%7650%1.841.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 market2348%−$94.53
Sideways market3043%−$460.49
Falling market2259%$572.94

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

How bad could the drawdown be?

6.4%

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

0%7%
All 75 trades
SideEntryExitBarsP&L
long29 Feb 2024 62,432.106 Mar 2024 63,724.006$206.93
long10 Mar 2024 68,313.3012 Mar 2024 72,078.102$552.25
short10 Apr 2024 69,146.0013 Apr 2024 67,116.503$295.74
long13 Apr 2024 67,116.5015 Apr 2024 65,661.902−$219.02
long1 May 2024 60,672.002 May 2024 58,365.001−$383.43
short2 May 2024 58,365.004 May 2024 62,882.002−$777.43
long15 May 2024 61,577.5016 May 2024 66,206.501$749.30
short16 May 2024 66,206.5017 May 2024 65,235.201$147.33
short4 Jun 2024 68,809.906 Jun 2024 71,108.002−$335.89
long13 Jun 2024 68,264.0014 Jun 2024 66,773.001−$218.93
short25 Jun 2024 60,293.3029 Jun 2024 60,427.804−$22.32
short1 Jul 2024 62,772.002 Jul 2024 62,900.001−$20.39
short6 Jul 2024 56,628.8011 Jul 2024 57,725.805−$193.68
short4 Aug 2024 60,698.009 Aug 2024 61,686.005−$162.42
long19 Aug 2024 58,427.3020 Aug 2024 59,438.501$172.40
short20 Aug 2024 59,438.5021 Aug 2024 59,013.801$71.30
short8 Sep 2024 54,160.9010 Sep 2024 57,042.002−$531.23
short12 Sep 2024 57,338.0013 Sep 2024 58,132.301−$137.60
long21 Sep 2024 63,201.1027 Sep 2024 65,174.006$309.65
long30 Sep 2024 65,602.004 Oct 2024 60,752.704−$735.52
long16 Oct 2024 67,074.1023 Oct 2024 67,426.007$51.81
long31 Oct 2024 72,344.803 Nov 2024 69,374.703−$405.69
long9 Nov 2024 76,509.8020 Nov 2024 92,310.8011$2,032.46
long23 Nov 2024 98,892.0028 Nov 2024 95,863.105−$307.65
short5 Dec 2024 98,587.3010 Dec 2024 97,276.505$133.15
long10 Dec 2024 97,276.5012 Dec 2024 101,125.002$396.70
long17 Dec 2024 106,059.0022 Dec 2024 97,292.005−$832.11
short3 Jan 2025 96,984.804 Jan 2025 98,174.201−$122.43
long29 Jan 2025 101,336.0030 Jan 2025 103,733.001$235.94
long1 Feb 2025 102,430.0027 Feb 2025 84,250.1026−$1,773.93
short27 Feb 2025 84,250.104 Mar 2025 86,221.205−$229.69
long26 Mar 2025 87,392.9027 Mar 2025 86,909.201−$54.21
long29 Mar 2025 84,424.4031 Mar 2025 82,390.002−$235.89
long3 Apr 2025 82,516.3010 Apr 2025 82,615.207$11.71
short10 Apr 2025 82,615.2014 Apr 2025 83,760.004−$135.34
long24 Apr 2025 93,691.101 May 2025 94,172.007$50.06
long5 May 2025 94,277.607 May 2025 96,834.002$264.60
long10 May 2025 102,972.0016 May 2025 103,764.006$75.23
short24 Jun 2025 105,334.0027 Jun 2025 106,947.003−$149.96
long12 Jul 2025 117,528.0019 Jul 2025 117,925.007$33.04
short3 Aug 2025 112,546.007 Aug 2025 114,992.004−$212.56
short8 Aug 2025 117,472.009 Aug 2025 116,675.001$66.24
short31 Aug 2025 108,816.003 Sep 2025 111,240.003−$217.52
long13 Sep 2025 116,029.0017 Sep 2025 116,789.004$63.79
long11 Oct 2025 112,774.0012 Oct 2025 110,644.001−$184.17
short6 Nov 2025 103,885.0011 Nov 2025 106,011.005−$199.16
short17 Nov 2025 94,261.4026 Nov 2025 87,370.009$710.06
short27 Nov 2025 90,484.0028 Nov 2025 91,333.901−$91.89
long6 Dec 2025 89,330.008 Dec 2025 90,395.302$116.56
short17 Dec 2025 87,863.4018 Dec 2025 86,243.201$180.45
long18 Dec 2025 86,243.209 Jan 2026 91,100.0022$552.09
long16 Jan 2026 95,604.8020 Jan 2026 92,631.004−$306.66
short1 Feb 2026 78,741.1010 Feb 2026 70,138.009$1,073.81
short26 Feb 2026 67,988.0028 Feb 2026 65,872.102$309.22
short1 Mar 2026 66,973.306 Mar 2026 70,891.005−$583.01
long6 Mar 2026 70,891.007 Mar 2026 68,114.001−$388.13
long9 Mar 2026 65,971.2010 Mar 2026 68,432.201$368.16
long25 Mar 2026 70,556.7026 Mar 2026 71,336.501$109.48
short26 Mar 2026 71,336.5027 Mar 2026 68,820.301$349.80
short30 Mar 2026 66,010.9031 Mar 2026 66,797.401−$118.57
long9 Apr 2026 71,069.9014 Apr 2026 74,418.005$468.28
long19 Apr 2026 75,691.8020 Apr 2026 73,801.801−$249.37
long30 Apr 2026 75,780.001 May 2026 76,346.601$74.48
short5 May 2026 79,861.006 May 2026 80,905.501−$130.40
long6 May 2026 80,905.5011 May 2026 82,210.105$160.54
short30 May 2026 73,460.8011 Jun 2026 61,511.0012$1,622.24
long23 Jun 2026 64,020.0027 Jun 2026 60,097.304−$621.00
short27 Jun 2026 60,097.302 Jul 2026 60,024.005$12.28
long14 Jul 2026 62,334.5015 Jul 2026 65,044.001$437.88
long25 Jul 2026 64,140.0026 Jul 2026 64,375.001$37.07
short16 Aug 2026 63,086.0021 Aug 2026 73,027.005−$1,594.93
long21 Aug 2026 73,027.0029 Aug 2026 77,845.908$657.38
long10 Sep 2026 78,306.4013 Sep 2026 77,278.703−$131.60
short19 Sep 2026 80,883.9020 Sep 2026 81,250.001−$45.33
long8 Oct 2026 83,321.8010 Oct 2026 82,635.602−$82.44

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
Moving Average Crossover Strategy this page—v5 strategy+0.0%754.3%
3 x EMA + Stochastic RSI + ATR by tomimarsonema rsi sma atrv4 strategy−42.3%1844.8%
Atrend by OTS by prim722ema rsi sma atrv4 strategy+12.1%7634.4%
EMA crossover (daily TF) by tradeswithashishema sma rsi atrv5 strategy+11.0%1211.6%
EMA Stoch Strategy For ProfitView by treigenrsi sma ema crossv5 strategy−69.8%580.6%
Delta-RSI Strategy (with filters) by tbiktagrsi ema atr smav4 strategy−28.8%7183.8%

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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

Same 75 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © Decam9-//@version=5+//@version=6strategy(title = "Moving Average Crossover", shorttitle = "MA Crossover Strategy", overlay=true,⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 43 msWith a workaround 1,000 bars in 67 msNot measured
PineTSNot testedNot testedNot measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © Decam9//@version=5strategy(title = "Moving Average Crossover", shorttitle = "MA Crossover Strategy", overlay=true,     initial_capital = 100000,default_qty_type = strategy.percent_of_equity, default_qty_value = 10)//Moving Average InputsEMA1 = input.int(title="Fast EMA", group = "Moving Averages:",      inline = "EMAs", defval=5, minval = 1)isDynamicEMA = input.bool(title = "Dynamic Exponential Moving Average?", defval = true,     inline = "EMAs", group = "Moving Averages:", tooltip = "Changes the source of the MA based on trend")SMA1 = input.int(title = "Slow SMA", group = "Moving Averages:",     inline = "SMAs", defval = 10, minval = 1)isDynamicSMA = input.bool(title = "Dynamic Simple Moving Average?", defval = false,     inline = "SMAs", group = "Moving Averages:", tooltip = "Changes the source of the MA based on trend")SMA2 = input.int(title="Trend Determining SMA", group = "Moving Averages:",     inline = "MAs", defval=13, minval = 1)//Moving AveragesTrend = ta.sma(close, SMA2)Fast = ta.ema(isDynamicEMA ? (close > Trend ? low : high) : close, EMA1)Slow = ta.sma(isDynamicSMA ? (close > Trend ? low : high) : close, SMA1)//Allowed Entriesislong = input.bool(title = "Long", group = "Allowed Entries:",     inline = "Entries",defval = true)isshort = input.bool(title = "Short", group = "Allowed Entries:",     inline = "Entries", defval= true)//Entry Long Conditionsbuycond = input.string(title="Buy when", group = "Entry Conditions:",      inline = "Conditions",defval="Fast-Slow Crossing",      options=["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"])     intrendbuy = input.bool(title = "In trend", defval = true, group = "Entry Conditions:",     inline = "Conditions", tooltip = "In trend if price is above SMA 2")//Entry Short Conditionssellcond = input.string(title="Sell when", group = "Entry Conditions:",      inline = "Conditions2",defval="Fast-Slow Crossing",      options=["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"])     intrendsell = input.bool(title = "In trend",defval = true, group = "Entry Conditions:",     inline = "Conditions2", tooltip = "In trend if price is below SMA 2?")//Exit Long Conditionsclosebuy = input.string(title="Close long when", group = "Exit Conditions:",      defval="Fast-Slow Crossing", options=["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"])//Exit Short Conditionscloseshort = input.string(title="Close short when", group = "Exit Conditions:",      defval="Fast-Slow Crossing", options=["Fast-Slow Crossing", "Fast-Trend Crossing","Slow-Trend Crossing"])     //Filtersfilterlong =input.bool(title = "Long Entries", inline = 'linefilt', group = 'Apply Filters to',      defval = true)filtershort =input.bool(title = "Short Entries", inline = 'linefilt', group = 'Apply Filters to',      defval = true)filterend =input.bool(title = "Exits", inline = 'linefilt', group = 'Apply Filters to',      defval = true)usevol =input.bool(title = "", inline = 'linefiltvol', group = 'Relative Volume Filter:',      defval = false)rvol = input.int(title = "Volume >", inline = 'linefiltvol', group = 'Relative Volume Filter:',      defval = 1)len_vol = input.int(title = "Avg. Volume Over Period", inline = 'linefiltvol', group = 'Relative Volume Filter:',      defval = 30, minval = 1,     tooltip="The current volume must be greater than N times the M-period average volume.")useatr =input.bool(title = "", inline = 'linefiltatr', group = 'Volatility Filter:',      defval = false)len_atr1 = input.int(title = "ATR", inline = 'linefiltatr', group = 'Volatility Filter:',      defval = 5, minval = 1)len_atr2 = input.int(title = "> ATR", inline = 'linefiltatr', group = 'Volatility Filter:',      defval = 30, minval = 1,     tooltip="The N-period ATR must be greater than the M-period ATR.")usersi =input.bool(title = "", inline = 'linersi', group = 'Overbought/Oversold Filter:',      defval = false)rsitrhs1 = input.int(title = "", inline = 'linersi', group = 'Overbought/Oversold Filter:',      defval = 0, minval=0, maxval=100)rsitrhs2 = input.int(title = "< RSI (14) <", inline = 'linersi', group = 'Overbought/Oversold Filter:',      defval = 100, minval=0, maxval=100,     tooltip="RSI(14) must be in the range between N and M.")issl =  input.bool(title = "SL", inline = 'linesl1', group = 'Stop Loss / Take Profit:',      defval = false)slpercent =  input.float(title = ", %", inline = 'linesl1', group = 'Stop Loss / Take Profit:',      defval = 10, minval=0.0)istrailing =  input.bool(title = "Trailing", inline = 'linesl1', group = 'Stop Loss / Take Profit:',      defval = false)istp =  input.bool(title = "TP", inline = 'linetp1', group = 'Stop Loss / Take Profit:',      defval = false)tppercent =  input.float(title = ", %", inline = 'linetp1', group = 'Stop Loss / Take Profit:',      defval = 20)     //Conditions for Crossingfscrossup = ta.crossover(Fast,Slow)fscrossdw = ta.crossunder(Fast,Slow)ftcrossup = ta.crossover(Fast,Trend)ftcrossdw = ta.crossunder(Fast,Trend)stcrossup = ta.crossover(Slow,Trend)stcrossdw = ta.crossunder(Slow,Trend)//Defining in trenduptrend = Fast >= Slow and Slow >= Trenddowntrend = Fast <= Slow and Slow <= TrendjustCrossed = ta.cross(Fast,Slow) or ta.cross(Slow,Trend)//Entry Signalscrosslong = if intrendbuy    (buycond =="Fast-Slow Crossing" and uptrend ? fscrossup:(buycond =="Fast-Trend Crossing" and uptrend ? ftcrossup:(buycond == "Slow-Trend Crossing" and uptrend ? stcrossup : na))) else    (buycond =="Fast-Slow Crossing"?fscrossup:(buycond=="Fast-Trend Crossing"?ftcrossup:stcrossup))crossshort = if intrendsell    (sellcond =="Fast-Slow Crossing" and downtrend ? fscrossdw:(sellcond =="Fast-Trend Crossing" and downtrend ? ftcrossdw:(sellcond == "Slow-Trend Crossing" and downtrend ? stcrossdw : na))) else    (sellcond =="Fast-Slow Crossing"?fscrossdw:(buycond=="Fast-Trend Crossing"?ftcrossdw:stcrossdw))crossexitlong = (closebuy =="Fast-Slow Crossing"?fscrossdw:(closebuy=="Fast-Trend Crossing"?ftcrossdw:stcrossdw))crossexitshort = (closeshort =="Fast-Slow Crossing"?fscrossup:(closeshort=="Fast-Trend Crossing"?ftcrossup:stcrossup))// Filtersrsifilter = usersi?(ta.rsi(close,14) > rsitrhs1 and ta.rsi(close,14) < rsitrhs2):truevolatilityfilter = useatr?(ta.atr(len_atr1) > ta.atr(len_atr2)):truevolumefilter = usevol?(volume > rvol*ta.sma(volume,len_vol)):truetotalfilter = volatilityfilter and volumefilter and rsifilter//Filtered signalsgolong  = crosslong  and islong  and (filterlong?totalfilter:true) goshort = crossshort and isshort and (filtershort?totalfilter:true)endlong  = crossexitlong and (filterend?totalfilter:true)endshort = crossexitshort and (filterend?totalfilter:true)// Entry price and TPstartprice = ta.valuewhen(condition=golong or goshort, source=close, occurrence=0)pm = golong?1:goshort?-1:1/math.sign(strategy.position_size)takeprofit = startprice*(1+pm*tppercent*0.01)// fixed stop lossstoploss = startprice * (1-pm*slpercent*0.01)// trailing stop lossif istrailing and strategy.position_size>0    stoploss := math.max(close*(1 - slpercent*0.01),stoploss[1])else if istrailing and strategy.position_size<0    stoploss := math.min(close*(1 + slpercent*0.01),stoploss[1])    if golong and islong    strategy.entry("long",   strategy.long )if goshort and isshort    strategy.entry("short",  strategy.short)if endlong    strategy.close("long")if endshort    strategy.close("short")// Exit via SL or TPstrategy.exit(id="sl/tp long", from_entry="long", stop=issl?stoploss:na,               limit=istp?takeprofit:na)strategy.exit(id="sl/tp short",from_entry="short",stop=issl?stoploss:na,               limit=istp?takeprofit:na)