Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Supertrend Strategy

A Pine Script v4 strategy built on SMA (tr, 10), ATR (10) and EMA (close, 15). It has 62 order rules, 56 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 10000 in cash and pays no commission. 32 settings; defaults include ATR Period 10, ATR Source hl2 and ATR Multiplier 3.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 Supertrend 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 Supertrend Strategy do on BTCUSDT 1D with default settings?
−20.46%
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 Supertrend Strategy 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 Supertrend Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 284, 286, 289, 291.
Does Supertrend Strategy run in Zeal Terminal?
Yes
It compiles in 109 ms and runs 1,000 bars in 304 ms, in the browser.

BTCUSDT · 1D · default settings

  • Up Trend
  • Down Trend
  • 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 (32)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,681$20,253Equity from $10,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. 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.
Net profit
−20.46%
−$2,045.96
Buy and hold
+102.5%
same period
Closed trades
26
8 won · 18 lost
Profitable
30.8%
of closed trades
Profit factor
0.88
gross profit ÷ gross loss
Max drawdown
63.52%
−$9,239.55

One run with the author's default settings, $10,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

    1 setting does nothing

    “Note For Your Reference Only” is declared but never read.

  • 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.

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 sma → ta.sma, atr → ta.atr, max → math.max, min → math.min, ema → ta.ema, sum → math.sum.

v4 → v5

Verified

Same 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 10: input(type = input.time) → input.time()
  • Line 11: input(type = input.time) → input.time()
  • Line 30: input(type = input.integer) → input.int()
  • Line 32: input(type = input.float) → input.float()
  • Line 33: input(type = input.bool) → input.bool()
11 more edits
  • Line 34: sma → ta.sma
  • Line 34: tr → ta.tr
  • Line 35: atr → ta.atr
  • Line 38: max → math.max
  • Line 41: min → math.min
  • Line 58: ema → ta.ema
  • Line 64: input(type = input.integer) → input.int()
  • Line 67: sum → math.sum
  • Line 67: sum → math.sum
  • Line 71: input(type = input.float) → input.float()
  • Line 72: input(type = input.float) → input.float()
⋯// © REV0LUTI0N-//@version=4+//@version=5//------------------------------------------------------------------------------  ⋯// Strategy Backtesting-startDate  = input(timestamp("2021-10-01T00:00:00"), type = input.time, title='Backtesting Start Date', group="Backtesting")+startDate  = input.time(timestamp("2021-10-01T00:00:00"), title='Backtesting Start Date', group="Backtesting")-finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date', group="Backtesting")+finishDate = input.time(timestamp("9999-12-31T00:00:00"), title='Backtesting End Date', group="Backtesting")time_cond  = time >= startDate and time <= finishDate⋯usesupertrend = input(true, title="Use Supertrend", inline="1", group="Supertrend Settings")-Periods = input(title="ATR Period", type=input.integer, defval=10, group="Supertrend Settings")+Periods = input.int(title="ATR Period", defval=10, group="Supertrend Settings")src = input(hl2, title="ATR Source", group="Supertrend Settings")-Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0, group="Supertrend Settings")+Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0, group="Supertrend Settings")-changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true, group="Supertrend Settings")+changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true, group="Supertrend Settings")-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⋯emapricesrc = input(close, title="EMA Price Source", group="EMA Filter")-ema = ema(emasrc, ema_length)+ema = ta.ema(emasrc, ema_length)plot(useemafilter ? ema : na, "EMA", style=plot.style_linebr, color=#cad850, linewidth=2)⋯usecmffilter = input(false, title="Use CMF Filter", inline="1", group="CMF Filter")-mflength = input(title="CMF length", group="CMF Filter", type=input.integer, defval=20)+mflength = input.int(title="CMF length", group="CMF Filter", defval=20)mfsrc = input(close, title="CMF Source", group="CMF Filter")ad = mfsrc==high and mfsrc==low or high==low ? 0 : ((2*mfsrc-low-high)/(high-low))*volume-mf = sum(ad, mflength) / sum(volume, mflength)+mf = math.sum(ad, mflength) / math.sum(volume, mflength)//------------------------------------------------------------------------------  ⋯enablesltp = input(false, title='Enable Stop Loss & Take Profit', group="% Stop Loss & Take Profit")-stopTick = input(2.0, title='Stop Loss %', group="% Stop Loss & Take Profit", type=input.float, step=0.1) / 100+stopTick = input.float(2.0, title='Stop Loss %', group="% Stop Loss & Take Profit", step=0.1) / 100-takeTick = input(4.0, title='Take Profit %', group="% Stop Loss & Take Profit", type=input.float, step=0.1) / 100+takeTick = input.float(4.0, title='Take Profit %', group="% Stop Loss & Take Profit", step=0.1) / 100longStop = strategy.position_avg_price * (1 - stopTick)⋯

