Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$3,390,890$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+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

Verified

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

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Len1 (no label in the script)21int · min 1ema1
Len2 (no label in the script)55int · min 1ema2
Len3 (no label in the script)200int · min 1ema3
Len4 (no label in the script)233int · min 1ema4
ATR Period10int (written input.integer)atr2 atr
Sourcehl2sourceup dn
ATR Multiplier3.0float · step 0.1up dn
Change ATR Calculation Method ?trueboolatr
Show Buy/Sell Signals ?trueboolBuy Sell
Highlighter On/Off ?trueboollongFillColor shortFillColor

What it calculates

  • EMA (ema, ta.ema in v5)close, Len1 (21)ema1 · line 16
  • EMA (ema, ta.ema in v5)close, Len2 (55)ema2 · line 21
  • EMA (ema, ta.ema in v5)close, Len3 (200)ema3 · line 26
  • EMA (ema, ta.ema in v5)close, Len4 (233)ema4 · line 31
  • SMA (sma, ta.sma in v5)tr, ATR Period (10)atr2 · line 39
  • ATR (atr, ta.atr in v5)ATR Period (10)atr · line 40
  • Crossunder (crossunder, ta.crossunder in v5)close, ema2Exitlong · line 69
  • Crossover (crossover, ta.crossover in 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.

closecloseprice datalen1Len1setting · 21len2Len2setting · 55len3Len3setting · 200len4Len4setting · 233PeriodsATR Periodsetting · 10high · low · closehigh · low · closeprice datahl2hl2price dataMultiplierATR Multipliersetting · 3.0ohlc4ohlc4price dataema1EMA→ ema1ema2EMA→ ema2ema3EMA→ ema3ema4EMA→ ema4atr2SMA→ atr2atrATR→ atrExitlongCrossunder→ ExitlongExitshortCrossover→ Exitshortupupvalueup1up1valuedndnvaluedn1dn1valuetrendtrendvalueEnterlongEnterlongconditionbuySignal, sellSignal, changeCondbuySignal · sellSignal …3 conditionsEntershortEntershortconditionlongFillColor, shortFillColorColourlongFillColor · shortFillColorentry:longOpen longstrategy.entryclose:longClose longstrategy.closeplot:17plotplotplot:22plotplotplot:27plotplotplot:32plotplotplot:50Up Trendplotplotshape:52UpTrend Beginsplotshapeplotshape:53Buyplotshapeplot:54Down Trendplotplotshape:56DownTrend Beginsplotshapeplotshape:57Sellplotshapeplot:58plotfill:UpTrend HighligterUpTrend Highligterfillfill:DownTrend HighligterDownTrend Highligterfillalertcondition:63SuperTrend Buyalertconditionalertcondition:64SuperTrend Sellalertconditionalertcondition:66SuperTrend Direction Ch…alertcondition

Order rules

OrderFires whenBy defaultLine
Open long longEnterlongcrossover(ema1,ema2) or (close>ema1 and close>ema2 and ema1>ema2) and close>ema4On75
Close longExitlongOn76

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
SuperTrend BuyalertconditionSuperTrend Buy!63
SuperTrend SellalertconditionSuperTrend Sell!64
SuperTrend Direction ChangealertconditionSuperTrend has changed direction!66

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

1/1trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+2,123.6%+102.5%1331%1.85980.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+711.7%+5.5%1540%1.86683.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+38.3%+9.8%1127%1.2059.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+10.0%+8.4%1828%1.1921.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−4.1%+16.7%1242%0.728.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.7%+21.5%1323%2.800.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+33.3%+148.3%1040%2.807.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+5.2%+17.1%1833%1.596.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.

Before 26 Dec 2025 · in-sample
Len2 ↓ · Len1 →1113151821252936
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%
From 26 Dec 2025 · out-of-sample
Len2 ↓ · Len1 →1113151821252936
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 barsTradesWonP&L
Rising market367%$851,623.00
Sideways market922%$1,425,260.00
Falling market10%−$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.

0%1,185%
All 13 trades
SideEntryExitBarsP&L
long16 May 2024 66,206.5015 Jun 2024 66,044.0030−$16,252.00
long24 Jul 2024 65,936.003 Aug 2024 61,498.3010−$443,766.00
long24 Sep 2024 63,340.002 Oct 2024 60,804.908−$253,507.00
long7 Oct 2024 62,819.9010 Oct 2024 60,636.003−$218,390.00
long12 Oct 2024 62,540.0010 Jan 2025 92,552.5090$3,001,250.00
long15 Jan 2025 96,560.903 Feb 2025 97,700.6019$113,974.00
long21 Feb 2025 98,305.0022 Feb 2025 96,182.001−$212,302.00
long26 Apr 2025 94,638.7022 Jun 2025 102,120.0057$748,134.00
long24 Jun 2025 105,334.0020 Aug 2025 112,873.0057$753,901.00
long23 Aug 2025 116,936.0025 Aug 2025 113,494.002−$344,241.00
long16 Sep 2025 115,350.0023 Sep 2025 112,651.007−$269,872.00
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$582,050.00
long18 Apr 2026 77,072.0023 May 2026 75,539.5035−$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.

ScriptSharesTypeNetTradesMax drawdown
EMA & Supertrend this page—v4 strategy+2,123.6%13980.9%
ATR with EOM and VORTEX by SoftKill21atr ema smav4 strategy+66.2%2229.9%
cATRpillar Strategy by Obi-wanClintobeatr sma emav4 strategy+1.02827e+24%2788,097.2%
Optimized Zhaocaijinbao strategy by fzj20020403sma ema atrv5 strategy+15.6%129.8%
Koala System EURUSD 15min by SoftKill21sma ema atrv4 strategyNo trades on this market
Buy&Sell Bullish Engulfing - The Quant Science by thequantsciencesma ema atrv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msYes 1,000 bars in 84 msNot measured
PineTSNo 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)