Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Multi MA MTF SandBox Strategy

A Pine Script v5 strategy built on SMA or EMA or WMA or HMA or ALMA (src, length), Change (src, length) and EMA (src, length). It has 7 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 3500 in cash and pays no commission. 22 settings; defaults include What trades should be taken: LONG, First Slow moving average EMA and First MA Length 6.

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 Multi MA MTF SandBox Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 15 of 15 trades.
How did Multi MA MTF SandBox Strategy do on BTCUSDT 1D with default settings?
+17.35%
From 26 Jan 2024 to 21 Oct 2026, over 48 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Multi MA MTF SandBox Strategy run in Pine Script v6?
Yes
Same 48 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 Multi MA MTF SandBox Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 179, 181.
Does Multi MA MTF SandBox Strategy run in Zeal Terminal?
Yes
It compiles in 48 ms and runs 1,000 bars in 128 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$11,735$20,253Equity from $10,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
+17.35%
$1,735.27
Buy and hold
+102.5%
same period
Closed trades
48
17 won · 31 lost
Profitable
35.4%
of closed trades
Profit factor
1.54
gross profit ÷ gross loss
Max drawdown
9.46%
−$1,012.05

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

Settings

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

SettingDefaultType and rangeFeeds
What trades should be taken:LONGstring · options ['LONG', 'SHORT', 'BOTH']long short
Act as indicator (will disable strategy functionality)falseboollongShape shortShape entry long entry short line 167 line 169
Start Datetimestamp('1 JAN 2020 09:30:00 +0000')timeline 26
End Datetimestamp('1 JAN 2030 09:30:00 +0000')timeline 26
Moving Average 1 (Blue)
First Slow moving averageEMAstring · options ['SMA', 'EMA', 'WMA', 'HMA', 'JMA', 'KAMA', 'TMA', 'VAMA', 'SMMA', 'DEMA', 'VMA', 'WWMA', 'EMA_NO_LAG', 'TSF', 'ALMA']ma_fast
First Time FrametimeframemaFastStep
First MA Length6intma_fast
Moving Average 2 (Yellow)
Second Fast moving averageJMAstring · options ['SMA', 'EMA', 'WMA', 'HMA', 'JMA', 'KAMA', 'TMA', 'VAMA', 'SMMA', 'DEMA', 'VMA', 'WWMA', 'EMA_NO_LAG', 'TSF', 'ALMA']ma_slow
Second time frametimeframemaSlowStep
Second MA length14intma_slow
Visual Settings
Line Width2intma1_plot ma2_plot plot
Fast Line Color (or Buy)color.new(#26c6da, 40)valuecolors_setting ma1_plot plot
Slow Line Color (or Sell)color.new(color.yellow, 40)valuecolors_setting ma2_plot plot
Change line color based on signalChange line color based on Buy or Sell Signal. Effected by Fast/Slow Line Color settings above.trueboolma1_plot ma2_plot plot
Fill Colortrueboolfill
Moving Average Parameters
Alma Offset (only for ALMA)0.85float · step 0.05ma
Volatility lookback (only for VAMA)12intvol_up vol_down
KAMA\'s alpha (only for KAMA)1.25float · min 1 · step 0.25fastAlpha
Stop Loss
Use Stop Lossfalseboolexit Take Profit exit Stop loss exit Take Profit/Stop Loss line 175 line 176 line 178 line 180
Stop Loss %2.5float · step 0.1stop_level
Take Profit
Use Take Profitfalseboolexit Take Profit exit Stop loss exit Take Profit/Stop Loss line 175 line 176 line 178 line 180
Take Profit %5float · step 0.1take_level

What it calculates

  • SMA / EMA / WMA / HMA / ALMAsrc, lengthma · line 47
  • Changesrc, lengthmomentum · line 74
  • Changesrcvolatility · line 75
  • EMAsrc, lengthEMA1 · line 103
  • EMAEMA1, lengthEMA2 · line 104
  • Linregsrc, length, 0lrc · line 109
  • Linregsrc, length, 1lrc1 · line 110
  • Linregsrc, length, 0TSF · line 112
  • EMAsrc, lengthmid · line 116
  • Highestdev, Volatility lookback (only for VAMA) (12)vol_up · line 118
  • Lowestdev, Volatility lookback (only for VAMA) (12)vol_down · line 119
  • SMAsrc, lengthsmaval · line 124
  • EMAsrc, lengthe1 · line 129
  • EMAe1, lengthe2 · line 130
  • CrossundermaFastStep, maSlowSteplongClose · line 150
  • CrossovermaFastStep, maSlowStepshortClose · line 153

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.

The script has 74 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long longlong and window() and act_like_indicator==falseOn168
Open short shortshort and window() and act_like_indicator==falseOn170
Close long(longClose)On172
Close short(shortClose)On174
Exit Take Profit limit(useTakeprofit and useStopLoss==false)On177
Exit Stop loss stop(useTakeprofit==false and useStopLoss)On179
Exit Take Profit/Stop Loss stop and limit(useTakeprofit and useStopLoss)On181

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.

15/15trades 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 data2 request.security call(s), none with lookahead on.
  • 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+17.4%+102.5%4835%1.549.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.6%+5.5%5127%1.203.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+7.0%+9.8%4933%1.1116.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.5%+8.4%5022%1.086.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+9.5%+16.7%4439%1.1522.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+8.4%+21.5%4732%1.614.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−1.5%+148.3%4736%0.9617.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+5.0%+17.1%4833%1.472.8%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 market1735%$774.43
Sideways market2143%$1,250.77
Falling market1020%−$289.92

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

How bad could the drawdown be?

14.4%

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

0%17%
All 48 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.5017 Mar 2024 65,300.6019$695.43
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$221.18
long8 Apr 2024 69,360.4013 Apr 2024 67,116.505−$113.23
long23 Apr 2024 66,819.3027 Apr 2024 63,770.004−$159.72
long6 May 2024 64,012.009 May 2024 61,193.003−$154.13
long10 May 2024 63,074.0011 May 2024 60,800.001−$126.19
long16 May 2024 66,206.5030 May 2024 67,652.4014$76.44
long5 Jun 2024 70,537.8012 Jun 2024 67,314.207−$159.95
long3 Jul 2024 62,135.504 Jul 2024 60,208.601−$108.54
long14 Jul 2024 59,204.001 Aug 2024 64,628.0018$320.65
long14 Aug 2024 60,587.2016 Aug 2024 57,541.102−$175.97
long20 Aug 2024 59,438.5029 Aug 2024 59,034.909−$23.77
long13 Sep 2024 58,132.302 Oct 2024 60,804.9019$160.91
long13 Oct 2024 63,206.2027 Oct 2024 67,092.8014$215.21
long28 Oct 2024 68,021.705 Nov 2024 67,850.008−$8.83
long7 Nov 2024 75,572.004 Dec 2024 95,849.7027$939.13
long5 Dec 2024 98,587.3020 Dec 2024 97,461.9015−$39.96
long4 Jan 2025 98,174.2010 Jan 2025 92,552.506−$200.42
long16 Jan 2025 100,497.0029 Jan 2025 101,336.0013$29.19
long31 Jan 2025 104,723.001 Feb 2025 102,430.001−$76.65
long16 Feb 2025 97,569.7017 Feb 2025 96,118.101−$52.07
long21 Feb 2025 98,305.0024 Feb 2025 96,258.003−$72.88
long7 Mar 2025 89,931.908 Mar 2025 86,801.701−$121.82
long20 Mar 2025 86,845.9030 Mar 2025 82,648.5010−$169.16
long13 Apr 2025 85,276.9030 May 2025 105,590.0047$833.70
long10 Jun 2025 110,263.0015 Jun 2025 105,415.005−$153.90
long26 Jun 2025 107,341.0026 Jul 2025 117,614.0030$334.99
long28 Jul 2025 119,416.0029 Jul 2025 118,062.001−$39.66
long9 Aug 2025 116,675.0018 Aug 2025 117,405.009$21.91
long6 Sep 2025 110,660.0023 Sep 2025 112,651.0017$62.97
long1 Oct 2025 114,049.0011 Oct 2025 112,774.0010−$39.11
long26 Oct 2025 111,646.0031 Oct 2025 108,323.005−$104.19
long28 Nov 2025 91,333.9015 Dec 2025 88,172.2017−$121.16
long29 Dec 2025 87,952.7030 Dec 2025 87,237.101−$28.48
long31 Dec 2025 88,485.5021 Jan 2026 88,427.7021−$2.29
long23 Feb 2026 67,643.4024 Feb 2026 64,656.001−$154.57
long1 Mar 2026 66,973.302 Mar 2026 65,776.501−$62.54
long3 Mar 2026 68,830.109 Mar 2026 65,971.206−$145.37
long11 Mar 2026 69,948.6021 Mar 2026 70,510.7010$28.13
long6 Apr 2026 69,034.2030 Apr 2026 75,780.0024$342.01
long3 May 2026 78,686.8016 May 2026 79,113.2013$18.96
long15 Jun 2026 65,746.4022 Jun 2026 63,312.007−$129.60
long4 Jul 2026 62,583.3026 Jul 2026 64,375.0022$100.20
long27 Jul 2026 65,400.0028 Jul 2026 63,755.901−$87.99
long6 Aug 2026 64,665.2012 Aug 2026 63,600.006−$57.66
long19 Aug 2026 64,725.403 Sep 2026 77,340.0015$682.13
long4 Sep 2026 81,270.409 Sep 2026 78,455.805−$121.21
long19 Sep 2026 80,883.908 Oct 2026 83,321.8019$105.50

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
Multi MA MTF SandBox Strategy this page—v5 strategy+17.4%489.5%
Ultra Moving Average Rating Trend Strategy by exlux99ema wma highest lowest sma alma linreg hmav5 strategy+2.8%52.4%
Multi Trend Cross Strategy Template by TradeAutomationalma ema hma linreg sma wma highest lowestv5 strategy+33.0%37.3%
Multi MA Trend Following Strategy Template by TradeAutomationalma ema hma linreg sma wma highest lowestv5 strategy+12.3%326.9%
Swing Multi Moving Averages Crypto and Stocks Strategy by exlux99ema wma highest lowest smav5 strategy+60.2%2213.1%
BTC 15 min by RafaelZionisma ema wma linreg highest lowestv4 strategy−25.7%11938.9%

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.

  • 9 settings use the untyped input() (line 29, 32, 33, 34, 35, 37, 39, 159, 161). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 29: input() → input.int()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 37: input() → input.bool()
  • Line 39: input() → input.int()
  • Line 159: input() → input.bool()
  • Line 161: input() → input.bool()
⋯resma_fast = input.timeframe(title='First Time Frame', defval='',group="Moving Average 1 (Blue)")-lenma_fast = input(title='First MA Length', defval=6,group="Moving Average 1 (Blue)")+lenma_fast = input.int(title='First MA Length', defval=6,group="Moving Average 1 (Blue)")ma_select2 = input.string(title='Second Fast moving average', defval='JMA', options=['SMA', 'EMA', 'WMA', 'HMA', 'JMA', 'KAMA', 'TMA', 'VAMA', 'SMMA', 'DEMA', 'VMA', 'WWMA', 'EMA_NO_LAG', 'TSF', 'ALMA'],group="Moving Average 2 (Yellow)")resma_slow = input.timeframe(title='Second time frame', defval='',group="Moving Average 2 (Yellow)")-lenma_slow = input(title='Second MA length', defval=14,group="Moving Average 2 (Yellow)")+lenma_slow = input.int(title='Second MA length', defval=14,group="Moving Average 2 (Yellow)")-lineWidth = input(2, title='Line Width', group="Visual Settings")+lineWidth = input.int(2, title='Line Width', group="Visual Settings")color_fast = input(title='Fast Line Color (or Buy)', defval=color.new(#26c6da, 40), group="Visual Settings")⋯change_line_color = input.bool(true, title='Change line color based on signal', tooltip='Change line color based on Buy or Sell Signal. Effected by Fast/Slow Line Color settings above.', group="Visual Settings")-fillColor = input(title='Fill Color', defval=true, group="Visual Settings")+fillColor = input.bool(title='Fill Color', defval=true, group="Visual Settings")offset = input.float(title='Alma Offset (only for ALMA)', defval=0.85, step=0.05, group="Moving Average Parameters")-volatility_lookback = input(title='Volatility lookback (only for VAMA)', defval=12, group="Moving Average Parameters")+volatility_lookback = input.int(title='Volatility lookback (only for VAMA)', defval=12, group="Moving Average Parameters")i_fastAlpha = input.float(1.25, 'KAMA\'s alpha (only for KAMA)', minval=1, step=0.25, group="Moving Average Parameters")⋯// === Stop LOSS ===-useStopLoss = input(false, title='Use Stop Loss',group="Stop Loss")+useStopLoss = input.bool(false, title='Use Stop Loss',group="Stop Loss")sl_inp = input.float(2.5, title='Stop Loss %', step=0.1, group="Stop Loss") // / 100-useTakeprofit = input(false, title='Use Take Profit',group="Take Profit")+useTakeprofit = input.bool(false, title='Use Take Profit',group="Take Profit")tp_inp = input.float(5, title='Take Profit %', step=0.1,group="Take Profit") // / 100⋯

Does it run in Pine Script v6?

Yes

Same 48 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

⋯// Can also act as an indicator by settings 'Act as indicator' to true.-//@version=5+//@version=6strategy('Multi MA MTF SandBox Strategy', 'Multi MA SandBox', overlay=true, default_qty_type=strategy.cash, default_qty_value=3500, initial_capital=10000)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 48 msYes 1,000 bars in 128 msNot measured
PineTSNot testedNot testedNot 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.

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 work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/// © dman103// A moving averages SandBox strategy where you can experiment with two moving averages (like KAMA, ALMA, HMA, JMA, VAMA, and more) on different time frames to generate BUY and SELL signals, when they cross.// Great sandbox for experimenting with different moving averages and different time frames.//// == How to use ==// We select two types of moving averages on two different time frames://// First is the FAST moving average which should be at the same time frame or higher.// Second is the SLOW moving average that should be on the same time frame or higher.// When FAST moving average cross over the SLOW moving average we have a BUY signal (for LONG)// When FAST moving average cross under the SLOW moving average we have a SELL signal (for SHORT)// WARNING: Using a lower time frame than your chart time frame will result in unrealistic results in your backtesting and bar replay.// == NOTES ==// You can select BOTH, LONG and SHORT in the strategy settings.// You can also enable Stop Loss and Take Profit.// More sandboxes to come, Follow to get notified.// Can also act as an indicator by settings 'Act as indicator' to true.//@version=5strategy('Multi MA MTF SandBox Strategy', 'Multi MA SandBox', overlay=true, default_qty_type=strategy.cash, default_qty_value=3500, initial_capital=10000)tradeType = input.string('LONG', title='What trades should be taken:', options=['LONG', 'SHORT', 'BOTH'])act_like_indicator = input.bool(false,'Act as indicator (will disable strategy functionality)')start_date = input.time(title='Start Date', defval=timestamp('1 JAN 2020 09:30:00 +0000'))end_date = input.time(title='End Date', defval=timestamp('1 JAN 2030 09:30:00 +0000'))window() =>    time_close >= start_date and time_close <= end_date ? true : falsema_select1 = input.string(title='First Slow moving average', defval='EMA', options=['SMA', 'EMA', 'WMA', 'HMA', 'JMA', 'KAMA', 'TMA', 'VAMA', 'SMMA', 'DEMA', 'VMA', 'WWMA', 'EMA_NO_LAG', 'TSF', 'ALMA'],group="Moving Average 1 (Blue)")resma_fast = input.timeframe(title='First Time Frame', defval='',group="Moving Average 1 (Blue)")lenma_fast = input(title='First MA Length', defval=6,group="Moving Average 1 (Blue)")ma_select2 = input.string(title='Second Fast moving average', defval='JMA', options=['SMA', 'EMA', 'WMA', 'HMA', 'JMA', 'KAMA', 'TMA', 'VAMA', 'SMMA', 'DEMA', 'VMA', 'WWMA', 'EMA_NO_LAG', 'TSF', 'ALMA'],group="Moving Average 2 (Yellow)")resma_slow = input.timeframe(title='Second time frame', defval='',group="Moving Average 2 (Yellow)")lenma_slow = input(title='Second MA length', defval=14,group="Moving Average 2 (Yellow)")lineWidth = input(2, title='Line Width', group="Visual Settings")color_fast = input(title='Fast Line Color (or Buy)', defval=color.new(#26c6da, 40), group="Visual Settings")color_slow = input(title='Slow Line Color (or Sell)', defval=color.new(color.yellow, 40), group="Visual Settings")change_line_color = input.bool(true, title='Change line color based on signal', tooltip='Change line color based on Buy or Sell Signal. Effected by Fast/Slow Line Color settings above.', group="Visual Settings")fillColor = input(title='Fill Color', defval=true, group="Visual Settings")offset = input.float(title='Alma Offset (only for ALMA)', defval=0.85, step=0.05, group="Moving Average Parameters")volatility_lookback = input(title='Volatility lookback (only for VAMA)', defval=12, group="Moving Average Parameters")i_fastAlpha = input.float(1.25, 'KAMA\'s alpha (only for KAMA)', minval=1, step=0.25, group="Moving Average Parameters")fastAlpha = 2.0 / (i_fastAlpha + 1)slowAlpha = 2.0 / 31///////Moving AveragesMA_selector(src, length, ma_select) =>    ma = 0.0    if ma_select == 'SMA'        ma := ta.sma(src, length)        ma    if ma_select == 'EMA'        ma := ta.ema(src, length)        ma    if ma_select == 'WMA'        ma := ta.wma(src, length)        ma    if ma_select == 'HMA'        ma := ta.hma(src, length)        ma    if ma_select == 'JMA'        beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2)        alpha = beta        tmp0 = 0.0        tmp1 = 0.0        tmp2 = 0.0        tmp3 = 0.0        tmp4 = 0.0        tmp0 := (1 - alpha) * src + alpha * nz(tmp0[1])        tmp1 := (src - tmp0[0]) * (1 - beta) + beta * nz(tmp1[1])        tmp2 := tmp0[0] + tmp1[0]        tmp3 := (tmp2[0] - nz(tmp4[1])) * (1 - alpha) * (1 - alpha) + alpha * alpha * nz(tmp3[1])        tmp4 := nz(tmp4[1]) + tmp3[0]        ma := tmp4        ma    if ma_select == 'KAMA'        momentum = math.abs(ta.change(src, length))        volatility = math.sum(math.abs(ta.change(src)), length)        efficiencyRatio = volatility != 0 ? momentum / volatility : 0        smoothingConstant = math.pow(efficiencyRatio * (fastAlpha - slowAlpha) + slowAlpha, 2)        var kama = 0.0        kama := nz(kama[1], src) + smoothingConstant * (src - nz(kama[1], src))        ma := kama        ma    if ma_select == 'TMA'        ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)        ma    if ma_select == 'VMA'        valpha = 2 / (length + 1)        vud1 = src > src[1] ? src - src[1] : 0        vdd1 = src < src[1] ? src[1] - src : 0        vUD = math.sum(vud1, 9)        vDD = math.sum(vdd1, 9)        vCMO = nz((vUD - vDD) / (vUD + vDD))        VAR = 0.0        VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])        ma := VAR        ma    if ma_select == 'WWMA'        wwalpha = 1 / length        WWMA = 0.0        WWMA := wwalpha * src + (1 - wwalpha) * nz(WWMA[1])        ma := WWMA        ma    if ma_select == 'EMA_NO_LAG'        EMA1 = ta.ema(src, length)        EMA2 = ta.ema(EMA1, length)        Difference = EMA1 - EMA2        ma := EMA1 + Difference        ma    if ma_select == 'TSF'        lrc = ta.linreg(src, length, 0)        lrc1 = ta.linreg(src, length, 1)        lrs = lrc - lrc1        TSF = ta.linreg(src, length, 0) + lrs        ma := TSF        ma    if ma_select == 'VAMA'  // Volatility Adjusted from @fractured        mid = ta.ema(src, length)        dev = src - mid        vol_up = ta.highest(dev, volatility_lookback)        vol_down = ta.lowest(dev, volatility_lookback)        ma := mid + math.avg(vol_up, vol_down)        ma    if ma_select == 'SMMA'        smma = float(0.0)        smaval = ta.sma(src, length)        smma := na(smma[1]) ? smaval : (smma[1] * (length - 1) + src) / length        ma := smma        ma    if ma_select == 'DEMA'        e1 = ta.ema(src, length)        e2 = ta.ema(e1, length)        ma := 2 * e1 - e2        ma    if ma_select == 'ALMA'        ma := ta.alma(src, length, offset, 6)        ma    ma// Calculate EMAma_fast = MA_selector(close, lenma_fast, ma_select1)ma_slow = MA_selector(close, lenma_slow, ma_select2)maFastStep = request.security(syminfo.tickerid, resma_fast, ma_fast)maSlowStep = request.security(syminfo.tickerid, resma_slow, ma_slow)colors = ma_fast > ma_slow ? color.new(color.green, 70) : color.new(color.red, 70)colors_setting = ma_fast > ma_slow ? color_fast : color_slowma1_plot = plot(maFastStep, color=change_line_color == false ? color_fast : colors_setting, linewidth=lineWidth)ma2_plot = plot(maSlowStep, color=change_line_color == false ? color_slow : colors_setting, linewidth=lineWidth)fill(ma1_plot, ma2_plot, color=fillColor ? colors : na)closeStatus = strategy.openprofit > 0 ? 'win' : 'lose'////////Long Ruleslong = ta.crossover(maFastStep, maSlowStep) and (tradeType == 'LONG' or tradeType == 'BOTH')longClose = ta.crossunder(maFastStep, maSlowStep)  //and falling(maSlowStep,1) ///////Short Rulesshort = ta.crossunder(maFastStep, maSlowStep) and (tradeType == 'SHORT' or tradeType == 'BOTH')shortClose = ta.crossover(maFastStep, maSlowStep)longShape = ta.crossover(maFastStep, maSlowStep) and act_like_indicatorshortShape = ta.crossunder(maFastStep, maSlowStep) and act_like_indicatorplotshape(longShape, style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 0), size=size.small)plotshape(shortShape, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.small)// === Stop LOSS ===useStopLoss = input(false, title='Use Stop Loss',group="Stop Loss")sl_inp = input.float(2.5, title='Stop Loss %', step=0.1, group="Stop Loss") // / 100useTakeprofit = input(false, title='Use Take Profit',group="Take Profit")tp_inp = input.float(5, title='Take Profit %', step=0.1,group="Take Profit") // / 100percentToTicks(pcnt) =>    strategy.position_size != 0 ? math.round(pcnt / 100.0 * strategy.position_avg_price / syminfo.mintick) : float(na)float stop_level = percentToTicks(sl_inp)float take_level = percentToTicks(tp_inp)if long and window() and act_like_indicator==false    strategy.entry('long', strategy.long)if short and window() and act_like_indicator==false    strategy.entry('short', strategy.short)if (longClose)    strategy.close('long', comment=closeStatus)if (shortClose)    strategy.close('short',  comment=closeStatus)if useStopLoss or useTakeprofit    if (useTakeprofit and useStopLoss==false)        strategy.exit('Take Profit',   profit=take_level, comment='tp '+closeStatus)    if (useTakeprofit==false and useStopLoss)        strategy.exit('Stop loss', loss=stop_level, comment='sl')    if (useTakeprofit and useStopLoss)        strategy.exit('Take Profit/Stop Loss',   profit=take_level,loss=stop_level, comment_profit ='tp '+closeStatus,comment_loss='sl')