Pine Script v4 · Strategy
FXFUNDINGMATE TREND INDICATOR
A Pine Script v4 strategy built on SMA or EMA (close, 12), SMA or Stoch (3) and SMA (k, 3). It has 5 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 is one contract and pays no commission. 22 settings; defaults include Conversion Line Length 9, Base Line Length 26 and Lagging Span 2 Length 52.
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 FXFUNDINGMATE TREND INDICATOR repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did FXFUNDINGMATE TREND INDICATOR do on BTCUSDT 1D with default settings?
- −6.40%
- From 26 Jan 2024 to 21 Oct 2026, over 10 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can FXFUNDINGMATE TREND INDICATOR 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 FXFUNDINGMATE TREND INDICATOR use a stop loss?
- Yes
- strategy.exit sets a stop on line 75, 78.
- Does FXFUNDINGMATE TREND INDICATOR run in Zeal Terminal?
- Yes
- It compiles in 21 ms and runs 1,000 bars in 89 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −6.40%
- −$6,404.43
- Buy and hold
- +102.5%
- same period
- Closed trades
- 10
- 4 won · 6 lost
- Profitable
- 40.0%
- of closed trades
- Profit factor
- 0.69
- gross profit ÷ gross loss
- Max drawdown
- 13.28%
- −$13,639.20
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.
-
Likely bug
sma(close, sma_len) ignores the settings line 55
Line 55 hard-codes close where line 22 uses “Source”. Changing those settings moves one band but not this one.
sma(close, sma_len)sma(src, sma_len) -
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.
-
Note
Uses an argument v6 removed
when = on line 74, 77. The upgraded version below moves each call inside an if block.
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 avg → math.avg, lowest → ta.lowest, highest → ta.highest, sma → ta.sma, ema → ta.ema, stoch → ta.stoch, rma → ta.rma, wma → ta.wma, tr → ta.tr, crossover → ta.crossover, crossunder → ta.crossunder, valuewhen → ta.valuewhen.
- 2 strategy calls use the when = argument (line 74, 77). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: avg → math.avg
- Line 10: lowest → ta.lowest
- Line 10: highest → ta.highest
- Line 13: avg → math.avg
- Line 16: input(type = input.integer) → input.int()
26 more edits
- Line 17: input(type = input.integer) → input.int()
- Line 18: input(type = input.source) → input.source()
- Line 19: input(type = input.integer) → input.int()
- Line 20: input(type = input.bool) → input.bool()
- Line 21: input(type = input.bool) → input.bool()
- Line 22: sma → ta.sma
- Line 22: ema → ta.ema
- Line 23: sma → ta.sma
- Line 23: ema → ta.ema
- Line 25: sma → ta.sma
- Line 25: ema → ta.ema
- Line 31: sma → ta.sma
- Line 31: stoch → ta.stoch
- Line 32: sma → ta.sma
- Line 40: rma → ta.rma
- Line 43: sma → ta.sma
- Line 46: ema → ta.ema
- Line 48: wma → ta.wma
- Line 49: tr → ta.tr
- Line 54: input(type = input.integer) → input.int()
- Line 55: sma → ta.sma
- Line 56: crossover → ta.crossover
- Line 57: crossunder → ta.crossunder
- Line 60: valuewhen → ta.valuewhen
- Line 70: input(type = input.time) → input.time()
- Line 71: input(type = input.time) → input.time()
⋯// © FXFUNDINGMATE-//@version=4+//@version=5strategy(title="FXFUNDINGMATE TREND INDICATOR", overlay=true)⋯displacement = input(26, minval=1, title="Displacement")-donchian(len) => avg(lowest(len), highest(len))+donchian(len) => math.avg(ta.lowest(len), ta.highest(len))conversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)-leadLine1 = avg(conversionLine, baseLine)[displacement - 1]+leadLine1 = math.avg(conversionLine, baseLine)[displacement - 1]leadLine2 = donchian(laggingSpan2Periods)[displacement - 1]//macd-fast_length = input(title="Fast Length", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length", defval=12)-slow_length = input(title="Slow Length", type=input.integer, defval=26)+slow_length = input.int(title="Slow Length", defval=26)-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)+sma_source = input.bool(title="Simple MA (Oscillator)", defval=false)-sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)+sma_signal = input.bool(title="Simple MA (Signal Line)", defval=false)-fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)+fast_ma = sma_source ? ta.sma(src, fast_length) : ta.ema(src, fast_length)-slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)+slow_ma = sma_source ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯periodD = input(3, title="%D Smoothing", minval=1)-k = sma(stoch(close, high, low, periodK), smoothK)+k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)-d = sma(k, periodD)+d = ta.sma(k, periodD)//atr⋯ if smoothing == "RMA"- rma(source, length)+ ta.rma(source, length) else if smoothing == "SMA"- sma(source, length)+ ta.sma(source, length) else if smoothing == "EMA"- ema(source, length)+ ta.ema(source, length) else- wma(source, length)+ ta.wma(source, length)-atr = ma_function(tr(true), atrlength)+atr = ma_function(ta.tr(true), atrlength)operation_type = input(defval = "Both", title = "Position side", options = ["Long", "Short", "Both"])⋯// MA-sma_len = input(100, title="MA Length", type=input.integer)+sma_len = input.int(100, title="MA Length")-sma = sma(close, sma_len)+sma = ta.sma(close, sma_len)-longCond = crossover(k, 20) and macd > 0 and close > sma and close > leadLine1 and close > leadLine2+longCond = ta.crossover(k, 20) and macd > 0 and close > sma and close > leadLine1 and close > leadLine2-shortCond = crossunder(k, 80) and macd < 0 and close < sma and close < leadLine1 and close < leadLine2+shortCond = ta.crossunder(k, 80) and macd < 0 and close < sma and close < leadLine1 and close < leadLine2entry_price = float(0.0) //set floatentry_price := strategy.position_size != 0 or longCond or shortCond ? strategy.position_avg_price : entry_price[1]-entry_atr = valuewhen(longCond or shortCond, atr,0)+entry_atr = ta.valuewhen(longCond or shortCond, atr,0)short_stop_level = float(0.0) //set float⋯// Strategy Backtest Limiting Algorithm-i_startTime = input(defval = timestamp("1 Jan 2020 00:00 +0000"), title = "Backtesting Start Time", type = input.time)+i_startTime = input.time(defval = timestamp("1 Jan 2020 00:00 +0000"), title = "Backtesting Start Time")-i_endTime = input(defval = timestamp("31 Dec 2025 23:59 +0000"), title = "Backtesting End Time", type = input.time)+i_endTime = input.time(defval = timestamp("31 Dec 2025 23:59 +0000"), title = "Backtesting End Time")timeCond = (time > i_startTime) and (time < i_endTime)⋯Same 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 28: input() → input.int()
- Line 29: input() → input.int()
9 more edits
- Line 30: input() → input.int()
- Line 34: input() → input.int()
- Line 35: input() → input.float()
- Line 36: input() → input.float()
- Line 37: input() → input.string()
- Line 50: input() → input.string()
- Line 52: input() → input.bool()
- Line 74: when = longCond and timeCond → if block
- Line 77: when = shortCond and timeCond → if block
⋯//Ichimoku Cloud-conversionPeriods = input(9, minval=1, title="Conversion Line Length")+conversionPeriods = input.int(9, minval=1, title="Conversion Line Length")-basePeriods = input(26, minval=1, title="Base Line Length")+basePeriods = input.int(26, minval=1, title="Base Line Length")-laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length")+laggingSpan2Periods = input.int(52, minval=1, title="Lagging Span 2 Length")-displacement = input(26, minval=1, title="Displacement")+displacement = input.int(26, minval=1, title="Displacement")donchian(len) => math.avg(ta.lowest(len), ta.highest(len))⋯//kd-periodK = input(5, title="%K Length", minval=1)+periodK = input.int(5, title="%K Length", minval=1)-smoothK = input(3, title="%K Smoothing", minval=1)+smoothK = input.int(3, title="%K Smoothing", minval=1)-periodD = input(3, title="%D Smoothing", minval=1)+periodD = input.int(3, title="%D Smoothing", minval=1)k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)⋯//atr-atrlength = input(title="Atr Length", defval=8, minval=1)+atrlength = input.int(title="Atr Length", defval=8, minval=1)-SMulti = input(title="Stop loss multi Atr", defval=1.0)+SMulti = input.float(title="Stop loss multi Atr", defval=1.0)-TMulti = input(title="Take profit multi Atr", defval=1.0)+TMulti = input.float(title="Take profit multi Atr", defval=1.0)-smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])+smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])ma_function(source, length) =>⋯atr = ma_function(ta.tr(true), atrlength)-operation_type = input(defval = "Both", title = "Position side", options = ["Long", "Short", "Both"])+operation_type = input.string(defval = "Both", title = "Position side", options = ["Long", "Short", "Both"])operation = operation_type == "Long" ? 1 : operation_type == "Short" ? 2 : 3-showlines = input(true, title="Show sl&tp lines")+showlines = input.bool(true, title="Show sl&tp lines")// MA⋯if (operation == 1 or operation == 3)- strategy.entry("long" , strategy.long , when=longCond and timeCond, alert_message = "Long")+ if longCond and timeCond+ strategy.entry("long" , strategy.long , alert_message = "Long") strategy.exit("SL/TP", from_entry = "long" , limit = long_profit_level , stop = long_stop_level , alert_message = "Long exit")if (operation == 2 or operation == 3)- strategy.entry("short", strategy.short, when=shortCond and timeCond, alert_message="Short")+ if shortCond and timeCond+ strategy.entry("short", strategy.short, alert_message="Short") strategy.exit("SL/TP", from_entry = "short", limit = short_profit_level , stop = short_stop_level , alert_message = "Short exit")⋯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: 10 before, 14 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.
⋯// © FXFUNDINGMATE-//@version=5+//@version=6strategy(title="FXFUNDINGMATE TREND INDICATOR", overlay=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Conversion Line Length | 9 | int · min 1 | conversionLine |
| Base Line Length | 26 | int · min 1 | baseLine |
| Lagging Span 2 Length | 52 | int · min 1 | leadLine2 |
| Displacement | 26 | int · min 1 | leadLine1 leadLine2 |
| Fast Length | 12 | int (written input.integer) | fast_ma |
| Slow Length | 26 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA (Oscillator) | false | bool | fast_ma slow_ma |
| Simple MA (Signal Line) | false | bool | signal |
| %K Length | 5 | int · min 1 | k |
| %K Smoothing | 3 | int · min 1 | k |
| %D Smoothing | 3 | int · min 1 | d |
| Atr Length | 8 | int · min 1 | atr |
| Stop loss multi Atr | 1.0 | float | short_stop_level long_stop_level |
| Take profit multi Atr | 1.0 | float | short_profit_level long_profit_level |
| Smoothing | RMA | string · options ["RMA", "SMA", "EMA", "WMA"] | line 39 line 42 line 45 |
| Position side | Both | string · options ["Long", "Short", "Both"] | operation |
| Show sl&tp lines | true | bool | plot |
| MA Length | 100 | int (written input.integer) | sma |
| Backtesting Start Time | timestamp("1 Jan 2020 00:00 +0000") | time | timeCond |
| Backtesting End Time | timestamp("31 Dec 2025 23:59 +0000") | time | timeCond close_all line 80 |
What it calculates
- SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (12)fast_ma · line 22 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (26)slow_ma · line 23 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (9)signal · line 25 - SMA / Stoch (
sma,ta.smain v5)stoch(close, high, low, periodK), %K Smoothing (3)k · line 31 - SMA (
sma,ta.smain v5)k, %D Smoothing (3)d · line 32 - TR (
tr,ta.trin v5)trueatr · line 49 - SMA (
sma,ta.smain v5)close, MA Length (100)sma · line 55
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longCond and timeCond | On | 74 |
| Exit SL/TP stop and limit | (operation == 1 or operation == 3) | On | 75 |
| Open short short | shortCond and timeCond | On | 77 |
| Exit SL/TP stop and limit | (operation == 2 or operation == 3) | On | 78 |
| Close | time > i_endTime | On | 81 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −6.4% | +102.5% | 10 | 40% | 0.69 | 13.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.9% | +9.8% | 11 | 64% | 3.06 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 17 | 41% | 0.73 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 14 | 50% | 0.99 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 4 | 50% | $1,467.69 |
| Sideways market | 3 | 33% | −$3,527.41 |
| Falling market | 3 | 33% | −$4,344.71 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
17.5%
The 95th percentile of the worst drawdown when the same 10 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 8.4% to 17.5%; the tick is what actually happened, 10.9%. Order luck alone moves it this much.
All 10 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 12 Aug 2024 58,712.60 | 23 Aug 2024 62,249.80 | 11 | −$3,537.25 |
| short | 17 Sep 2024 58,214.00 | 18 Sep 2024 60,315.50 | 1 | −$2,101.47 |
| long | 5 Oct 2024 62,086.00 | 7 Oct 2024 64,197.30 | 2 | $2,111.31 |
| long | 6 Nov 2024 69,372.00 | 7 Nov 2024 75,572.00 | 1 | $6,199.98 |
| long | 22 Dec 2024 97,292.00 | 23 Dec 2024 92,709.70 | 1 | −$4,582.30 |
| short | 16 Apr 2025 83,644.00 | 21 Apr 2025 87,532.00 | 5 | −$3,888.01 |
| long | 2 Jun 2025 105,643.00 | 5 Jun 2025 102,879.00 | 3 | −$2,763.89 |
| long | 5 Aug 2025 115,055.00 | 9 Aug 2025 117,669.00 | 4 | $2,613.90 |
| short | 30 Nov 2025 90,802.40 | 1 Dec 2025 87,397.50 | 1 | $3,404.97 |
| short | 6 Dec 2025 89,330.00 | 9 Dec 2025 93,191.70 | 3 | −$3,861.67 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| FXFUNDINGMATE TREND INDICATOR this page | — | v4 strategy | −6.4% | 10 | 13.3% |
| Scalping Trading System bot Crypto and Stocks by exlux99 | sma ema tr | v5 strategy | +6.5% | 5 | 1.0% |
| Daily Investments Index Scalp by dailycryptoinvestments | sma ema tr | v5 strategy | −6.9% | 42 | 30.1% |
| Stochastic Moving Average by LucasVivien | stoch sma ema | v5 strategy | +2.8% | 7 | 4.4% |
| OTT-Stoch-TP-SL by BigCoinHunter | ema sma stoch | v5 strategy | No trades on this market | ||
| Webhook Starter Kit [HullBuster] by tradingtudi | ema stoch sma | v4 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 21 ms | Yes 1,000 bars in 89 ms | Not measured |
| PineTS | No 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/// © FXFUNDINGMATE//@version=4strategy(title="FXFUNDINGMATE TREND INDICATOR", overlay=true)//Ichimoku CloudconversionPeriods = input(9, minval=1, title="Conversion Line Length")basePeriods = input(26, minval=1, title="Base Line Length")laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length")displacement = input(26, minval=1, title="Displacement")donchian(len) => avg(lowest(len), highest(len))conversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)leadLine1 = avg(conversionLine, baseLine)[displacement - 1]leadLine2 = donchian(laggingSpan2Periods)[displacement - 1]//macdfast_length = input(title="Fast Length", type=input.integer, defval=12)slow_length = input(title="Slow Length", type=input.integer, defval=26)src = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signal//kdperiodK = input(5, title="%K Length", minval=1)smoothK = input(3, title="%K Smoothing", minval=1)periodD = input(3, title="%D Smoothing", minval=1)k = sma(stoch(close, high, low, periodK), smoothK)d = sma(k, periodD)//atratrlength = input(title="Atr Length", defval=8, minval=1)SMulti = input(title="Stop loss multi Atr", defval=1.0)TMulti = input(title="Take profit multi Atr", defval=1.0)smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])ma_function(source, length) => if smoothing == "RMA" rma(source, length) else if smoothing == "SMA" sma(source, length) else if smoothing == "EMA" ema(source, length) else wma(source, length)atr = ma_function(tr(true), atrlength)operation_type = input(defval = "Both", title = "Position side", options = ["Long", "Short", "Both"])operation = operation_type == "Long" ? 1 : operation_type == "Short" ? 2 : 3showlines = input(true, title="Show sl&tp lines")// MAsma_len = input(100, title="MA Length", type=input.integer)sma = sma(close, sma_len)longCond = crossover(k, 20) and macd > 0 and close > sma and close > leadLine1 and close > leadLine2shortCond = crossunder(k, 80) and macd < 0 and close < sma and close < leadLine1 and close < leadLine2entry_price = float(0.0) //set floatentry_price := strategy.position_size != 0 or longCond or shortCond ? strategy.position_avg_price : entry_price[1]entry_atr = valuewhen(longCond or shortCond, atr,0)short_stop_level = float(0.0) //set floatshort_profit_level = float(0.0) //set floatlong_stop_level = float(0.0) //set floatlong_profit_level = float(0.0) //set floatshort_stop_level := entry_price + SMulti * entry_atrshort_profit_level := entry_price - TMulti * entry_atrlong_stop_level := entry_price - SMulti * entry_atrlong_profit_level := entry_price + TMulti * entry_atr// Strategy Backtest Limiting Algorithmi_startTime = input(defval = timestamp("1 Jan 2020 00:00 +0000"), title = "Backtesting Start Time", type = input.time)i_endTime = input(defval = timestamp("31 Dec 2025 23:59 +0000"), title = "Backtesting End Time", type = input.time)timeCond = (time > i_startTime) and (time < i_endTime)if (operation == 1 or operation == 3) strategy.entry("long" , strategy.long , when=longCond and timeCond, alert_message = "Long") strategy.exit("SL/TP", from_entry = "long" , limit = long_profit_level , stop = long_stop_level , alert_message = "Long exit")if (operation == 2 or operation == 3) strategy.entry("short", strategy.short, when=shortCond and timeCond, alert_message="Short") strategy.exit("SL/TP", from_entry = "short", limit = short_profit_level , stop = short_stop_level , alert_message = "Short exit") if time > i_endTime strategy.close_all(comment = "close all", alert_message = "close all") plot(showlines and strategy.position_size <= 0 ? na : long_stop_level, color=color.red, style=plot.style_linebr, linewidth = 2)plot(showlines and strategy.position_size <= 0 ? na : long_profit_level, color=color.lime, style=plot.style_linebr, linewidth = 2)plot(showlines and strategy.position_size >= 0 ? na : short_stop_level, color=color.red, style=plot.style_linebr, linewidth = 2)plot(showlines and strategy.position_size >= 0 ? na : short_profit_level, color=color.lime, style=plot.style_linebr, linewidth = 2)//}