Pine Script v5 · Strategy
Multi Trend Cross Strategy Template
A Pine Script v5 strategy built on ALMA (close, 10), EMA (close, 10) and HMA (close, 10). It has 5 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.0035 commission. 21 settings; defaults include Fast Trend Selector EMA, Slow Trend Selector EMA and Price Source close.
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 Trend Cross Strategy Template repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Multi Trend Cross Strategy Template do on BTCUSDT 1D with default settings?
- +33.01%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Multi Trend Cross Strategy Template 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: 3 before, 7 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Multi Trend Cross Strategy Template use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Multi Trend Cross Strategy Template run in Zeal Terminal?
- Yes
- It compiles in 148 ms and runs 1,000 bars in 236 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +33.01%
- $330,106.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 2 won · 1 lost
- Profitable
- 66.7%
- of closed trades
- Profit factor
- 9.30
- gross profit ÷ gross loss
- Max drawdown
- 7.29%
- −$72,866.50
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A long 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
2 settings do nothing
“ATR Multiplier For SuperTrend”, “ATR Length For SuperTrend” are declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Date Range | |||
| Start Time | timestamp('01 Jan 2000 05:00 +0000') | time | InDateRange |
| End Time | timestamp('01 Jan 2099 00:00 +0000') | time | InDateRange |
| Core Settings | |||
| Fast Trend SelectorSelect your fast trend | EMA | string · options ["ALMA", "DEMA", "DSMA", "EMA", "HMA", "JMA", "KAMA", "Linear Regression (LSMA)", "RMA", "SMA", "SMMA", "Price Source", "TEMA", "TMA", "VAMA", "VIDYA", "VMA", "VWMA", "WMA", "WWMA", "ZLEMA"] | FastTrend |
| Slow Trend SelectorSelect your slow trend | EMA | string · options ["ALMA", "DEMA", "DSMA", "EMA", "HMA", "JMA", "KAMA", "Linear Regression (LSMA)", "RMA", "SMA", "SMMA", "Price Source", "TEMA", "TMA", "VAMA", "VIDYA", "VMA", "VWMA", "WMA", "WWMA", "ZLEMA"] | SlowTrend |
| Price SourceThis is the price source being used for the trends to calculate based on | close | source | ALMA EMA HMA LinReg RMA SMA VWMA WMA ALMA2 EMA2 HMA2 LinReg2 RMA2 SMA2 VWMA2 WMA2 de1 de3 zeros EDSMA EDSMA2 e0 e1 e02 e12 KAMA momentum volatility KAMA2 momentum2 volatility2 SMMA SMMA2 t1 t12 TMA TMA2 mid dev mid2 dev2 VIDYA ud1 dd1 VIDYA2 ud12 dd12 pdm mdm VMA pdm2 mdm2 VMA2 WWMA WWMA2 EMA1a EMA12 FastTrend SlowTrend ssf ssf2 |
| Fast Trend LengthA long is entered when the selected fast trend crosses over the selected slow trend | 10 | int · step 5 | ALMA EMA HMA LinReg RMA SMA VWMA WMA de1 de2 stdev alpha1 beta momentum volatility SMMA t1 t2 t3 TMA mid VIDYA VMAalpha sc hhv llv VMA hhv2 llv2 WWMA EMA1a EMA2a arg |
| Slow Trend LengthA long is entered when the selected fast trend crosses over the selected slow trend | 200 | int · step 5 | ALMA2 EMA2 HMA2 LinReg2 RMA2 SMA2 VWMA2 WMA2 de3 de4 arg stdev2 alpha12 beta2 momentum2 volatility2 SMMA2 t12 t22 t32 TMA2 mid2 VIDYA2 VMAalpha2 sc2 VMA2 WWMA2 EMA12 EMA22 |
| Line WidthThis is the width of the line plotted that represents the selected trend | 1 | int | plot |
| Model Long Trades | true | bool | entry Long close Long line 275 line 277 |
| Model Short Trades | false | bool | entry Short close Short line 279 line 281 |
| Individual Trend Settings | |||
| ALMA OffsetThis only applies when ALMA is selected | 0.85 | float | ALMA ALMA2 |
| ALMA SigmaThis only applies when ALMA is selected | 6 | float | ALMA ALMA2 |
| ATR Multiplier For SuperTrendThis only applies when SuperTrend is selected | 3 | float | unused |
| ATR Length For SuperTrendThis only applies when SuperTrend is selected | 12 | int | unused |
| DSMA Super Smoother Filter LengthThis only applies when EDSMA is selected | 20 | int · min 1 | ssf ssf2 |
| DSMA Super Smoother Filter PolesThis only applies when EDSMA is selected | 2 | int · options [2, 3] | ssf ssf2 |
| JMA Power ParameterThis only applies when JMA is selected | 2 | int | alpha alpha2 |
| JMA Phase ParameterThis only applies when JMA is selected | -45 | int · min -110 · max 110 · step 10 | phaseRatio |
| KAMA's AlphaThis only applies when KAMA is selected | 3 | float · min 1 · step 0.5 | fastAlpha |
| Linear Regression OffsetThis only applies when Linear Regression is selected | 0 | int | LinReg LinReg2 |
| VAMA Volatility lookbackThis only applies when VAMA is selected | 12 | int | vol_up vol_down vol_up2 vol_down2 |
What it calculates
- ALMAPrice Source (close), Fast Trend Length (10), ALMA Offset (0.85), ALMA Sigma (6)
ALMA · line 29 - EMAPrice Source (close), Fast Trend Length (10)
EMA · line 30 - HMAPrice Source (close), Fast Trend Length (10)
HMA · line 31 - LinregPrice Source (close), Fast Trend Length (10), Linear Regression Offset (0)
LinReg · line 32 - RMAPrice Source (close), Fast Trend Length (10)
RMA · line 33 - SMAPrice Source (close), Fast Trend Length (10)
SMA · line 34 - VWMAPrice Source (close), Fast Trend Length (10)
VWMA · line 35 - WMAPrice Source (close), Fast Trend Length (10)
WMA · line 36 - ALMAPrice Source (close), Slow Trend Length (200), ALMA Offset (0.85), ALMA Sigma (6)
ALMA2 · line 37 - EMAPrice Source (close), Slow Trend Length (200)
EMA2 · line 38 - HMAPrice Source (close), Slow Trend Length (200)
HMA2 · line 39 - LinregPrice Source (close), Slow Trend Length (200), Linear Regression Offset (0)
LinReg2 · line 40 - RMAPrice Source (close), Slow Trend Length (200)
RMA2 · line 41 - SMAPrice Source (close), Slow Trend Length (200)
SMA2 · line 42 - VWMAPrice Source (close), Slow Trend Length (200)
VWMA2 · line 43 - WMAPrice Source (close), Slow Trend Length (200)
WMA2 · line 44 - EMAPrice Source (close), Fast Trend Length (10)
de1 · line 47 - EMAde1, Fast Trend Length (10)
de2 · line 48 - EMAPrice Source (close), Slow Trend Length (200)
de3 · line 50 - EMAde3, Slow Trend Length (200)
de4 · line 51 - Stdevssf, Fast Trend Length (10)
stdev · line 82 - Stdevssf2, Slow Trend Length (200)
stdev2 · line 114 - ChangePrice Source (close), Fast Trend Length (10)
momentum · line 147 - ChangePrice Source (close)
volatility · line 148 - ChangePrice Source (close), Slow Trend Length (200)
momentum2 · line 153 - ChangePrice Source (close)
volatility2 · line 154 - SMAPrice Source (close), Fast Trend Length (10)
SMMA · line 160 - SMAPrice Source (close), Slow Trend Length (200)
SMMA2 · line 162 - EMAPrice Source (close), Fast Trend Length (10)
t1 · line 164 - EMAt1, Fast Trend Length (10)
t2 · line 165 - EMAt2, Fast Trend Length (10)
t3 · line 166 - EMAPrice Source (close), Slow Trend Length (200)
t12 · line 168 - EMAt12, Slow Trend Length (200)
t22 · line 169 - EMAt22, Slow Trend Length (200)
t32 · line 170 - SMAta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1
TMA · line 173 - SMAta.sma(src, math.ceil(length2 / 2)), math.floor(length2 / 2) + 1
TMA2 · line 174 - EMAPrice Source (close), Fast Trend Length (10)
mid · line 176 - Highestdev, VAMA Volatility lookback (12)
vol_up · line 178 - Lowestdev, VAMA Volatility lookback (12)
vol_down · line 179 - EMAPrice Source (close), Slow Trend Length (200)
mid2 · line 181 - Highestdev2, VAMA Volatility lookback (12)
vol_up2 · line 183 - Lowestdev2, VAMA Volatility lookback (12)
vol_down2 · line 184 - SMAPrice Source (close), Fast Trend Length (10)
VIDYA · line 194 - SMAPrice Source (close), Slow Trend Length (200)
VIDYA2 · line 202 - HighestiS, Fast Trend Length (10)
hhv · line 222 - LowestiS, Fast Trend Length (10)
llv · line 223 - SMAPrice Source (close), Fast Trend Length (10)
VMA · line 227 - HighestiS2, Fast Trend Length (10)
hhv2 · line 246 - LowestiS2, Fast Trend Length (10)
llv2 · line 247 - SMAPrice Source (close), Slow Trend Length (200)
VMA2 · line 251 - EMAPrice Source (close), Fast Trend Length (10)
EMA1a · line 258 - EMAEMA1a, Fast Trend Length (10)
EMA2a · line 259 - EMAPrice Source (close), Slow Trend Length (200)
EMA12 · line 262 - EMAEMA12, Slow Trend Length (200)
EMA22 · line 263
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 159 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (InDateRange and Long==true and FastTrend>SlowTrend) | On | 276 |
| Close Long | (InDateRange and Long==true and FastTrend<SlowTrend) | On | 278 |
| Open Short short | (InDateRange and Short==true and FastTrend<SlowTrend) | On | 280 |
| Close Short | (InDateRange and Short==true and FastTrend>SlowTrend) | On | 282 |
| Close | (not InDateRange) | On | 284 |
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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +33.0% | +102.5% | 3 | 67% | 9.30 | 7.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +13.1% | +5.5% | 7 | 14% | 2.35 | 9.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.6% | +9.8% | 3 | 33% | 0.98 | 28.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +34.3% | +8.4% | 2 | 50% | 16.40 | 3.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −28.8% | +16.7% | 6 | 17% | 0.17 | 33.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +32.4% | +21.5% | 5 | 20% | 4.79 | 9.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −22.7% | +148.3% | 9 | 22% | 0.52 | 33.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +24.7% | +17.1% | 2 | 50% | 18.82 | 3.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 | 0 | — | $0.00 |
| Sideways market | 3 | 67% | $330,106.00 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
3.2%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.2% to 3.2%; the tick is what actually happened, 3.2%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 22 Sep 2024 63,578.80 | 10 Mar 2025 78,595.90 | 169 | $236,197.00 |
| long | 27 Mar 2025 87,232.00 | 28 Mar 2025 84,424.40 | 1 | −$39,788.10 |
| long | 22 Apr 2025 93,443.00 | 5 Nov 2025 103,885.00 | 197 | $133,697.00 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Multi Trend Cross Strategy Template this page | — | v5 strategy | +33.0% | 3 | 7.3% |
| Multi MA Trend Following Strategy Template by TradeAutomation | alma ema hma linreg rma sma vwma wma stdev highest lowest | v5 strategy | +12.3% | 3 | 26.9% |
| Ultra Moving Average Rating Trend Strategy by exlux99 | ema wma highest lowest sma rma alma linreg vwma hma | v5 strategy | +2.8% | 5 | 2.4% |
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma alma rma linreg vwma | v4 strategy | No trades on this market | ||
| VCP pivot buy by perrycc007 | sma ema rma vwma wma lowest highest | v4 strategy | does not run in Zeal Terminal | ||
| BTC 15 min by RafaelZioni | sma ema wma linreg stdev highest lowest | v4 strategy | −25.7% | 119 | 38.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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 3 before, 7 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version=5+// @version=6// Author = TradeAutomation⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 148 ms | Yes 1,000 bars in 236 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// @version=5// Author = TradeAutomationstrategy(title="Multi Trend Cross Strategy Template", shorttitle="Multi Trend Cross Strategy", process_orders_on_close=true, overlay=true, commission_type=strategy.commission.cash_per_contract, commission_value=0.0035, initial_capital = 1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Backtest Date Range Inputs // StartTime = input.time(defval=timestamp('01 Jan 2000 05:00 +0000'), group="Date Range", title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), group="Date Range", title='End Time')InDateRange = time>=StartTime and time<=EndTime// Trend Selector //TrendSelectorInput = input.string(title="Fast Trend Selector", defval="EMA", group="Core Settings", options=["ALMA", "DEMA", "DSMA", "EMA", "HMA", "JMA", "KAMA", "Linear Regression (LSMA)", "RMA", "SMA", "SMMA", "Price Source", "TEMA", "TMA", "VAMA", "VIDYA", "VMA", "VWMA", "WMA", "WWMA", "ZLEMA"], tooltip="Select your fast trend")TrendSelectorInput2 = input.string(title="Slow Trend Selector", defval="EMA", group="Core Settings", options=["ALMA", "DEMA", "DSMA", "EMA", "HMA", "JMA", "KAMA", "Linear Regression (LSMA)", "RMA", "SMA", "SMMA", "Price Source", "TEMA", "TMA", "VAMA", "VIDYA", "VMA", "VWMA", "WMA", "WWMA", "ZLEMA"], tooltip="Select your slow trend")src = input.source(close, "Price Source", group="Core Settings", tooltip="This is the price source being used for the trends to calculate based on")length = input.int(10, "Fast Trend Length", group="Core Settings", step=5, tooltip="A long is entered when the selected fast trend crosses over the selected slow trend")length2 = input.int(200, "Slow Trend Length", group="Core Settings", step=5, tooltip="A long is entered when the selected fast trend crosses over the selected slow trend")LineWidth = input.int(1, "Line Width", group="Core Settings", tooltip="This is the width of the line plotted that represents the selected trend")// Individual Moving Average / Regression Setting //AlmaOffset = input.float(0.85, "ALMA Offset", group="Individual Trend Settings", tooltip="This only applies when ALMA is selected")AlmaSigma = input.float(6, "ALMA Sigma", group="Individual Trend Settings", tooltip="This only applies when ALMA is selected")ATRFactor = input.float(3, "ATR Multiplier For SuperTrend", group="Individual Trend Settings", tooltip="This only applies when SuperTrend is selected")ATRLength = input.int(12, "ATR Length For SuperTrend", group="Individual Trend Settings", tooltip="This only applies when SuperTrend is selected")ssfLength = input.int(20, "DSMA Super Smoother Filter Length", minval=1, tooltip="This only applies when EDSMA is selected", group="Individual Trend Settings")ssfPoles = input.int(2, "DSMA Super Smoother Filter Poles", options=[2, 3], tooltip="This only applies when EDSMA is selected", group="Individual Trend Settings")JMApower = input.int(2, "JMA Power Parameter", group="Individual Trend Settings", tooltip="This only applies when JMA is selected")phase = input.int(-45, title="JMA Phase Parameter", step=10, minval=-110, maxval=110, group="Individual Trend Settings", tooltip="This only applies when JMA is selected")KamaAlpha = input.float(3, "KAMA's Alpha", minval=1,step=0.5, group="Individual Trend Settings", tooltip="This only applies when KAMA is selected")LinRegOffset = input.int(0, "Linear Regression Offset", group="Individual Trend Settings", tooltip="This only applies when Linear Regression is selected")VAMALookback =input.int(12, "VAMA Volatility lookback", group="Individual Trend Settings", tooltip="This only applies when VAMA is selected")// Trend Indicators With Library Functions //ALMA = ta.alma(src, length, AlmaOffset, AlmaSigma) EMA = ta.ema(src, length)HMA = ta.hma(src, length)LinReg = ta.linreg(src, length, LinRegOffset)RMA = ta.rma(src, length)SMA = ta.sma(src, length)VWMA = ta.vwma(src, length)WMA = ta.wma(src, length)ALMA2 = ta.alma(src, length2, AlmaOffset, AlmaSigma) EMA2 = ta.ema(src, length2)HMA2 = ta.hma(src, length2)LinReg2 = ta.linreg(src, length2, LinRegOffset)RMA2 = ta.rma(src, length2)SMA2 = ta.sma(src, length2)VWMA2 = ta.vwma(src, length2)WMA2 = ta.wma(src, length2)// Additional Trend Indicators Built In And/Or Open Sourced ////DEMAde1 = ta.ema(src, length)de2 = ta.ema(de1, length)DEMA = 2 * de1 - de2de3 = ta.ema(src, length2)de4 = ta.ema(de3, length2)DEMA2 = 2 * de3 - de4// Ehlers Deviation-Scaled Moving Average - DSMA [Everget]PI = 2 * math.asin(1)get2PoleSSF(src, length) => arg = math.sqrt(2) * PI / length a1 = math.exp(-arg) b1 = 2 * a1 * math.cos(arg) c2 = b1 c3 = -math.pow(a1, 2) c1 = 1 - c2 - c3 var ssf = 0.0 ssf := c1 * src + c2 * nz(ssf[1]) + c3 * nz(ssf[2])get3PoleSSF(src, length) => arg = PI / length a1 = math.exp(-arg) b1 = 2 * a1 * math.cos(1.738 * arg) c1 = math.pow(a1, 2) coef2 = b1 + c1 coef3 = -(c1 + b1 * c1) coef4 = math.pow(c1, 2) coef1 = 1 - coef2 - coef3 - coef4 var ssf = 0.0 ssf := coef1 * src + coef2 * nz(ssf[1]) + coef3 * nz(ssf[2]) + coef4 * nz(ssf[3])zeros = src - nz(src[2])avgZeros = (zeros + zeros[1]) / 2// Ehlers Super Smoother Filter ssf = ssfPoles == 2 ? get2PoleSSF(avgZeros, ssfLength) : get3PoleSSF(avgZeros, ssfLength)// Rescale filter in terms of Standard Deviationsstdev = ta.stdev(ssf, length)scaledFilter = stdev != 0 ? ssf / stdev : 0alpha1 = 5 * math.abs(scaledFilter) / lengthEDSMA = 0.0EDSMA := alpha1 * src + (1 - alpha1) * nz(EDSMA[1])get2PoleSSF2(src, length2) => arg = math.sqrt(2) * PI / length2 a1 = math.exp(-arg) b1 = 2 * a1 * math.cos(arg) c2 = b1 c3 = -math.pow(a1, 2) c1 = 1 - c2 - c3 var ssf2 = 0.0 ssf2 := c1 * src + c2 * nz(ssf2[1]) + c3 * nz(ssf2[2])get3PoleSSF2(src, length2) => arg = PI / length2 a1 = math.exp(-arg) b1 = 2 * a1 * math.cos(1.738 * arg) c1 = math.pow(a1, 2) coef2 = b1 + c1 coef3 = -(c1 + b1 * c1) coef4 = math.pow(c1, 2) coef1 = 1 - coef2 - coef3 - coef4 var ssf2 = 0.0 ssf2 := coef1 * src + coef2 * nz(ssf2[1]) + coef3 * nz(ssf2[2]) + coef4 * nz(ssf2[3])// Ehlers Super Smoother Filter ssf2 = ssfPoles == 2 ? get2PoleSSF2(avgZeros, ssfLength) : get3PoleSSF2(avgZeros, ssfLength)// Rescale filter in terms of Standard Deviationsstdev2 = ta.stdev(ssf2, length2)scaledFilter2 = stdev2 != 0 ? ssf2 / stdev2 : 0alpha12 = 5 * math.abs(scaledFilter2) / length2EDSMA2 = 0.0EDSMA2 := alpha12 * src + (1 - alpha12) * nz(EDSMA2[1])//JMA [Everget]phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2)alpha = math.pow(beta, JMApower)var JMA = 0.0var e0 = 0.0e0 := (1 - alpha) * src + alpha * nz(e0[1])var e1 = 0.0e1 := (src - e0) * (1 - beta) + beta * nz(e1[1])var e2 = 0.0e2 := (e0 + phaseRatio * e1 - nz(JMA[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1])JMA := e2 + nz(JMA[1])beta2 = 0.45 * (length2 - 1) / (0.45 * (length2 - 1) + 2)alpha2 = math.pow(beta2, JMApower)var JMA2 = 0.0var e02 = 0.0e02 := (1 - alpha2) * src + alpha2 * nz(e02[1])var e12 = 0.0e12 := (src - e02) * (1 - beta2) + beta2 * nz(e12[1])var e22 = 0.0e22 := (e02 + phaseRatio * e12 - nz(JMA2[1])) * math.pow(1 - alpha2, 2) + math.pow(alpha2, 2) * nz(e22[1])JMA2 := e22 + nz(JMA2[1])//KAMA [Everget]var KAMA = 0.0fastAlpha = 2.0 / (KamaAlpha + 1)slowAlpha = 2.0 / 31momentum = math.abs(ta.change(src, length))volatility = math.sum(math.abs(ta.change(src)), length)efficiencyRatio = volatility != 0 ? momentum / volatility : 0smoothingConstant = math.pow((efficiencyRatio * (fastAlpha - slowAlpha)) + slowAlpha, 2)KAMA := nz(KAMA[1], src) + smoothingConstant * (src - nz(KAMA[1], src))var KAMA2 = 0.0momentum2 = math.abs(ta.change(src, length2))volatility2 = math.sum(math.abs(ta.change(src)), length2)efficiencyRatio2 = volatility2 != 0 ? momentum2 / volatility2 : 0smoothingConstant2 = math.pow((efficiencyRatio2 * (fastAlpha - slowAlpha)) + slowAlpha, 2)KAMA2 := nz(KAMA2[1], src) + smoothingConstant2 * (src - nz(KAMA2[1], src))//SMMAvar SMMA = 0.0SMMA := na(SMMA[1]) ? ta.sma(src, length) : (SMMA[1] * (length - 1) + src) / lengthvar SMMA2 = 0.0SMMA2 := na(SMMA2[1]) ? ta.sma(src, length2) : (SMMA2[1] * (length2 - 1) + src) / length2//TEMAt1 = ta.ema(src, length)t2 = ta.ema(t1, length)t3 = ta.ema(t2, length)TEMA = 3 * (t1 - t2) + t3t12 = ta.ema(src, length2)t22 = ta.ema(t12, length2)t32 = ta.ema(t22, length2)TEMA2 = 3 * (t12 - t22) + t32//TMATMA = ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)TMA2 = ta.sma(ta.sma(src, math.ceil(length2 / 2)), math.floor(length2 / 2) + 1)//VAMA [Duyck]mid=ta.ema(src,length)dev=src-midvol_up=ta.highest(dev,VAMALookback)vol_down=ta.lowest(dev,VAMALookback)VAMA = mid+math.avg(vol_up,vol_down)mid2=ta.ema(src,length2)dev2=src-mid2vol_up2=ta.highest(dev2,VAMALookback)vol_down2=ta.lowest(dev2,VAMALookback)VAMA2 = mid2+math.avg(vol_up2,vol_down2)//VIDYA [KivancOzbilgic]var VIDYA=0.0VMAalpha=2/(length+1)ud1=src>src[1] ? src-src[1] : 0dd1=src<src[1] ? src[1]-src : 0UD=math.sum(ud1,9)DD=math.sum(dd1,9)CMO=nz((UD-DD)/(UD+DD))VIDYA := na(VIDYA[1]) ? ta.sma(src, length) : nz(VMAalpha*math.abs(CMO)*src)+(1-VMAalpha*math.abs(CMO))*nz(VIDYA[1])var VIDYA2=0.0VMAalpha2=2/(length2+1)ud12=src>src[1] ? src-src[1] : 0dd12=src<src[1] ? src[1]-src : 0UD2=math.sum(ud12,9)DD2=math.sum(dd12,9)CMO2=nz((UD2-DD2)/(UD2+DD2))VIDYA2 := na(VIDYA2[1]) ? ta.sma(src, length2) : nz(VMAalpha2*math.abs(CMO2)*src)+(1-VMAalpha2*math.abs(CMO2))*nz(VIDYA2[1])//VMA [LazyBear]sc = 1/lengthpdm = math.max((src - src[1]), 0)mdm = math.max((src[1] - src), 0)var pdmS = 0.0var mdmS = 0.0pdmS := ((1 - sc)*nz(pdmS[1]) + sc*pdm)mdmS := ((1 - sc)*nz(mdmS[1]) + sc*mdm)s = pdmS + mdmSpdi = pdmS/smdi = mdmS/svar pdiS = 0.0var mdiS = 0.0pdiS := ((1 - sc)*nz(pdiS[1]) + sc*pdi)mdiS := ((1 - sc)*nz(mdiS[1]) + sc*mdi)d = math.abs(pdiS - mdiS)s1 = pdiS + mdiSvar iS = 0.0iS := ((1 - sc)*nz(iS[1]) + sc*d/s1)hhv = ta.highest(iS, length) llv = ta.lowest(iS, length) d1 = hhv - llvvi = (iS - llv)/d1var VMA=0.0VMA := na(VMA[1]) ? ta.sma(src, length) : sc*vi*src + (1 - sc*vi)*nz(VMA[1])sc2 = 1/length2pdm2 = math.max((src - src[1]), 0)mdm2 = math.max((src[1] - src), 0)var pdmS2 = 0.0var mdmS2 = 0.0pdmS2 := ((1 - sc2)*nz(pdmS2[1]) + sc2*pdm2)mdmS2 := ((1 - sc2)*nz(mdmS2[1]) + sc2*mdm2)s2 = pdmS2 + mdmS2pdi2 = pdmS2/s2mdi2 = mdmS2/s2var pdiS2 = 0.0var mdiS2 = 0.0pdiS2 := ((1 - sc2)*nz(pdiS2[1]) + sc2*pdi2)mdiS2 := ((1 - sc2)*nz(mdiS2[1]) + sc2*mdi2)d2 = math.abs(pdiS2 - mdiS2)s12 = pdiS2 + mdiS2var iS2 = 0.0iS2 := ((1 - sc2)*nz(iS2[1]) + sc2*d2/s12)hhv2 = ta.highest(iS2, length) llv2 = ta.lowest(iS2, length) d12 = hhv2 - llv2vi2 = (iS2 - llv2)/d12var VMA2=0.0VMA2 := na(VMA2[1]) ? ta.sma(src, length2) : sc2*vi2*src + (1 - sc2*vi2)*nz(VMA2[1])//WWMAvar WWMA=0.0WWMA := (1/length)*src + (1-(1/length))*nz(WWMA[1])var WWMA2=0.0WWMA2 := (1/length2)*src + (1-(1/length2))*nz(WWMA2[1])//Zero Lag EMA [KivancOzbilgic]EMA1a = ta.ema(src,length)EMA2a = ta.ema(EMA1a,length)Diff = EMA1a - EMA2aZLEMA = EMA1a + DiffEMA12 = ta.ema(src,length2)EMA22 = ta.ema(EMA12,length2)Diff2 = EMA12 - EMA22ZLEMA2 = EMA12 + Diff2// Trend Mapping and Plotting //FastTrend = TrendSelectorInput == "ALMA" ? ALMA : TrendSelectorInput == "DEMA" ? DEMA : TrendSelectorInput == "DSMA" ? EDSMA : TrendSelectorInput == "EMA" ? EMA : TrendSelectorInput == "HMA" ? HMA : TrendSelectorInput == "JMA" ? JMA : TrendSelectorInput == "KAMA" ? KAMA : TrendSelectorInput == "Linear Regression (LSMA)" ? LinReg : TrendSelectorInput == "RMA" ? RMA : TrendSelectorInput == "SMA" ? SMA : TrendSelectorInput == "SMMA" ? SMMA : TrendSelectorInput == "Price Source" ? src : TrendSelectorInput == "TEMA" ? TEMA : TrendSelectorInput == "TMA" ? TMA : TrendSelectorInput == "VAMA" ? VAMA : TrendSelectorInput == "VIDYA" ? VIDYA : TrendSelectorInput == "VMA" ? VMA : TrendSelectorInput == "VWMA" ? VWMA : TrendSelectorInput == "WMA" ? WMA : TrendSelectorInput == "WWMA" ? WWMA : TrendSelectorInput == "ZLEMA" ? ZLEMA : SMASlowTrend = TrendSelectorInput2 == "ALMA" ? ALMA2 : TrendSelectorInput2 == "DEMA" ? DEMA2 : TrendSelectorInput2 == "DSMA" ? EDSMA2 : TrendSelectorInput2 == "EMA" ? EMA2 : TrendSelectorInput2 == "HMA" ? HMA2 : TrendSelectorInput2 == "JMA" ? JMA2 : TrendSelectorInput2 == "KAMA" ? KAMA2 : TrendSelectorInput2 == "Linear Regression (LSMA)" ? LinReg2 : TrendSelectorInput2 == "RMA" ? RMA2 : TrendSelectorInput2 == "SMA" ? SMA2 : TrendSelectorInput2 == "SMMA" ? SMMA2 : TrendSelectorInput2 == "Price Source" ? src : TrendSelectorInput2 == "TEMA" ? TEMA2 : TrendSelectorInput2 == "TMA" ? TMA2 : TrendSelectorInput2 == "VAMA" ? VAMA2 : TrendSelectorInput2 == "VIDYA" ? VIDYA2 : TrendSelectorInput2 == "VMA" ? VMA2 : TrendSelectorInput2 == "VWMA" ? VWMA2 : TrendSelectorInput2 == "WMA" ? WMA2 : TrendSelectorInput2 == "WWMA" ? WWMA2 : TrendSelectorInput2 == "ZLEMA" ? ZLEMA2 : SMA2plot(FastTrend, color=color.green, linewidth=LineWidth)plot(SlowTrend, color=color.red, linewidth=LineWidth)//Short & Long OptionsLong = input.bool(true, "Model Long Trades", group="Core Settings")Short = input.bool(false, "Model Short Trades", group="Core Settings")// Entry & Exit Functions //if (InDateRange and Long==true and FastTrend>SlowTrend) strategy.entry("Long", strategy.long, alert_message="Long")if (InDateRange and Long==true and FastTrend<SlowTrend) strategy.close("Long", alert_message="Close Long")if (InDateRange and Short==true and FastTrend<SlowTrend) strategy.entry("Short", strategy.short, alert_message="Short")if (InDateRange and Short==true and FastTrend>SlowTrend) strategy.close("Short", alert_message="Cover Short") if (not InDateRange) strategy.close_all(alert_message="End of Date Range")