Pine Script v4 · Strategy
EMA & Supertrend
A Pine Script v4 strategy built on EMA (close, 21), SMA (tr, 10) and ATR (10). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 10 settings; defaults include Len1 21, Len2 55 and Len3 200.
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 EMA & Supertrend repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did EMA & Supertrend do on BTCUSDT 1D with default settings?
- +2,123.63%
- From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can EMA & Supertrend 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.
- What alerts does EMA & Supertrend have?
- 3
- SuperTrend Buy; SuperTrend Sell; SuperTrend Direction Change.
- Does EMA & Supertrend use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Up Trend
- UpTrend Begins
- Buy
- Down Trend
- DownTrend Begins
- Sell
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2,123.63%
- $2,123,630.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 13
- 4 won · 9 lost
- Profitable
- 30.8%
- of closed trades
- Profit factor
- 1.85
- gross profit ÷ gross loss
- Max drawdown
- 980.91%
- −$2,273,610.00
One run with the author's default settings, $100,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
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
4 settings have no label
In the settings dialog len1 (line 14), len2 (line 19), len3 (line 24), len4 (line 29) 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 75, 76. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 52
transp = on line 52, 53, 56, 57. v5 folds the transparency into the colour with color.new(c, transp).
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, sma → ta.sma, atr → ta.atr, max → math.max, min → math.min, crossover → ta.crossover, crossunder → ta.crossunder.
- 2 strategy calls use the when = argument (line 75, 76). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 13 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 16: ema → ta.ema
- Line 21: ema → ta.ema
- Line 26: ema → ta.ema
- Line 31: ema → ta.ema
- Line 33: input(type = input.integer) → input.int()
17 more edits
- Line 35: input(type = input.float) → input.float()
- Line 36: input(type = input.bool) → input.bool()
- Line 37: input(type = input.bool) → input.bool()
- Line 38: input(type = input.bool) → input.bool()
- Line 39: sma → ta.sma
- Line 39: tr → ta.tr
- Line 40: atr → ta.atr
- Line 43: max → math.max
- Line 46: min → math.min
- Line 52: transp = 0 → color.new(color.green, 0)
- Line 53: transp = 0 → color.new(color.green, 0)
- Line 56: transp = 0 → color.new(color.red, 0)
- Line 57: transp = 0 → color.new(color.red, 0)
- Line 68: crossover → ta.crossover
- Line 69: crossunder → ta.crossunder
- Line 70: crossunder → ta.crossunder
- Line 71: crossover → ta.crossover
⋯// © bhavikmota-//@version=4+//@version=5strategy("EMA & Supertrend", overlay = true)⋯//src1 = input(close)-ema1 = ema(close,len1)+ema1 = ta.ema(close,len1)plot(ema1, color=color.red, linewidth=1)⋯//src2 = input(close)-ema2 = ema(close,len2)+ema2 = ta.ema(close,len2)plot(ema2, color=color.green, linewidth=1)⋯//src3 = input(close)-ema3 = ema(close,len3)+ema3 = ta.ema(close,len3)plot(ema3, color=color.blue, linewidth=1)⋯//src4 = input(close)-ema4 = ema(close,len4)+ema4 = ta.ema(close,len4)plot(ema4, color=color.black, linewidth=1)-Periods = input(title="ATR Period", type=input.integer, defval=10)+Periods = input.int(title="ATR Period", defval=10)src = input(hl2, title="Source")-Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)+Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)-changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)+changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true)-showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)+showsignals = input.bool(title="Show Buy/Sell Signals ?", defval=true)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)-atr2 = sma(tr, Periods)+atr2 = ta.sma(ta.tr, Periods)-atr= changeATR ? atr(Periods) : atr2+atr= changeATR ? ta.atr(Periods) : atr2up=src-(Multiplier*atr)up1 = nz(up[1],up)-up := close[1] > up1 ? max(up,up1) : up+up := close[1] > up1 ? math.max(up,up1) : updn=src+(Multiplier*atr)dn1 = nz(dn[1], dn)-dn := close[1] < dn1 ? min(dn, dn1) : dn+dn := close[1] < dn1 ? math.min(dn, dn1) : dntrend = 1⋯buySignal = trend == 1 and trend[1] == -1-plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)+plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))-plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)sellSignal = trend == -1 and trend[1] == 1-plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)+plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))-plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)⋯//Trading logic-Enterlong = crossover(ema1,ema2) or (close>ema1 and close>ema2 and ema1>ema2) and close>ema4// positive ema crossover+Enterlong = ta.crossover(ema1,ema2) or (close>ema1 and close>ema2 and ema1>ema2) and close>ema4// positive ema crossover-Exitlong = crossunder(close,ema2) // candle closes below supertrend+Exitlong = ta.crossunder(close,ema2) // candle closes below supertrend-Entershort = crossunder(ema1,ema2) or (close<ema1 and close<ema2 and ema2<ema1) and close<ema4// negative ema crossover+Entershort = ta.crossunder(ema1,ema2) or (close<ema1 and close<ema2 and ema2<ema1) and close<ema4// negative ema crossover-Exitshort = crossover(close,ema2) // candle closes above supertrend+Exitshort = ta.crossover(close,ema2) // candle closes above supertrend//Execution Logic - Placing Order⋯Same 13 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 14: input() → input.int()
- Line 19: input() → input.int()
- Line 24: input() → input.int()
- Line 29: input() → input.int()
- Line 34: input() → input.source()
- Line 75: when = Enterlong → if block
- Line 76: when = Exitlong → if block
⋯//for Ema1-len1 = input(21, minval=1)+len1 = input.int(21, minval=1)//src1 = input(close)⋯//for Ema2-len2 = input(55, minval=1)+len2 = input.int(55, minval=1)//src2 = input(close)⋯//for Ema3-len3 = input(200, minval=1)+len3 = input.int(200, minval=1)//src3 = input(close)⋯//for Ema4-len4 = input(233, minval=1)+len4 = input.int(233, minval=1)//src4 = input(close)⋯Periods = input.int(title="ATR Period", defval=10)-src = input(hl2, title="Source")+src = input.source(hl2, title="Source")Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)⋯if time>= start- strategy.entry("long", strategy.long, 100, when=Enterlong)+ if Enterlong+ strategy.entry("long", strategy.long, 100)- strategy.close("long",when=Exitlong)+ if Exitlong+ strategy.close("long")//strategy.entry("short",strategy.short,100,when=Entershort)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L58:C56: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © bhavikmota-//@version=5+//@version=6strategy("EMA & Supertrend", 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 |
|---|---|---|---|
| Len1 (no label in the script) | 21 | int · min 1 | ema1 |
| Len2 (no label in the script) | 55 | int · min 1 | ema2 |
| Len3 (no label in the script) | 200 | int · min 1 | ema3 |
| Len4 (no label in the script) | 233 | int · min 1 | ema4 |
| ATR Period | 10 | int (written input.integer) | atr2 atr |
| Source | hl2 | source | up dn |
| ATR Multiplier | 3.0 | float · step 0.1 | up dn |
| Change ATR Calculation Method ? | true | bool | atr |
| Show Buy/Sell Signals ? | true | bool | Buy Sell |
| Highlighter On/Off ? | true | bool | longFillColor shortFillColor |
What it calculates
- EMA (
ema,ta.emain v5)close, Len1 (21)ema1 · line 16 - EMA (
ema,ta.emain v5)close, Len2 (55)ema2 · line 21 - EMA (
ema,ta.emain v5)close, Len3 (200)ema3 · line 26 - EMA (
ema,ta.emain v5)close, Len4 (233)ema4 · line 31 - SMA (
sma,ta.smain v5)tr, ATR Period (10)atr2 · line 39 - ATR (
atr,ta.atrin v5)ATR Period (10)atr · line 40 - Crossunder (
crossunder,ta.crossunderin v5)close, ema2Exitlong · line 69 - Crossover (
crossover,ta.crossoverin v5)close, ema2Exitshort · line 71
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 | Enterlongcrossover(ema1,ema2) or (close>ema1 and close>ema2 and ema1>ema2) and close>ema4 | On | 75 |
| Close long | Exitlong | On | 76 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| SuperTrend Buy | alertcondition | SuperTrend Buy! | 63 |
| SuperTrend Sell | alertcondition | SuperTrend Sell! | 64 |
| SuperTrend Direction Change | alertcondition | SuperTrend has changed direction! | 66 |
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 | +2,123.6% | +102.5% | 13 | 31% | 1.85 | 980.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +711.7% | +5.5% | 15 | 40% | 1.86 | 683.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +38.3% | +9.8% | 11 | 27% | 1.20 | 59.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +10.0% | +8.4% | 18 | 28% | 1.19 | 21.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −4.1% | +16.7% | 12 | 42% | 0.72 | 8.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +2.7% | +21.5% | 13 | 23% | 2.80 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +33.3% | +148.3% | 10 | 40% | 2.80 | 7.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +5.2% | +17.1% | 18 | 33% | 1.59 | 6.9% | 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 (Len1 36, Len2 33) made +3,714.1% before 26 Dec 2025 and −2,558.2% after it, worse than the defaults' −153.3% after. Tuning on the past did not carry forward. 100% of the 64 combinations made money in-sample and 20% out-of-sample.
| Len2 ↓ · Len1 → | 11 | 13 | 15 | 18 | 21 | 25 | 29 | 36 |
|---|---|---|---|---|---|---|---|---|
| 28 | +3,161% | +2,668% | +2,626% | +2,290% | +2,424% | +1,824% | +2,351% | +3,708% |
| 33 | +2,092% | +2,093% | +1,591% | +2,111% | +1,918% | +1,175% | +1,409% | +3,714% |
| 39 | +966% | +1,092% | +1,653% | +1,252% | +1,301% | +1,125% | +1,366% | +790% |
| 47 | +1,421% | +1,802% | +1,667% | +1,726% | +1,690% | +1,216% | +1,032% | +1,472% |
| 55 | +2,543% | +2,415% | +2,465% | +2,477% | +2,277% | +1,941% | +1,864% | +2,008% |
| 66 | +2,024% | +2,272% | +2,232% | +2,253% | +2,309% | +3,025% | +2,692% | +2,718% |
| 77 | +2,191% | +2,245% | +2,219% | +2,240% | +2,461% | +2,587% | +2,434% | +1,991% |
| 94 | +3,220% | +3,187% | +3,150% | +3,122% | +3,321% | +3,036% | +2,247% | +2,391% |
| Len2 ↓ · Len1 → | 11 | 13 | 15 | 18 | 21 | 25 | 29 | 36 |
|---|---|---|---|---|---|---|---|---|
| 28 | −79% | −293% | −19% | +414% | +344% | +450% | −2,908% | −3,176% |
| 33 | +424% | +362% | +865% | +908% | +551% | +431% | +630% | −2,558% |
| 39 | −3% | −585% | −563% | −594% | −594% | −431% | −453% | −7% |
| 47 | −320% | −611% | −611% | −447% | −510% | +168% | −24% | +50% |
| 55 | −320% | −157% | −219% | −213% | −153% | −15% | −30% | −272% |
| 66 | −219% | +39% | −153% | −15% | −30% | −264% | −272% | −312% |
| 77 | −153% | −15% | −30% | −264% | −272% | −209% | −183% | −315% |
| 94 | −264% | −272% | −190% | −312% | −80% | −315% | −432% | −447% |
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 | 3 | 67% | $851,623.00 |
| Sideways market | 9 | 22% | $1,425,260.00 |
| Falling market | 1 | 0% | −$153,251.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1,030.5%
The 95th percentile of the worst drawdown when the same 13 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 313.7% to 1,030.5%; the tick is what actually happened, 931.9%. Order luck alone moves it this much.
All 13 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 May 2024 66,206.50 | 15 Jun 2024 66,044.00 | 30 | −$16,252.00 |
| long | 24 Jul 2024 65,936.00 | 3 Aug 2024 61,498.30 | 10 | −$443,766.00 |
| long | 24 Sep 2024 63,340.00 | 2 Oct 2024 60,804.90 | 8 | −$253,507.00 |
| long | 7 Oct 2024 62,819.90 | 10 Oct 2024 60,636.00 | 3 | −$218,390.00 |
| long | 12 Oct 2024 62,540.00 | 10 Jan 2025 92,552.50 | 90 | $3,001,250.00 |
| long | 15 Jan 2025 96,560.90 | 3 Feb 2025 97,700.60 | 19 | $113,974.00 |
| long | 21 Feb 2025 98,305.00 | 22 Feb 2025 96,182.00 | 1 | −$212,302.00 |
| long | 26 Apr 2025 94,638.70 | 22 Jun 2025 102,120.00 | 57 | $748,134.00 |
| long | 24 Jun 2025 105,334.00 | 20 Aug 2025 112,873.00 | 57 | $753,901.00 |
| long | 23 Aug 2025 116,936.00 | 25 Aug 2025 113,494.00 | 2 | −$344,241.00 |
| long | 16 Sep 2025 115,350.00 | 23 Sep 2025 112,651.00 | 7 | −$269,872.00 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$582,050.00 |
| long | 18 Apr 2026 77,072.00 | 23 May 2026 75,539.50 | 35 | −$153,251.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 |
|---|---|---|---|---|---|
| EMA & Supertrend this page | — | v4 strategy | +2,123.6% | 13 | 980.9% |
| ATR with EOM and VORTEX by SoftKill21 | atr ema sma | v4 strategy | +66.2% | 22 | 29.9% |
| cATRpillar Strategy by Obi-wanClintobe | atr sma ema | v4 strategy | +1.02827e+24% | 27 | 88,097.2% |
| Optimized Zhaocaijinbao strategy by fzj20020403 | sma ema atr | v5 strategy | +15.6% | 12 | 9.8% |
| Koala System EURUSD 15min by SoftKill21 | sma ema atr | v4 strategy | No trades on this market | ||
| Buy&Sell Bullish Engulfing - The Quant Science by thequantscience | sma ema atr | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | Yes 1,000 bars in 84 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © bhavikmota//@version=4strategy("EMA & Supertrend", overlay = true)//length = input(9, minval=1)//ema1 = ema(close, length)//ema2 = ema(ema1, length)//ema3 = ema(ema2, length)//shortest = ema(close, 20)//short = ema(close, 50)//longer = ema(close, 100)//longest = ema(close, 200)//for Ema1len1 = input(21, minval=1)//src1 = input(close)ema1 = ema(close,len1)plot(ema1, color=color.red, linewidth=1)//for Ema2len2 = input(55, minval=1)//src2 = input(close)ema2 = ema(close,len2)plot(ema2, color=color.green, linewidth=1)//for Ema3len3 = input(200, minval=1)//src3 = input(close)ema3 = ema(close,len3)plot(ema3, color=color.blue, linewidth=1)//for Ema4len4 = input(233, minval=1)//src4 = input(close)ema4 = ema(close,len4)plot(ema4, color=color.black, linewidth=1)Periods = input(title="ATR Period", type=input.integer, defval=10)src = input(hl2, title="Source")Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)atr2 = sma(tr, Periods)atr= changeATR ? atr(Periods) : atr2up=src-(Multiplier*atr)up1 = nz(up[1],up)up := close[1] > up1 ? max(up,up1) : updn=src+(Multiplier*atr)dn1 = nz(dn[1], dn)dn := close[1] < dn1 ? min(dn, dn1) : dntrend = 1trend := nz(trend[1], trend)trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trendupPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)buySignal = trend == 1 and trend[1] == -1plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)sellSignal = trend == -1 and trend[1] == 1plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.whiteshortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.whitefill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")changeCond = trend != trend[1]alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")//Trading logicEnterlong = crossover(ema1,ema2) or (close>ema1 and close>ema2 and ema1>ema2) and close>ema4// positive ema crossoverExitlong = crossunder(close,ema2) // candle closes below supertrendEntershort = crossunder(ema1,ema2) or (close<ema1 and close<ema2 and ema2<ema1) and close<ema4// negative ema crossoverExitshort = crossover(close,ema2) // candle closes above supertrend//Execution Logic - Placing Orderstart = timestamp(2008,1,1,0,0)if time>= start strategy.entry("long", strategy.long, 100, when=Enterlong) strategy.close("long",when=Exitlong)//strategy.entry("short",strategy.short,100,when=Entershort)//strategy.close("short",when=Exitshort)