Pine Script v4 · Strategy
Daytrade strategy RSI CCI EMA 4-8
A Pine Script v4 strategy built on EMA (close, 4), RMA or Change or EMA (14) and CCI (source, 6). It has 4 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. 13 settings; defaults include Length_MA4 4, Source close and Offset 0.
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 Daytrade strategy RSI CCI EMA 4-8 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 Daytrade strategy RSI CCI EMA 4-8 do on BTCUSDT 1D with default settings?
- +0.00%
- From 26 Jan 2024 to 21 Oct 2026, over 26 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Daytrade strategy RSI CCI EMA 4-8 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 Daytrade strategy RSI CCI EMA 4-8 use a stop loss?
- Yes
- strategy.exit sets a stop on line 93, 94.
- Does Daytrade strategy RSI CCI EMA 4-8 run in Zeal Terminal?
- Yes
- It compiles in 20 ms and runs 1,000 bars in 48 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.00%
- $3.12
- Buy and hold
- +102.5%
- same period
- Closed trades
- 26
- 13 won · 13 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 1.25
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- −$3.36
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
ema(rsi, 21) ignores the settings line 25
Line 25 hard-codes 21 where line 8 uses “Length_MA4”. Changing those settings moves one band but not this one.
ema(rsi, 21)ema(rsi, len4) -
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
4 settings have no label
In the settings dialog a (line 38), b (line 39), tp (line 84), sl (line 85) show an empty name. The labels on this page come from the variable names.
-
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 87, 89. 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 ema → ta.ema, rma → ta.rma, max → math.max, change → ta.change, min → math.min, cci → ta.cci, crossover → ta.crossover, crossunder → ta.crossunder.
- 2 strategy calls use the when = argument (line 87, 89). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 26 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 7: input(type = input.integer) → input.int()
- Line 8: ema → ta.ema
- Line 12: input(type = input.integer) → input.int()
- Line 13: ema → ta.ema
- Line 17: rma → ta.rma
14 more edits
- Line 17: max → math.max
- Line 17: change → ta.change
- Line 17: ema → ta.ema
- Line 18: rma → ta.rma
- Line 18: min → math.min
- Line 18: change → ta.change
- Line 18: ema → ta.ema
- Line 25: ema → ta.ema
- Line 28: input(type = input.integer) → input.int()
- Line 29: input(type = input.integer) → input.int()
- Line 31: cci → ta.cci
- Line 32: cci → ta.cci
- Line 42: crossover → ta.crossover
- Line 43: crossunder → ta.crossunder
⋯// © SoftKill21-//@version=4+//@version=5strategy(title="Moving Average Exponential", shorttitle="EMA", overlay=true)⋯src4 = input(close, title="Source")-offset4 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)+offset4 = input.int(title="Offset", defval=0, minval=-500, maxval=500)-out4 = ema(src4, len4)+out4 = ta.ema(src4, len4)plot(out4, title="EMA", color=color.blue, offset=offset4)⋯src8 = input(close, title="Source")-offset8 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)+offset8 = input.int(title="Offset", defval=0, minval=-500, maxval=500)-out8 = ema(src8, len8)+out8 = ta.ema(src8, len8)plot(out8, title="EMA", color=color.blue, offset=offset8)⋯src = close, len = input(14, minval=1, title="Length")-up = rma(max(change(ema(src, len)), 0), len)+up = ta.rma(math.max(ta.change(ta.ema(src, len)), 0), len)-down = rma(-min(change(ema(src, len)), 0), len)+down = ta.rma(-math.min(ta.change(ta.ema(src, len)), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))⋯//hline(50, color=color.gray, linestyle=plot.style_line)-sig = ema(rsi, 21)+sig = ta.ema(rsi, 21)//plot(sig, color=color.purple)//woodie-cciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=14)+cciTurboLength = input.int(title="CCI Turbo Length", defval=6, minval=3, maxval=14)-cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=20)+cci14Length = input.int(title="CCI 14 Length", defval=14, minval=7, maxval=20)source = close-cciTurbo = cci(source, cciTurboLength)+cciTurbo = ta.cci(source, cciTurboLength)-cci14 = cci(source, cci14Length)+cci14 = ta.cci(source, cci14Length)last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0⋯d = b*syminfo.mintick-longCondition = crossover(out4, out8) and (rsi >= 65 and cci14>=0)+longCondition = ta.crossover(out4, out8) and (rsi >= 65 and cci14>=0)-shortCondition = crossunder(out4, out8) and (rsi <=35 and cci14<=0)+shortCondition = ta.crossunder(out4, out8) and (rsi <=35 and cci14<=0)long_stop_level = float(na)⋯Same 26 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.source()
- Line 10: input() → input.int()
- Line 11: input() → input.source()
- Line 16: input() → input.int()
- Line 38: input() → input.int()
5 more edits
- Line 39: input() → input.int()
- Line 84: input() → input.int()
- Line 85: input() → input.int()
- Line 87: when = longCondition → if block
- Line 89: when = shortCondition → if block
⋯strategy(title="Moving Average Exponential", shorttitle="EMA", overlay=true)-len4 = input(4, minval=1, title="Length_MA4")+len4 = input.int(4, minval=1, title="Length_MA4")-src4 = input(close, title="Source")+src4 = input.source(close, title="Source")offset4 = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯plot(out4, title="EMA", color=color.blue, offset=offset4)-len8 = input(8, minval=1, title="Length_MA8")+len8 = input.int(8, minval=1, title="Length_MA8")-src8 = input(close, title="Source")+src8 = input.source(close, title="Source")offset8 = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯//rsioma-src = close, len = input(14, minval=1, title="Length")+src = close, len = input.int(14, minval=1, title="Length")up = ta.rma(math.max(ta.change(ta.ema(src, len)), 0), len)⋯// Exit Condition-a = input(12)*10+a = input.int(12)*10-b = input(15)*10+b = input.int(15)*10c = a*syminfo.mintick⋯//plotcandle(o2, h2, l2, c2, title="HA Smoothed", color=ha_col)-tp=input(120)+tp=input.int(120)-sl=input(96)+sl=input.int(96) -strategy.entry("long", strategy.long, when = longCondition)+if longCondition+ strategy.entry("long", strategy.long)//strategy.close("long", when = o2>c2 , comment="ha_long")-strategy.entry("short", strategy.short , when =shortCondition )+if shortCondition+ strategy.entry("short", strategy.short )//strategy.close("short", when = o2<=c2 , comment = "ha_short" )⋯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: 26 before, 20 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.
⋯// © SoftKill21-//@version=5+//@version=6strategy(title="Moving Average Exponential", shorttitle="EMA", overlay=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length_MA4 | 4 | int · min 1 | out4 |
| Source | close | source | out4 |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | EMA |
| Length_MA8 | 8 | int · min 1 | out8 |
| Source | close | source | out8 |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | EMA |
| Length | 14 | int · min 1 | up down |
| CCI Turbo Length | 6 | int (written input.integer) · min 3 · max 14 | cciTurbo |
| CCI 14 Length | 14 | int (written input.integer) · min 7 · max 20 | cci14 |
| A (no label in the script) | 12 | int | c |
| B (no label in the script) | 15 | int | d |
| Tp (no label in the script) | 120 | int | exit x_long exit x_short |
| Sl (no label in the script) | 96 | int | exit x_long exit x_short |
What it calculates
- EMA (
ema,ta.emain v5)Source (close), Length_MA4 (4)out4 · line 8 - EMA (
ema,ta.emain v5)Source (close), Length_MA8 (8)out8 · line 13 - RMA / Change / EMA (
rma,ta.rmain v5)max(change(ema(src, len)), 0), Length (14)up · line 17 - RMA / Change / EMA (
rma,ta.rmain v5)-min(change(ema(src, len)), 0), Length (14)down · line 18 - EMA (
ema,ta.emain v5)rsi, 21sig · line 25 - CCI (
cci,ta.cciin v5)source, CCI Turbo Length (6)cciTurbo · line 31 - CCI (
cci,ta.cciin v5)source, CCI 14 Length (14)cci14 · line 32
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longConditioncrossover(out4, out8) and (rsi >= 65 and cci14>=0) | On | 87 |
| Open short short | shortConditioncrossunder(out4, out8) and (rsi <=35 and cci14<=0) | On | 89 |
| Exit x_long stop and limit | every bar | On | 93 |
| Exit x_short stop and limit | every bar | On | 94 |
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 | +0.0% | +102.5% | 26 | 50% | 1.25 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 22 | 55% | 1.50 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.0% | +9.8% | 30 | 30% | 0.54 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 31 | 65% | 2.27 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 25 | 52% | 1.35 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 20 | 30% | 0.54 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 26 | 46% | 1.07 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 23 | 43% | 0.96 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Length_MA4 2, Length_MA8 4) made +0.0% before 26 Dec 2025 and −0.0% after it, worse than the defaults' +0.0% after. Tuning on the past did not carry forward. 48% of the 48 combinations made money in-sample and 65% out-of-sample.
| Length_MA8 ↓ · Length_MA4 → | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|
| 4 | +0% | +0% | 0% | +0% | +0% | +0% |
| 5 | +0% | +0% | +0% | 0% | −0% | −0% |
| 6 | +0% | +0% | +0% | +0% | 0% | 0% |
| 7 | +0% | +0% | +0% | +0% | +0% | 0% |
| 8 | +0% | 0% | +0% | +0% | +0% | −0% |
| 10 | −0% | −0% | +0% | −0% | −0% | −0% |
| 11 | −0% | −0% | −0% | −0% | −0% | −0% |
| 14 | −0% | −0% | −0% | −0% | +0% | −0% |
| Length_MA8 ↓ · Length_MA4 → | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|
| 4 | −0% | −0% | 0% | −0% | −0% | +0% |
| 5 | −0% | −0% | −0% | 0% | 0% | 0% |
| 6 | −0% | +0% | +0% | +0% | 0% | 0% |
| 7 | −0% | +0% | +0% | +0% | +0% | 0% |
| 8 | +0% | +0% | +0% | +0% | +0% | +0% |
| 10 | +0% | +0% | +0% | +0% | +0% | +0% |
| 11 | +0% | +0% | +0% | +0% | +0% | +0% |
| 14 | +0% | −0% | +0% | +0% | +0% | +0% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 10 | 40% | −$0.96 |
| Sideways market | 10 | 50% | $1.20 |
| Falling market | 6 | 67% | $2.88 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 26 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 26 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 26 Mar 2024 69,880.00 | 26 Mar 2024 69,879.00 | 0 | −$0.96 |
| long | 8 Apr 2024 69,360.40 | 8 Apr 2024 69,359.40 | 0 | −$0.96 |
| short | 9 May 2024 61,193.00 | 9 May 2024 61,191.80 | 0 | $1.20 |
| short | 11 May 2024 60,800.00 | 11 May 2024 60,798.80 | 0 | $1.20 |
| short | 15 May 2024 61,577.50 | 15 May 2024 61,576.30 | 0 | $1.20 |
| long | 4 Jun 2024 68,809.90 | 4 Jun 2024 68,808.90 | 0 | −$0.96 |
| short | 12 Aug 2024 58,712.60 | 12 Aug 2024 58,711.40 | 0 | $1.20 |
| short | 15 Aug 2024 58,683.40 | 15 Aug 2024 58,684.30 | 0 | −$0.96 |
| long | 7 Nov 2024 75,572.00 | 7 Nov 2024 75,571.00 | 0 | −$0.96 |
| long | 12 Dec 2024 101,125.00 | 12 Dec 2024 101,126.00 | 0 | $1.20 |
| long | 30 Jan 2025 103,733.00 | 30 Jan 2025 103,732.00 | 0 | −$0.96 |
| short | 22 Feb 2025 96,182.00 | 22 Feb 2025 96,180.80 | 0 | $1.20 |
| short | 8 Mar 2025 86,801.70 | 8 Mar 2025 86,802.70 | 0 | −$0.96 |
| short | 30 Mar 2025 82,648.50 | 30 Mar 2025 82,649.50 | 0 | −$0.96 |
| long | 9 Jun 2025 105,734.00 | 9 Jun 2025 105,733.00 | 0 | −$0.96 |
| short | 31 Oct 2025 108,323.00 | 31 Oct 2025 108,322.00 | 0 | $1.20 |
| short | 2 Dec 2025 86,286.00 | 2 Dec 2025 86,284.80 | 0 | $1.20 |
| short | 7 Dec 2025 89,236.80 | 7 Dec 2025 89,235.60 | 0 | $1.20 |
| short | 14 Dec 2025 90,240.00 | 14 Dec 2025 90,241.00 | 0 | −$0.96 |
| short | 24 Dec 2025 87,486.00 | 24 Dec 2025 87,487.00 | 0 | −$0.96 |
| short | 9 Mar 2026 65,971.20 | 9 Mar 2026 65,970.00 | 0 | $1.20 |
| long | 2 May 2026 78,231.10 | 2 May 2026 78,230.20 | 0 | −$0.96 |
| long | 15 May 2026 81,090.00 | 15 May 2026 81,091.20 | 0 | $1.20 |
| short | 19 Jun 2026 62,958.00 | 19 Jun 2026 62,956.80 | 0 | $1.20 |
| long | 27 Jul 2026 65,400.00 | 27 Jul 2026 65,401.20 | 0 | $1.20 |
| long | 19 Sep 2026 80,883.90 | 19 Sep 2026 80,882.90 | 0 | −$0.96 |
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 |
|---|---|---|---|---|---|
| Daytrade strategy RSI CCI EMA 4-8 this page | — | v4 strategy | +0.0% | 26 | 0.0% |
| DCA After Downtrend v2 (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rma | v5 strategy | No trades on this market | ||
| Williams Fractals Strategy by B_L_A_C_K_S_C_O_R_P_I_O_N | ema rma | v4 strategy | No trades on this market | ||
| Strategy Myth-Busting #10 - InsideBar+EMA - [MYN] by myncrypto | ema rma | v5 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| Take Profit On Trend v2 (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rma | v5 strategy | +9.4% | 6 | 24.0% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 20 ms | With a workaround 1,000 bars in 48 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © SoftKill21//@version=4strategy(title="Moving Average Exponential", shorttitle="EMA", overlay=true)len4 = input(4, minval=1, title="Length_MA4")src4 = input(close, title="Source")offset4 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)out4 = ema(src4, len4)plot(out4, title="EMA", color=color.blue, offset=offset4)len8 = input(8, minval=1, title="Length_MA8")src8 = input(close, title="Source")offset8 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)out8 = ema(src8, len8)plot(out8, title="EMA", color=color.blue, offset=offset8)//rsiomasrc = close, len = input(14, minval=1, title="Length")up = rma(max(change(ema(src, len)), 0), len)down = rma(-min(change(ema(src, len)), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))//plot(rsi, color=color.blue)//band1 = hline(80)//band0 = hline(20)//fill(band1, band0, color=color.purple, transp=90)//hline(50, color=color.gray, linestyle=plot.style_line)sig = ema(rsi, 21)//plot(sig, color=color.purple)//woodiecciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=14)cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=20)source = closecciTurbo = cci(source, cciTurboLength)cci14 = cci(source, cci14Length)last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0last5IsUp = cci14[5] > 0 and cci14[4] > 0 and cci14[3] > 0 and cci14[2] > 0 and cci14[1] > 0histogramColor = last5IsUp ? color.green : last5IsDown ? color.red : cci14 < 0 ? color.green : color.red// Exit Condition// Exit Conditiona = input(12)*10b = input(15)*10c = a*syminfo.mintickd = b*syminfo.minticklongCondition = crossover(out4, out8) and (rsi >= 65 and cci14>=0)shortCondition = crossunder(out4, out8) and (rsi <=35 and cci14<=0)long_stop_level = float(na)long_profit_level1 = float(na)long_profit_level2 = float(na)long_even_level = float(na)short_stop_level = float(na)short_profit_level1 = float(na)short_profit_level2 = float(na)short_even_level = float(na)long_stop_level := longCondition ? close - c : long_stop_level [1]long_profit_level1 := longCondition ? close + d : long_profit_level1 [1]//long_profit_level2 := longCondition ? close + d : long_profit_level2 [1]//long_even_level := longCondition ? close + 0 : long_even_level [1]short_stop_level := shortCondition ? close + c : short_stop_level [1]short_profit_level1 := shortCondition ? close - d : short_profit_level1 [1]//short_profit_level2 := shortCondition ? close - d : short_profit_level2 [1]//short_even_level := shortCondition ? close + 0 : short_even_level [1] //ha// === Input ===//ma1_len = input(1, title="MA 01")//ma2_len = input(40, title="MA 02")// === MA 01 Filter ===//o=ema(open,ma1_len)//cc=ema(close,ma1_len)//h=ema(high,ma1_len)//l=ema(low,ma1_len)// === HA calculator ===//ha_t = heikinashi(syminfo.tickerid)//ha_o = security(ha_t, timeframe.period, o)//ha_c = security(ha_t, timeframe.period, cc)//ha_h = security(ha_t, timeframe.period, h)//ha_l = security(ha_t, timeframe.period, l)// === MA 02 Filter ===//o2=ema(ha_o, ma2_len)//c2=ema(ha_c, ma2_len)//h2=ema(ha_h, ma2_len)//l2=ema(ha_l, ma2_len)// === Color def ===//ha_col=o2>c2 ? color.red : color.lime// === PLOTITING===//plotcandle(o2, h2, l2, c2, title="HA Smoothed", color=ha_col)tp=input(120)sl=input(96) strategy.entry("long", strategy.long, when = longCondition)//strategy.close("long", when = o2>c2 , comment="ha_long")strategy.entry("short", strategy.short , when =shortCondition )//strategy.close("short", when = o2<=c2 , comment = "ha_short" )//strategy.close("long",when=long_profit_level1 or long_stop_level , comment="tp/sl")//strategy.close("short",when=short_profit_level1 or short_stop_level , comment="tp/sl")strategy.exit("x_long","long",profit = tp, loss = sl) //when = o2>c2)strategy.exit("x_short","short",profit = tp, loss = sl) //when = o2<c2)