Pine Script v5 · Strategy
MACD ReLoaded STRATEGY
A Pine Script v5 strategy built on EMA (close, 12), Linreg (close, 12) and WMA (src, length). It has 2 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 is one contract and pays no commission. 13 settings; defaults include Source close, Short Moving Average Length 12 and Long Moving Average Length 26.
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 MACD ReLoaded STRATEGY repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did MACD ReLoaded STRATEGY do on BTCUSDT 1D with default settings?
- +7.83%
- From 26 Jan 2024 to 21 Oct 2026, over 31 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does MACD ReLoaded STRATEGY 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: 31 before, 18 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 MACD ReLoaded STRATEGY use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does MACD ReLoaded STRATEGY run in Zeal Terminal?
- Yes
- It compiles in 81 ms and runs 1,000 bars in 160 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +7.83%
- $78,322.40
- Buy and hold
- +102.5%
- same period
- Closed trades
- 31
- 13 won · 18 lost
- Profitable
- 41.9%
- of closed trades
- Profit factor
- 1.86
- gross profit ÷ gross loss
- Max drawdown
- 5.11%
- −$54,549.60
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A short position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Source | close | source | vud1 vdd1 VAR DEMA WWMA zxEMAData ZLEMA lrc lrc1 TSF HMA T3e1 ma MA12 vud11 vdd11 VAR1 DEMA1 WWMA1 zxEMAData1 ZLEMA1 lrc11 TSF1 HMA1 T3e11 ma1 MA26 |
| Short Moving Average Length | 12 | int · min 1 | valpha VAR DEMA wwalpha WWMA zxLag ZLEMA lrc TSF HMA T3e1 T3e2 T3e3 T3e4 T3e5 T3e6 ma MA12 lrc1 |
| Long Moving Average Length | 26 | int · min 1 | lrc1 valpha1 VAR1 DEMA1 wwalpha1 WWMA1 zxLag1 ZLEMA1 lrc11 TSF1 HMA1 T3e11 T3e21 T3e31 T3e41 T3e51 T3e61 ma1 MA26 |
| Trigger Length | 9 | int · min 1 | valpha2 VAR2 DEMA2 wwalpha2 WWMA2 zxLag2 ZLEMA2 lrc2 lrc12 TSF2 HMA2 T3e12 T3e22 T3e32 T3e42 T3e52 T3e62 ma2 MATR |
| TILLSON T3 Volume Factor | 0.7 | float · step 0.1 | T3c1 T3c2 T3c3 T3c4 T3c11 T3c21 T3c31 T3c41 T3c12 T3c22 T3c32 T3c42 |
| Bar Coloring On/Off ? | true | bool | barcolor |
| Moving Average Type | VAR | string · options ['SMA', 'EMA', 'WMA', 'DEMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF', 'HULL', 'TILL'] | line 59 line 62 line 65 line 68 line 71 line 74 line 77 line 80 line 83 line 86 line 89 line 139 line 142 line 145 line 148 line 151 line 154 line 157 line 160 line 163 line 166 line 169 line 220 line 223 line 226 line 229 line 232 line 235 line 238 line 241 line 244 line 247 line 250 |
| From Month | 9 | int · min 1 · max 12 | start |
| From Day | 1 | int · min 1 · max 31 | start |
| From Year | 2018 | int · min 999 | start |
| To Month | 1 | int · min 1 · max 12 | finish |
| To Day | 1 | int · min 1 · max 31 | finish |
| To Year | 9999 | int · min 999 | finish |
What it calculates
- EMASource (close), Short Moving Average Length (12)
DEMA · line 25 - LinregSource (close), Short Moving Average Length (12), 0
lrc · line 39 - LinregSource (close), Long Moving Average Length (26), 0
lrc1 · line 119 - WMA2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(length))
HMA · line 45 - EMASource (close), Short Moving Average Length (12)
T3e1 · line 46 - EMAT3e1, Short Moving Average Length (12)
T3e2 · line 47 - EMAT3e2, Short Moving Average Length (12)
T3e3 · line 48 - EMAT3e3, Short Moving Average Length (12)
T3e4 · line 49 - EMAT3e4, Short Moving Average Length (12)
T3e5 · line 50 - EMAT3e5, Short Moving Average Length (12)
T3e6 · line 51 - SMA / EMA / WMASource (close), Short Moving Average Length (12)
ma · line 60 - EMASource (close), Long Moving Average Length (26)
DEMA1 · line 105 - LinregSource (close), Long Moving Average Length (26), 1
lrc11 · line 120 - WMA2 * ta.wma(src, length1 / 2) - ta.wma(src, length1), math.round(math.sqrt(length1))
HMA1 · line 125 - EMASource (close), Long Moving Average Length (26)
T3e11 · line 126 - EMAT3e11, Long Moving Average Length (26)
T3e21 · line 127 - EMAT3e21, Long Moving Average Length (26)
T3e31 · line 128 - EMAT3e31, Long Moving Average Length (26)
T3e41 · line 129 - EMAT3e41, Long Moving Average Length (26)
T3e51 · line 130 - EMAT3e51, Long Moving Average Length (26)
T3e61 · line 131 - SMA / EMA / WMASource (close), Long Moving Average Length (26)
ma1 · line 140 - EMAsrc2, Trigger Length (9)
DEMA2 · line 186 - Linregsrc2, Trigger Length (9), 0
lrc2 · line 200 - Linregsrc2, Trigger Length (9), 1
lrc12 · line 201 - WMA2 * ta.wma(src2, length2 / 2) - ta.wma(src2, length2), math.round(math.sqrt(length2))
HMA2 · line 206 - EMAsrc2, Trigger Length (9)
T3e12 · line 207 - EMAT3e12, Trigger Length (9)
T3e22 · line 208 - EMAT3e22, Trigger Length (9)
T3e32 · line 209 - EMAT3e32, Trigger Length (9)
T3e42 · line 210 - EMAT3e42, Trigger Length (9)
T3e52 · line 211 - EMAT3e52, Trigger Length (9)
T3e62 · line 212 - SMA / EMA / WMAsrc2, Trigger Length (9)
ma2 · line 221 - Crossoverhist, 0
buySignal · line 266 - Crossunderhist, 0
sellSignal · line 269 - BarssincebuySignal
buy1 · line 272 - BarssincesellSignal
sell1 · line 273
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 83 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 MacdLong long | ta.crossover(hist, 0) | On | 268 |
| Open MacdShort short | ta.crossunder(hist, 0) | On | 271 |
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.
- 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 | +7.8% | +102.5% | 31 | 42% | 1.86 | 5.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.7% | +5.5% | 32 | 41% | 1.57 | 1.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.6% | +9.8% | 31 | 42% | 2.56 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 36 | 25% | 1.38 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 33 | 39% | 1.56 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 34 | 35% | 1.52 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 33 | 36% | 1.30 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 36 | 39% | 1.15 | 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 | 11 | 36% | −$7,562.48 |
| Sideways market | 15 | 40% | $61,422.20 |
| Falling market | 5 | 60% | $24,462.60 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
4.7%
The 95th percentile of the worst drawdown when the same 31 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.9% to 4.7%; the tick is what actually happened, 3.9%. Order luck alone moves it this much.
All 31 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 4 Feb 2024 43,011.10 | 9 Mar 2024 68,124.20 | 34 | $25,113.10 |
| short | 9 Mar 2024 68,124.20 | 22 May 2024 70,148.30 | 74 | −$2,024.14 |
| long | 22 May 2024 70,148.30 | 24 May 2024 67,969.70 | 2 | −$2,178.68 |
| short | 24 May 2024 67,969.70 | 17 Jul 2024 65,044.00 | 54 | $2,925.66 |
| long | 17 Jul 2024 65,044.00 | 4 Aug 2024 60,698.00 | 18 | −$4,346.01 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.20 | 20 | −$3,339.25 |
| long | 24 Aug 2024 64,037.20 | 2 Sep 2024 57,301.80 | 9 | −$6,735.47 |
| short | 2 Sep 2024 57,301.80 | 16 Sep 2024 59,132.00 | 14 | −$1,830.23 |
| long | 16 Sep 2024 59,132.00 | 10 Oct 2024 60,636.00 | 24 | $1,504.01 |
| short | 10 Oct 2024 60,636.00 | 14 Oct 2024 62,870.00 | 4 | −$2,234.01 |
| long | 14 Oct 2024 62,870.00 | 22 Dec 2024 97,292.00 | 69 | $34,422.00 |
| short | 22 Dec 2024 97,292.00 | 19 Jan 2025 104,556.00 | 28 | −$7,264.23 |
| long | 19 Jan 2025 104,556.00 | 20 Jan 2025 101,332.00 | 1 | −$3,224.66 |
| short | 20 Jan 2025 101,332.00 | 18 Apr 2025 84,947.90 | 88 | $16,383.70 |
| long | 18 Apr 2025 84,947.90 | 1 Jun 2025 104,592.00 | 44 | $19,644.00 |
| short | 1 Jun 2025 104,592.00 | 10 Jul 2025 111,234.00 | 39 | −$6,642.12 |
| long | 10 Jul 2025 111,234.00 | 1 Aug 2025 115,764.00 | 22 | $4,530.07 |
| short | 1 Aug 2025 115,764.00 | 14 Aug 2025 123,306.00 | 13 | −$7,542.37 |
| long | 14 Aug 2025 123,306.00 | 20 Aug 2025 112,873.00 | 6 | −$10,433.50 |
| short | 20 Aug 2025 112,873.00 | 17 Sep 2025 116,789.00 | 28 | −$3,916.01 |
| long | 17 Sep 2025 116,789.00 | 23 Sep 2025 112,651.00 | 6 | −$4,137.97 |
| short | 23 Sep 2025 112,651.00 | 3 Oct 2025 120,529.00 | 10 | −$7,878.36 |
| long | 3 Oct 2025 120,529.00 | 13 Oct 2025 114,959.00 | 10 | −$5,570.54 |
| short | 13 Oct 2025 114,959.00 | 5 Dec 2025 92,078.10 | 53 | $22,880.80 |
| long | 5 Dec 2025 92,078.10 | 31 Jan 2026 84,260.50 | 57 | −$7,817.56 |
| short | 31 Jan 2026 84,260.50 | 5 Mar 2026 72,666.80 | 33 | $11,593.70 |
| long | 5 Mar 2026 72,666.80 | 23 May 2026 75,539.50 | 79 | $2,872.73 |
| short | 23 May 2026 75,539.50 | 5 Jul 2026 63,144.00 | 43 | $12,395.50 |
| long | 5 Jul 2026 63,144.00 | 14 Sep 2026 76,842.00 | 71 | $13,698.00 |
| short | 14 Sep 2026 76,842.00 | 21 Sep 2026 81,178.00 | 7 | −$4,336.00 |
| long | 21 Sep 2026 81,178.00 | 11 Oct 2026 82,988.40 | 20 | $1,810.34 |
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 |
|---|---|---|---|---|---|
| MACD ReLoaded STRATEGY this page | — | v5 strategy | +7.8% | 31 | 5.1% |
| Linear Regression MA - Strategy by lazy_capitalist | sma linreg ema | v5 strategy | −1,240.4% | 10 | 318.7% |
| Forex SWING Trader by SoftKill21 | wma ema sma | v4 strategy | No trades on this market | ||
| Twin Optimized Trend Tracker Strategy TOTT by KivancOzbilgic | linreg sma barssince | v5 strategy | +4.5% | 8 | 1.4% |
| Dazzling Bolts by OrcChieftain | sma ema barssince | v4 strategy | +8.5% | 14 | 13.0% |
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma linreg | v4 strategy | No trades on this market | ||
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.
- 2 settings use the untyped input() (line 7, 12). 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.
Same 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.source()
- Line 12: input() → input.bool()
⋯strategy('MACD ReLoaded', 'MACDReSt', overlay=true)-src = input(close, title='Source')+src = input.source(close, title='Source')length = input.int(12, 'Short Moving Average Length', minval=1)⋯T3a1 = input.float(0.7, 'TILLSON T3 Volume Factor', step=0.1)-barcoloring = input(title='Bar Coloring On/Off ?', defval=true)+barcoloring = input.bool(title='Bar Coloring On/Off ?', defval=true)mav = input.string(title='Moving Average Type', defval='VAR', options=['SMA', 'EMA', 'WMA', 'DEMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF', 'HULL', 'TILL'])⋯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: 31 before, 18 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.
-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 81 ms | Yes 1,000 bars in 160 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.
//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © KivancOzbilgic//developer: Gerald Appel//author: @kivancozbilgicstrategy('MACD ReLoaded', 'MACDReSt', overlay=true)src = input(close, title='Source')length = input.int(12, 'Short Moving Average Length', minval=1)length1 = input.int(26, 'Long Moving Average Length', minval=1)length2 = input.int(9, 'Trigger Length', minval=1)T3a1 = input.float(0.7, 'TILLSON T3 Volume Factor', step=0.1)barcoloring = input(title='Bar Coloring On/Off ?', defval=true)mav = input.string(title='Moving Average Type', defval='VAR', options=['SMA', 'EMA', 'WMA', 'DEMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF', 'HULL', 'TILL'])Var_Func(src, length) => 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]) VARVAR = Var_Func(src, length)DEMA = 2 * ta.ema(src, length) - ta.ema(ta.ema(src, length), length)Wwma_Func(src, length) => wwalpha = 1 / length WWMA = 0.0 WWMA := wwalpha * src + (1 - wwalpha) * nz(WWMA[1]) WWMAWWMA = Wwma_Func(src, length)Zlema_Func(src, length) => zxLag = length / 2 == math.round(length / 2) ? length / 2 : (length - 1) / 2 zxEMAData = src + src - src[zxLag] ZLEMA = ta.ema(zxEMAData, length) ZLEMAZLEMA = Zlema_Func(src, length)Tsf_Func(src, length) => lrc = ta.linreg(src, length, 0) lrc1 = ta.linreg(src, length, 1) lrs = lrc - lrc1 TSF = ta.linreg(src, length, 0) + lrs TSFTSF = Tsf_Func(src, length)HMA = ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(length)))T3e1 = ta.ema(src, length)T3e2 = ta.ema(T3e1, length)T3e3 = ta.ema(T3e2, length)T3e4 = ta.ema(T3e3, length)T3e5 = ta.ema(T3e4, length)T3e6 = ta.ema(T3e5, length)T3c1 = -T3a1 * T3a1 * T3a1T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1T3c3 = -6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3getMA(src, length) => ma = 0.0 if mav == 'SMA' ma := ta.sma(src, length) ma if mav == 'EMA' ma := ta.ema(src, length) ma if mav == 'WMA' ma := ta.wma(src, length) ma if mav == 'DEMA' ma := DEMA ma if mav == 'TMA' ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1) ma if mav == 'VAR' ma := VAR ma if mav == 'WWMA' ma := WWMA ma if mav == 'ZLEMA' ma := ZLEMA ma if mav == 'TSF' ma := TSF ma if mav == 'HULL' ma := HMA ma if mav == 'TILL' ma := T3 ma maMA12 = getMA(src, length)Var_Func1(src, length1) => valpha1 = 2 / (length1 + 1) vud11 = src > src[1] ? src - src[1] : 0 vdd11 = src < src[1] ? src[1] - src : 0 vUD1 = math.sum(vud11, 9) vDD1 = math.sum(vdd11, 9) vCMO1 = nz((vUD1 - vDD1) / (vUD1 + vDD1)) VAR1 = 0.0 VAR1 := nz(valpha1 * math.abs(vCMO1) * src) + (1 - valpha1 * math.abs(vCMO1)) * nz(VAR1[1]) VAR1VAR1 = Var_Func1(src, length1)DEMA1 = 2 * ta.ema(src, length1) - ta.ema(ta.ema(src, length1), length1)Wwma_Func1(src, length1) => wwalpha1 = 1 / length1 WWMA1 = 0.0 WWMA1 := wwalpha1 * src + (1 - wwalpha1) * nz(WWMA1[1]) WWMA1WWMA1 = Wwma_Func1(src, length1)Zlema_Func1(src, length1) => zxLag1 = length1 / 2 == math.round(length1 / 2) ? length1 / 2 : (length1 - 1) / 2 zxEMAData1 = src + src - src[zxLag1] ZLEMA1 = ta.ema(zxEMAData1, length1) ZLEMA1ZLEMA1 = Zlema_Func1(src, length1)Tsf_Func1(src, length1) => lrc1 = ta.linreg(src, length1, 0) lrc11 = ta.linreg(src, length1, 1) lrs1 = lrc1 - lrc11 TSF1 = ta.linreg(src, length1, 0) + lrs1 TSF1TSF1 = Tsf_Func1(src, length1)HMA1 = ta.wma(2 * ta.wma(src, length1 / 2) - ta.wma(src, length1), math.round(math.sqrt(length1)))T3e11 = ta.ema(src, length1)T3e21 = ta.ema(T3e11, length1)T3e31 = ta.ema(T3e21, length1)T3e41 = ta.ema(T3e31, length1)T3e51 = ta.ema(T3e41, length1)T3e61 = ta.ema(T3e51, length1)T3c11 = -T3a1 * T3a1 * T3a1T3c21 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1T3c31 = -6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1T3c41 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1T31 = T3c11 * T3e61 + T3c21 * T3e51 + T3c31 * T3e41 + T3c41 * T3e31getMA1(src, length1) => ma1 = 0.0 if mav == 'SMA' ma1 := ta.sma(src, length1) ma1 if mav == 'EMA' ma1 := ta.ema(src, length1) ma1 if mav == 'WMA' ma1 := ta.wma(src, length1) ma1 if mav == 'DEMA' ma1 := DEMA1 ma1 if mav == 'TMA' ma1 := ta.sma(ta.sma(src, math.ceil(length1 / 2)), math.floor(length1 / 2) + 1) ma1 if mav == 'VAR' ma1 := VAR1 ma1 if mav == 'WWMA' ma1 := WWMA1 ma1 if mav == 'ZLEMA' ma1 := ZLEMA1 ma1 if mav == 'TSF' ma1 := TSF1 ma1 if mav == 'HULL' ma1 := HMA1 ma1 if mav == 'TILL' ma1 := T31 ma1 ma1MA26 = getMA1(src, length1)src2 = MA12 - MA26Var_Func2(src2, length2) => valpha2 = 2 / (length2 + 1) vud12 = src2 > src2[1] ? src2 - src2[1] : 0 vdd12 = src2 < src2[1] ? src2[1] - src2 : 0 vUD2 = math.sum(vud12, 9) vDD2 = math.sum(vdd12, 9) vCMO2 = nz((vUD2 - vDD2) / (vUD2 + vDD2)) VAR2 = 0.0 VAR2 := nz(valpha2 * math.abs(vCMO2) * src2) + (1 - valpha2 * math.abs(vCMO2)) * nz(VAR2[1]) VAR2VAR2 = Var_Func2(src2, length2)DEMA2 = 2 * ta.ema(src2, length2) - ta.ema(ta.ema(src2, length2), length2)Wwma_Func2(src2, length2) => wwalpha2 = 1 / length2 WWMA2 = 0.0 WWMA2 := wwalpha2 * src2 + (1 - wwalpha2) * nz(WWMA2[1]) WWMA2WWMA2 = Wwma_Func2(src2, length2)Zlema_Func2(src2, length2) => zxLag2 = length2 / 2 == math.round(length2 / 2) ? length2 / 2 : (length2 - 1) / 2 zxEMAData2 = src2 + src2 - src2[zxLag2] ZLEMA2 = ta.ema(zxEMAData2, length2) ZLEMA2ZLEMA2 = Zlema_Func2(src2, length2)Tsf_Func2(src2, length2) => lrc2 = ta.linreg(src2, length2, 0) lrc12 = ta.linreg(src2, length2, 1) lrs2 = lrc2 - lrc12 TSF2 = ta.linreg(src2, length2, 0) + lrs2 TSF2TSF2 = Tsf_Func2(src2, length2)HMA2 = ta.wma(2 * ta.wma(src2, length2 / 2) - ta.wma(src2, length2), math.round(math.sqrt(length2)))T3e12 = ta.ema(src2, length2)T3e22 = ta.ema(T3e12, length2)T3e32 = ta.ema(T3e22, length2)T3e42 = ta.ema(T3e32, length2)T3e52 = ta.ema(T3e42, length2)T3e62 = ta.ema(T3e52, length2)T3c12 = -T3a1 * T3a1 * T3a1T3c22 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1T3c32 = -6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1T3c42 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1T32 = T3c12 * T3e62 + T3c22 * T3e52 + T3c32 * T3e42 + T3c42 * T3e32getMA2(src2, length2) => ma2 = 0.0 if mav == 'SMA' ma2 := ta.sma(src2, length2) ma2 if mav == 'EMA' ma2 := ta.ema(src2, length2) ma2 if mav == 'WMA' ma2 := ta.wma(src2, length2) ma2 if mav == 'DEMA' ma2 := DEMA2 ma2 if mav == 'TMA' ma2 := ta.sma(ta.sma(src2, math.ceil(length2 / 2)), math.floor(length2 / 2) + 1) ma2 if mav == 'VAR' ma2 := VAR2 ma2 if mav == 'WWMA' ma2 := WWMA2 ma2 if mav == 'ZLEMA' ma2 := ZLEMA2 ma2 if mav == 'TSF' ma2 := TSF2 ma2 if mav == 'HULL' ma2 := HMA2 ma2 if mav == 'TILL' ma2 := T32 ma2 ma2MATR = getMA2(MA12 - MA26, length2)hist = src2 - MATRFromMonth = input.int(defval=9, title='From Month', minval=1, maxval=12)FromDay = input.int(defval=1, title='From Day', minval=1, maxval=31)FromYear = input.int(defval=2018, title='From Year', minval=999)ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31)ToYear = input.int(defval=9999, title='To Year', minval=999)start = timestamp(FromYear, FromMonth, FromDay, 00, 00)finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)window() => time >= start and time <= finish ? true : falsebuySignal = ta.crossover(hist, 0)if ta.crossover(hist, 0) strategy.entry('MacdLong', strategy.long, comment='MacdLong')sellSignal = ta.crossunder(hist, 0)if ta.crossunder(hist, 0) strategy.entry('MacdShort', strategy.short, comment='MacdShort')buy1 = ta.barssince(buySignal)sell1 = ta.barssince(sellSignal)color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : nabarcolor(barcoloring ? color1 : na)//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)