Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (22)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$93,596$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
−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

Verified

Same 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)⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Conversion Line Length9int · min 1conversionLine
Base Line Length26int · min 1baseLine
Lagging Span 2 Length52int · min 1leadLine2
Displacement26int · min 1leadLine1 leadLine2
Fast Length12int (written input.integer)fast_ma
Slow Length26int (written input.integer)slow_ma
Sourceclosesourcefast_ma slow_ma
Signal Smoothing9int (written input.integer) · min 1 · max 50signal
Simple MA (Oscillator)falseboolfast_ma slow_ma
Simple MA (Signal Line)falseboolsignal
%K Length5int · min 1k
%K Smoothing3int · min 1k
%D Smoothing3int · min 1d
Atr Length8int · min 1atr
Stop loss multi Atr1.0floatshort_stop_level long_stop_level
Take profit multi Atr1.0floatshort_profit_level long_profit_level
SmoothingRMAstring · options ["RMA", "SMA", "EMA", "WMA"]line 39 line 42 line 45
Position sideBothstring · options ["Long", "Short", "Both"]operation
Show sl&tp linestrueboolplot
MA Length100int (written input.integer)sma
Backtesting Start Timetimestamp("1 Jan 2020 00:00 +0000")timetimeCond
Backtesting End Timetimestamp("31 Dec 2025 23:59 +0000")timetimeCond close_all line 80

What it calculates

  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length (12)fast_ma · line 22
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length (26)slow_ma · line 23
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing (9)signal · line 25
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, periodK), %K Smoothing (3)k · line 31
  • SMA (sma, ta.sma in v5)k, %D Smoothing (3)d · line 32
  • TR (tr, ta.tr in v5)trueatr · line 49
  • SMA (sma, ta.sma in 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.

closecloseprice datafast_lengthFast Lengthsetting · 12slow_lengthSlow Lengthsetting · 26signal_lengthSignal Smoothingsetting · 9lowlowprice datahighhighprice dataperiodK%K Lengthsetting · 5smoothK%K Smoothingsetting · 3periodD%D Smoothingsetting · 3high · low · closehigh · low · closeprice dataatrlengthAtr Lengthsetting · 8sma_lenMA Lengthsetting · 100conversionPeriodsConversion Line Lengthsetting · 9basePeriodsBase Line Lengthsetting · 26displacementDisplacementsetting · 26laggingSpan2PeriodsLagging Span 2 Lengthsetting · 52operation_typePosition sidesetting · BothSMultiStop loss multi Atrsetting · 1.0TMultiTake profit multi Atrsetting · 1.0timetimeprice datai_startTimeBacktesting Start Timesetting · timestamp("1 Jan 20…i_endTimeBacktesting End Timesetting · timestamp("31 Dec 2…fast_maSMA / EMA→ fast_maslow_maSMA / EMA→ slow_masignalSMA / EMA→ signalkSMA / Stoch→ kdSMA→ datrTR→ atrsmaSMA→ smaconversionLineconversionLinevaluebaseLinebaseLinevalueleadLine1leadLine1valueleadLine2leadLine2valuemacdmacdvaluehisthistvalueoperationoperationvalueentry_priceentry_pricevalueshort_stop_level, long_stop_levelshort_stop_level · long…2 valuesshort_profit_level, long_profit_levelshort_profit_level · lo…2 valueslongCond, shortCondlongCond · shortCond2 conditionsentry_atrentry_atrconditiontimeCondtimeCondconditionentry:longOpen longstrategy.entryexit:SL/TPexit SL/TPstrategy.exitentry:shortOpen shortstrategy.entryclose_all:close_all strategy.close_allplot:83plotplotplot:84plotplotplot:85plotplotplot:86plotplot

Order rules

OrderFires whenBy defaultLine
Open long longlongCond and timeCondOn74
Exit SL/TP stop and limit(operation == 1 or operation == 3)On75
Open short shortshortCond and timeCondOn77
Exit SL/TP stop and limit(operation == 2 or operation == 3)On78
Close time > i_endTimeOn81

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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−6.4%+102.5%1040%0.6913.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.9%+9.8%1164%3.060.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%1741%0.730.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%1450%0.990.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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 barsTradesWonP&L
Rising market450%$1,467.69
Sideways market333%−$3,527.41
Falling market333%−$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.

0%20%
All 10 trades
SideEntryExitBarsP&L
short12 Aug 2024 58,712.6023 Aug 2024 62,249.8011−$3,537.25
short17 Sep 2024 58,214.0018 Sep 2024 60,315.501−$2,101.47
long5 Oct 2024 62,086.007 Oct 2024 64,197.302$2,111.31
long6 Nov 2024 69,372.007 Nov 2024 75,572.001$6,199.98
long22 Dec 2024 97,292.0023 Dec 2024 92,709.701−$4,582.30
short16 Apr 2025 83,644.0021 Apr 2025 87,532.005−$3,888.01
long2 Jun 2025 105,643.005 Jun 2025 102,879.003−$2,763.89
long5 Aug 2025 115,055.009 Aug 2025 117,669.004$2,613.90
short30 Nov 2025 90,802.401 Dec 2025 87,397.501$3,404.97
short6 Dec 2025 89,330.009 Dec 2025 93,191.703−$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.

ScriptSharesTypeNetTradesMax drawdown
FXFUNDINGMATE TREND INDICATOR this page—v4 strategy−6.4%1013.3%
Scalping Trading System bot Crypto and Stocks by exlux99sma ema trv5 strategy+6.5%51.0%
Daily Investments Index Scalp by dailycryptoinvestmentssma ema trv5 strategy−6.9%4230.1%
Stochastic Moving Average by LucasVivienstoch sma emav5 strategy+2.8%74.4%
OTT-Stoch-TP-SL by BigCoinHunterema sma stochv5 strategyNo trades on this market
Webhook Starter Kit [HullBuster] by tradingtudiema stoch smav4 strategydoes not run in Zeal Terminal

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 21 msYes 1,000 bars in 89 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/// © 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)//}