Clean v5

VerifiedDownload the v5 script

Same 26 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 7: input() → input.string()
  • Line 15: input() → input.string()
  • Line 16: input() → input.string()
  • Line 17: input() → input.bool()
  • Line 20: input() → input.bool()
  • Line 21: input() → input.bool()
18 more edits
  • Line 24: input() → input.bool()
  • Line 25: input() → input.bool()
  • Line 28: input() → input.bool()
  • Line 29: input() → input.bool()
  • Line 31: input() → input.source()
  • Line 53: input() → input.bool()
  • Line 54: input() → input.bool()
  • Line 55: input() → input.int()
  • Line 56: input() → input.source()
  • Line 57: input() → input.source()
  • Line 62: input() → input.bool()
  • Line 63: input() → input.bool()
  • Line 65: input() → input.source()
  • Line 70: input() → input.bool()
  • Line 87: input() → input.string()
  • Line 88: input() → input.string()
  • Line 89: input() → input.string()
  • Line 90: input() → input.string()
⋯strategy("Supertrend Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)-notes = input("", title="Note For Your Reference Only")+notes = input.string("", title="Note For Your Reference Only")//------------------------------------------------------------------------------  ⋯//Time Restriction Settings-startendtime = input("", title='Time Frame To Enter Trades', group="Time Restriction")+startendtime = input.string("", title='Time Frame To Enter Trades', group="Time Restriction")-endtime = input("", title='Time Frame To Exit Trades', group="Time Restriction")+endtime = input.string("", title='Time Frame To Exit Trades', group="Time Restriction")-enableclose = input(false, title='Enable Close Trade At End Of Exit Time Frame', group="Time Restriction")+enableclose = input.bool(false, title='Enable Close Trade At End Of Exit Time Frame', group="Time Restriction")timetobuy = (time(timeframe.period, startendtime))timetoclose = na(time(timeframe.period, endtime))-enableentry = input(true, title="Enter Supertrend ASAP", inline="1", group="Time Restriction")+enableentry = input.bool(true, title="Enter Supertrend ASAP", inline="1", group="Time Restriction")-waitentry = input(false, title="Wait To Enter Supertrend", inline="1", group="Time Restriction")+waitentry = input.bool(false, title="Wait To Enter Supertrend", inline="1", group="Time Restriction")//------------------------------------------------------------------------------  // Contrarian Settings-nocontrarian = input(true, title="Trade Regular Signals", inline="1", group="Contrarian Settings")+nocontrarian = input.bool(true, title="Trade Regular Signals", inline="1", group="Contrarian Settings")-usecontrarian = input(false, title="Trade Contrarian Signals", inline="1", group="Contrarian Settings")+usecontrarian = input.bool(false, title="Trade Contrarian Signals", inline="1", group="Contrarian Settings")//------------------------------------------------------------------------------  // Supertrend Code-nosupertrend = input(false, title="No Supertrend", inline="1", group="Supertrend Settings")+nosupertrend = input.bool(false, title="No Supertrend", inline="1", group="Supertrend Settings")-usesupertrend = input(true, title="Use Supertrend", inline="1", group="Supertrend Settings")+usesupertrend = input.bool(true, title="Use Supertrend", inline="1", group="Supertrend Settings")Periods = input.int(title="ATR Period", defval=10, group="Supertrend Settings")-src = input(hl2, title="ATR Source", group="Supertrend Settings")+src = input.source(hl2, title="ATR Source", group="Supertrend Settings")Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0, group="Supertrend Settings")⋯// EMA Filter-noemafilter = input(true, title="No EMA Filter", inline="1", group="EMA Filter")+noemafilter = input.bool(true, title="No EMA Filter", inline="1", group="EMA Filter")-useemafilter = input(false, title="Use EMA Filter", inline="1", group="EMA Filter")+useemafilter = input.bool(false, title="Use EMA Filter", inline="1", group="EMA Filter")-ema_length = input(defval=15, minval=1, title="EMA Length", group="EMA Filter")+ema_length = input.int(defval=15, minval=1, title="EMA Length", group="EMA Filter")-emasrc = input(close, title="EMA Source", group="EMA Filter")+emasrc = input.source(close, title="EMA Source", group="EMA Filter")-emapricesrc = input(close, title="EMA Price Source", group="EMA Filter")+emapricesrc = input.source(close, title="EMA Price Source", group="EMA Filter")ema = ta.ema(emasrc, ema_length)⋯// CMF Filter-nocmffilter = input(true, title="No CMF Filter", inline="1", group="CMF Filter")+nocmffilter = input.bool(true, title="No CMF Filter", inline="1", group="CMF Filter")-usecmffilter = input(false, title="Use CMF Filter", inline="1", group="CMF Filter")+usecmffilter = input.bool(false, title="Use CMF Filter", inline="1", group="CMF Filter")mflength = input.int(title="CMF length", group="CMF Filter", defval=20)-mfsrc = input(close, title="CMF Source", group="CMF Filter")+mfsrc = input.source(close, title="CMF Source", group="CMF Filter")ad = mfsrc==high and mfsrc==low or high==low ? 0 : ((2*mfsrc-low-high)/(high-low))*volume⋯// Stop Loss & Take Profit % Based-enablesltp = input(false, title='Enable Stop Loss & Take Profit', group="% Stop Loss & Take Profit")+enablesltp = input.bool(false, title='Enable Stop Loss & Take Profit', group="% Stop Loss & Take Profit")stopTick = input.float(2.0, title='Stop Loss %', group="% Stop Loss & Take Profit", step=0.1) / 100⋯// Alert messages-message_enterlong  = input("", title="Long Entry message", group="Alert Messages")+message_enterlong  = input.string("", title="Long Entry message", group="Alert Messages")-message_entershort = input("", title="Short Entry message", group="Alert Messages")+message_entershort = input.string("", title="Short Entry message", group="Alert Messages")-message_closelong = input("", title="Close Long message", group="Alert Messages")+message_closelong = input.string("", title="Close Long message", group="Alert Messages")-message_closeshort = input("", title="Close Short message", group="Alert Messages")+message_closeshort = input.string("", title="Close Short message", group="Alert Messages")//------------------------------------------------------------------------------  ⋯

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, 9 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.

⋯// © REV0LUTI0N-//@version=5+//@version=6//------------------------------------------------------------------------------  ⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Note For Your Reference Onlystringunused
Backtesting
Backtesting Start Datetimestamp("2021-10-01T00:00:00")timetime_cond
Backtesting End Datetimestamp("9999-12-31T00:00:00")timetime_cond
Time Restriction
Time Frame To Enter Tradesstringtimetobuy
Time Frame To Exit Tradesstringtimetoclose
Enable Close Trade At End Of Exit Time Framefalseboolclose_all close_all line 277 line 279
Enter Supertrend ASAPtrueboolentry Long entry Short entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long line 95 line 98 line 108 line 111 line 121 line 124 line 134 line 137 line 147 line 150 line 160 line 163 line 174 line 177 line 186 line 189 line 199 line 202 line 211 line 214 line 224 line 227 line 237 line 240 line 250 line 253 line 263 line 266
Wait To Enter Supertrendfalseboolentry Long entry Short entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long line 101 line 104 line 114 line 117 line 127 line 130 line 140 line 143 line 153 line 156 line 166 line 169 line 180 line 183 line 192 line 195 line 205 line 208 line 217 line 220 line 230 line 233 line 243 line 246 line 256 line 259 line 269 line 272
Contrarian Settings
Trade Regular Signalstrueboolentry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short exit Close Long exit Close Short Long Stop Loss Short Stop Loss Long Take Profit Short Take Profit line 95 line 98 line 101 line 104 line 121 line 124 line 127 line 130 line 134 line 137 line 140 line 143 line 174 line 177 line 180 line 183 line 186 line 189 line 192 line 195 line 224 line 227 line 230 line 233 line 237 line 240 line 243 line 246 line 283 line 285
Trade Contrarian Signalsfalseboolentry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long exit Close Long exit Close Short Contrarian Long Stop Loss Contrarian Short Stop Loss Contrarian Long Take Profit Contrarian Short Take Profit line 108 line 111 line 114 line 117 line 147 line 150 line 153 line 156 line 160 line 163 line 166 line 169 line 199 line 202 line 205 line 208 line 211 line 214 line 217 line 220 line 250 line 253 line 256 line 259 line 263 line 266 line 269 line 272 line 288 line 290
Supertrend Settings
No Supertrendfalseboolentry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long line 134 line 137 line 140 line 143 line 160 line 163 line 166 line 169 line 186 line 189 line 192 line 195 line 211 line 214 line 217 line 220 line 237 line 240 line 243 line 246 line 263 line 266 line 269 line 272
Use Supertrendtrueboolentry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long line 95 line 98 line 101 line 104 line 108 line 111 line 114 line 117 line 121 line 124 line 127 line 130 line 147 line 150 line 153 line 156 line 174 line 177 line 180 line 183 line 199 line 202 line 205 line 208 line 224 line 227 line 230 line 233 line 250 line 253 line 256 line 259
ATR Period10int (written input.integer)atr2 atr
ATR Sourcehl2sourceup dn
ATR Multiplier3.0float · step 0.1up dn
Change ATR Calculation Method ?trueboolatr
EMA Filter
No EMA Filtertrueboolentry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long line 95 line 98 line 101 line 104 line 108 line 111 line 114 line 117 line 174 line 177 line 180 line 183 line 186 line 189 line 192 line 195 line 199 line 202 line 205 line 208 line 211 line 214 line 217 line 220
Use EMA Filterfalseboolentry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long EMA line 121 line 124 line 127 line 130 line 134 line 137 line 140 line 143 line 147 line 150 line 153 line 156 line 160 line 163 line 166 line 169 line 224 line 227 line 230 line 233 line 237 line 240 line 243 line 246 line 250 line 253 line 256 line 259 line 263 line 266 line 269 line 272
EMA Length15int · min 1ema
EMA Sourceclosesourceema
EMA Price Sourceclosesourceentry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long line 121 line 124 line 127 line 130 line 134 line 137 line 140 line 143 line 147 line 150 line 153 line 156 line 160 line 163 line 166 line 169 line 224 line 227 line 230 line 233 line 237 line 240 line 243 line 246 line 250 line 253 line 256 line 259 line 263 line 266 line 269 line 272
CMF Filter
No CMF Filtertrueboolentry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long line 95 line 98 line 101 line 104 line 108 line 111 line 114 line 117 line 121 line 124 line 127 line 130 line 134 line 137 line 140 line 143 line 147 line 150 line 153 line 156 line 160 line 163 line 166 line 169
Use CMF Filterfalseboolentry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Long entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Short entry Long entry Short entry Long entry Short entry Long entry Short entry Long line 174 line 177 line 180 line 183 line 186 line 189 line 192 line 195 line 199 line 202 line 205 line 208 line 211 line 214 line 217 line 220 line 224 line 227 line 230 line 233 line 237 line 240 line 243 line 246 line 250 line 253 line 256 line 259 line 263 line 266 line 269 line 272
CMF length20int (written input.integer)mf
CMF Sourceclosesourcead
% Stop Loss & Take Profit
Enable Stop Loss & Take Profitfalseboolexit Close Long exit Close Short exit Close Long exit Close Short Long Stop Loss Short Stop Loss Long Take Profit Short Take Profit Contrarian Long Stop Loss Contrarian Short Stop Loss Contrarian Long Take Profit Contrarian Short Take Profit line 283 line 285 line 288 line 290
Stop Loss %2.0float · step 0.1longStop shortStop
Take Profit %4.0float · step 0.1shortTake longTake
Alert Messages
Long Entry messagestringentry Long
Short Entry messagestringentry Short
Close Long messagestringclose_all exit Close Long
Close Short messagestringclose_all exit Close Short

What it calculates

  • SMA (sma, ta.sma in v5)tr, ATR Period (10)atr2 · line 34
  • ATR (atr, ta.atr in v5)ATR Period (10)atr · line 35
  • EMA (ema, ta.ema in v5)EMA Source (close), EMA Length (15)ema · line 58

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.

PeriodsATR Periodsetting · 10high · low · closehigh · low · closeprice dataclosecloseprice dataema_lengthEMA Lengthsetting · 15startendtimeTime Frame To Enter Tra…setting · endtimeTime Frame To Exit Trad…setting · hl2hl2price dataMultiplierATR Multipliersetting · 3.0volumevolumeprice datalowlowprice datahighhighprice datamflengthCMF lengthsetting · 20stopTickStop Loss %setting · 2.0takeTickTake Profit %setting · 4.0timetimeprice datastartDateBacktesting Start Datesetting · timestamp("2021-10-…finishDateBacktesting End Datesetting · timestamp("9999-12-…atr2SMA→ atr2atrATR→ atremaEMA→ ematimetobuytimetobuyvaluetimetoclosetimetoclosevalueupupvalueup1up1valuedndnvaluedn1dn1valuetrendtrendvalueLongLongvalueShortShortvalueadadvaluemfmfvaluelongStop, shortStoplongStop · shortStop2 valuesshortTake, longTakeshortTake · longTake2 valuestime_condtime_condconditionbuySignalbuySignalconditionsellSignalsellSignalconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose_all:close_all strategy.close_allexit:Close Longexit Close Longstrategy.exitexit:Close Shortexit Close Shortstrategy.exitplot:45Up Trendplotplot:48Down Trendplotplot:59EMAplotplot:77Long Stop Lossplotplot:78Short Stop Lossplotplot:79Long Take Profitplotplot:80Short Take Profitplotplot:81Contrarian Long Stop Lo…plotplot:82Contrarian Short Stop L…plotplot:83Contrarian Long Take Pr…plotplot:84Contrarian Short Take P…plot

Order rules

OrderFires whenBy defaultLine
Open Long longLong and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and nocontrarianOn96
Open Short shortShort and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and nocontrarianOn99
Open Long longbuySignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and nocontrarianOn102
Open Short shortsellSignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and nocontrarianOn105
Open Short shortLong and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and usecontrarianOn109
Open Long longShort and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and usecontrarianOn112
Open Short shortbuySignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and usecontrarianOn115
Open Long longsellSignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and usecontrarianOn118
Open Long longLong and emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and nocontrarianOn122
Open Short shortShort and emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and nocontrarianOn125
Open Long longbuySignal and emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and nocontrarianOn128
Open Short shortsellSignal and emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and nocontrarianOn131
Open Long longemapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and nocontrarianOn135
Open Short shortemapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and nocontrarianOn138
Open Long longemapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and nocontrarianOn141
Open Short shortemapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and nocontrarianOn144
Open Short shortLong and emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and usecontrarianOn148
Open Long longShort and emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and usecontrarianOn151
Open Short shortbuySignal and emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and usecontrarianOn154
Open Long longsellSignal and emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and usecontrarianOn157
Open Short shortemapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and usecontrarianOn161
Open Long longemapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and usecontrarianOn164
Open Short shortemapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and usecontrarianOn167
Open Long longemapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and usecontrarianOn170
Open Long longLong and mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and nocontrarianOn175
Open Short shortShort and mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and nocontrarianOn178
Open Long longbuySignal and mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and nocontrarianOn181
Open Short shortsellSignal and mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and nocontrarianOn184
Open Long longmf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and nocontrarianOn187
Open Short shortmf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and nocontrarianOn190
Open Long longmf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and nocontrarianOn193
Open Short shortmf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and nocontrarianOn196
Open Short shortLong and mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and usecontrarianOn200
Open Long longShort and mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and usecontrarianOn203
Open Short shortbuySignal and mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and usecontrarianOn206
Open Long longsellSignal and mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and usecontrarianOn209
Open Short shortmf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and usecontrarianOn212
Open Long longmf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and usecontrarianOn215
Open Short shortmf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and usecontrarianOn218
Open Long longmf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and usecontrarianOn221
Open Long longLong and emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and nocontrarianOn225
Open Short shortShort and emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and nocontrarianOn228
Open Long longbuySignal and emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and nocontrarianOn231
Open Short shortsellSignal and emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and nocontrarianOn234
Open Long longemapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and nocontrarianOn238
Open Short shortemapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and nocontrarianOn241
Open Long longemapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and nocontrarianOn244
Open Short shortemapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and nocontrarianOn247
Open Short shortLong and emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and usecontrarianOn251
Open Long longShort and emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and usecontrarianOn254
Open Short shortbuySignal and emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and usecontrarianOn257
Open Long longsellSignal and emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and usecontrarianOn260
Open Short shortemapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and usecontrarianOn264
Open Long longemapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and usecontrarianOn267
Open Short shortemapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and usecontrarianOn270
Open Long longemapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and usecontrarianOn273
Close strategy.position_size > 0 and timetoclose and enablecloseOn278
Close strategy.position_size < 0 and timetoclose and enablecloseOn280
Exit Close Long stop and limitstrategy.position_size > 0 and enablesltp and time_cond and nocontrarianOn284
Exit Close Short stop and limitstrategy.position_size < 0 and enablesltp and time_cond and nocontrarianOn286
Exit Close Long stop and limitstrategy.position_size > 0 and enablesltp and time_cond and usecontrarianOn289
Exit Close Short stop and limitstrategy.position_size < 0 and enablesltp and time_cond and usecontrarianOn291

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.

6/6trades 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−20.5%+102.5%2631%0.8863.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7.8%+5.5%2438%1.1915.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+60.5%+9.8%2343%1.3467.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+11.0%+8.4%2429%1.2020.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+105.8%+16.7%2343%1.7831.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+13.7%+21.5%2433%1.2222.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.5%+148.3%2733%1.0075.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.5%+17.1%2438%1.0416.6%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 barsTradesWonP&L
Rising market617%−$5,633.46
Sideways market1436%$6,937.72
Falling market633%−$3,350.22

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

73.2%

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, 44.0% to 73.2%; the tick is what actually happened, 57.3%. Order luck alone moves it this much.

0%84%
All 26 trades
SideEntryExitBarsP&L
long5 Feb 2024 42,582.9020 Mar 2024 61,937.4044$4,545.14
short20 Mar 2024 61,937.4021 May 2024 71,446.6062−$1,535.29
long21 May 2024 71,446.6022 Jun 2024 64,143.6032−$1,022.17
short22 Jun 2024 64,143.6016 Jul 2024 64,724.1024−$90.50
long16 Jul 2024 64,724.104 Aug 2024 60,698.0019−$622.03
short4 Aug 2024 60,698.0024 Aug 2024 64,037.2020−$550.14
long24 Aug 2024 64,037.206 Sep 2024 56,180.0013−$1,226.98
short6 Sep 2024 56,180.0020 Sep 2024 62,948.0014−$1,204.70
long20 Sep 2024 62,948.0024 Dec 2024 94,881.5095$5,072.99
short24 Dec 2024 94,881.5018 Jan 2025 104,077.0025−$969.21
long18 Jan 2025 104,077.0025 Feb 2025 91,552.9038−$1,203.39
short25 Feb 2025 91,552.903 Mar 2025 94,270.006−$296.78
long3 Mar 2025 94,270.0011 Mar 2025 78,595.908−$1,662.68
short11 Mar 2025 78,595.9023 Apr 2025 93,443.0043−$1,889.05
long23 Apr 2025 93,443.0023 Jun 2025 100,964.0061$804.86
short23 Jun 2025 100,964.0010 Jul 2025 111,234.0017−$1,017.21
long10 Jul 2025 111,234.0022 Aug 2025 112,500.0043$113.81
short22 Aug 2025 112,500.002 Oct 2025 118,595.0041−$541.78
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$490.79
short11 Oct 2025 112,774.0014 Jan 2026 95,414.0095$1,539.40
long14 Jan 2026 95,414.0021 Jan 2026 88,427.707−$732.21
short21 Jan 2026 88,427.705 Mar 2026 72,666.8043$1,782.35
long5 Mar 2026 72,666.8030 Mar 2026 66,010.9025−$915.94
short30 Mar 2026 66,010.9014 Apr 2026 74,418.0015−$1,273.59
long14 Apr 2026 74,418.0023 May 2026 75,539.5039$150.70
short23 May 2026 75,539.5022 Jul 2026 66,556.1060$1,189.23

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
Supertrend Strategy this page—v4 strategy−20.5%2663.5%
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%
EMA & Supertrend by bhavikmotaema sma atrv4 strategy+2,123.6%13980.9%
Koala System EURUSD 15min by SoftKill21sma ema atrv4 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 109 msWith a workaround 1,000 bars in 304 msNot measured
PineTSNo 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/// © REV0LUTI0N//@version=4//------------------------------------------------------------------------------  // Strategystrategy("Supertrend Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)notes = input("", title="Note For Your Reference Only")//------------------------------------------------------------------------------  // Strategy BacktestingstartDate  = input(timestamp("2021-10-01T00:00:00"), type = input.time, title='Backtesting Start Date', group="Backtesting")finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date', group="Backtesting")time_cond  = time >= startDate and time <= finishDate//------------------------------------------------------------------------------  //Time Restriction Settingsstartendtime = input("", title='Time Frame To Enter Trades', group="Time Restriction")endtime = input("", title='Time Frame To Exit Trades', group="Time Restriction")enableclose = input(false, title='Enable Close Trade At End Of Exit Time Frame', group="Time Restriction")timetobuy = (time(timeframe.period, startendtime))timetoclose = na(time(timeframe.period, endtime))enableentry = input(true, title="Enter Supertrend ASAP", inline="1", group="Time Restriction")waitentry = input(false, title="Wait To Enter Supertrend", inline="1", group="Time Restriction")//------------------------------------------------------------------------------  // Contrarian Settingsnocontrarian = input(true, title="Trade Regular Signals", inline="1", group="Contrarian Settings")usecontrarian = input(false, title="Trade Contrarian Signals", inline="1", group="Contrarian Settings")//------------------------------------------------------------------------------  // Supertrend Codenosupertrend = input(false, title="No Supertrend", inline="1", group="Supertrend Settings")usesupertrend = input(true, title="Use Supertrend", inline="1", group="Supertrend Settings")Periods = input(title="ATR Period", type=input.integer, defval=10, group="Supertrend Settings")src = input(hl2, title="ATR Source", group="Supertrend Settings")Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0, group="Supertrend Settings")changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true, group="Supertrend Settings")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)Long = (trend == 1 ? up : na)buySignal = trend == 1 and trend[1] == -1dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)Short = (trend == 1 ? na : dn)sellSignal = trend == -1 and trend[1] == 1//------------------------------------------------------------------------------  // EMA Filternoemafilter = input(true, title="No EMA Filter", inline="1", group="EMA Filter")useemafilter = input(false, title="Use EMA Filter", inline="1", group="EMA Filter")ema_length = input(defval=15, minval=1, title="EMA Length", group="EMA Filter")emasrc = input(close, title="EMA Source", group="EMA Filter")emapricesrc = input(close, title="EMA Price Source", group="EMA Filter")ema = ema(emasrc, ema_length)plot(useemafilter ? ema : na, "EMA", style=plot.style_linebr, color=#cad850, linewidth=2)//------------------------------------------------------------------------------  // CMF Filternocmffilter = input(true, title="No CMF Filter", inline="1", group="CMF Filter")usecmffilter = input(false, title="Use CMF Filter", inline="1", group="CMF Filter")mflength = input(title="CMF length", group="CMF Filter", type=input.integer, defval=20)mfsrc = input(close, title="CMF Source", group="CMF Filter")ad = mfsrc==high and mfsrc==low or high==low ? 0 : ((2*mfsrc-low-high)/(high-low))*volumemf = sum(ad, mflength) / sum(volume, mflength)//------------------------------------------------------------------------------  // Stop Loss & Take Profit % Basedenablesltp = input(false, title='Enable Stop Loss & Take Profit', group="% Stop Loss & Take Profit")stopTick = input(2.0, title='Stop Loss %', group="% Stop Loss & Take Profit", type=input.float, step=0.1) / 100takeTick = input(4.0, title='Take Profit %', group="% Stop Loss & Take Profit", type=input.float, step=0.1) / 100longStop = strategy.position_avg_price * (1 - stopTick)shortStop = strategy.position_avg_price * (1 + stopTick)shortTake = strategy.position_avg_price * (1 - takeTick)longTake = strategy.position_avg_price * (1 + takeTick)plot(strategy.position_size > 0 and enablesltp and nocontrarian ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")plot(strategy.position_size < 0 and enablesltp and nocontrarian ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Stop Loss")plot(strategy.position_size > 0 and enablesltp and nocontrarian ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")plot(strategy.position_size < 0 and enablesltp and nocontrarian ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")plot(strategy.position_size > 0 and enablesltp and usecontrarian ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Contrarian Long Stop Loss")plot(strategy.position_size < 0 and enablesltp and usecontrarian ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Contrarian Short Stop Loss")plot(strategy.position_size > 0 and enablesltp and usecontrarian ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Contrarian Long Take Profit")plot(strategy.position_size < 0 and enablesltp and usecontrarian ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Contrarian Short Take Profit")//------------------------------------------------------------------------------  // Alert messagesmessage_enterlong  = input("", title="Long Entry message", group="Alert Messages")message_entershort = input("", title="Short Entry message", group="Alert Messages")message_closelong = input("", title="Close Long message", group="Alert Messages")message_closeshort = input("", title="Close Short message", group="Alert Messages")//------------------------------------------------------------------------------  // Strategy Execution//------------------------------------------------------------------------------  // No EMA or CMF Entryif Long and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if Short and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if buySignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if sellSignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    // Contrarian - No EMA or CMF Entryif Long and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if Short and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if buySignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if sellSignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)//------------------------------------------------------------------------------  // Use EMA but No CMF Entry with supertrendif Long  and emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if Short and emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if buySignal and emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if sellSignal and emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    // Use EMA but No CMF Entry no supertrendif emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    // Contrarian - Use EMA but No CMF Entry with supertrendif Long  and emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if Short and emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if buySignal and emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if sellSignal and emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    // Contrarian - Use EMA but No CMF Entry no supertrendif emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    //------------------------------------------------------------------------------      // Use CMF but No EMA Entry with supertrendif Long  and mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if Short and mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if buySignal and mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if sellSignal and mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)// Use CMF but No EMA Entry no supertrendif mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    // Contrarian - Use CMF but No EMA Entry with supertrendif Long  and mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if Short and mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if buySignal and mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if sellSignal and mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)// Contrarian - Use CMF but No EMA Entry no supertrendif mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)//------------------------------------------------------------------------------  // Use EMA and CMF Entry with supertrendif Long  and emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if Short and emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if buySignal and emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if sellSignal and emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    // Use EMA and CMF Entry no supertrendif emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and nocontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    // Contrarian - Use EMA and CMF Entry with supertrendif Long  and emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if Short and emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if buySignal and emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if sellSignal and emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    // Contrarian - Use EMA and CMF Entry no supertrendif emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    if emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Short", strategy.short, alert_message = message_entershort)    if emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and usecontrarian    strategy.entry("Long", strategy.long, alert_message = message_enterlong)    //------------------------------------------------------------------------------  // Hours exitsif strategy.position_size > 0 and timetoclose and enableclose    strategy.close_all(alert_message = message_closelong)if strategy.position_size < 0 and timetoclose and enableclose    strategy.close_all(alert_message = message_closeshort)//------------------------------------------------------------------------------      // % TP and SL exits    if strategy.position_size > 0 and enablesltp and time_cond and nocontrarian    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)if strategy.position_size < 0 and enablesltp and time_cond and nocontrarian    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)// Contrarian - % TP and SL exits    if strategy.position_size > 0 and enablesltp and time_cond and usecontrarian    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)if strategy.position_size < 0 and enablesltp and time_cond and usecontrarian    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)