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
- 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
VerifiedSame 26 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 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)⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Note For Your Reference Only | | string | unused |
| Backtesting | |||
| Backtesting Start Date | timestamp("2021-10-01T00:00:00") | time | time_cond |
| Backtesting End Date | timestamp("9999-12-31T00:00:00") | time | time_cond |
| Time Restriction | |||
| Time Frame To Enter Trades | | string | timetobuy |
| Time Frame To Exit Trades | | string | timetoclose |
| Enable Close Trade At End Of Exit Time Frame | false | bool | close_all close_all line 277 line 279 |
| Enter Supertrend ASAP | true | bool | entry 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 Supertrend | false | bool | entry 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 Signals | true | bool | 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 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 Signals | false | bool | 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 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 Supertrend | false | bool | 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 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 Supertrend | true | bool | 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 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 Period | 10 | int (written input.integer) | atr2 atr |
| ATR Source | hl2 | source | up dn |
| ATR Multiplier | 3.0 | float · step 0.1 | up dn |
| Change ATR Calculation Method ? | true | bool | atr |
| EMA Filter | |||
| No EMA Filter | true | bool | 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 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 Filter | false | bool | 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 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 Length | 15 | int · min 1 | ema |
| EMA Source | close | source | ema |
| EMA Price Source | close | source | 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 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 Filter | true | bool | 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 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 Filter | false | bool | 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 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 length | 20 | int (written input.integer) | mf |
| CMF Source | close | source | ad |
| % Stop Loss & Take Profit | |||
| Enable Stop Loss & Take Profit | false | bool | exit 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.0 | float · step 0.1 | longStop shortStop |
| Take Profit % | 4.0 | float · step 0.1 | shortTake longTake |
| Alert Messages | |||
| Long Entry message | | string | entry Long |
| Short Entry message | | string | entry Short |
| Close Long message | | string | close_all exit Close Long |
| Close Short message | | string | close_all exit Close Short |
What it calculates
- SMA (
sma,ta.smain v5)tr, ATR Period (10)atr2 · line 34 - ATR (
atr,ta.atrin v5)ATR Period (10)atr · line 35 - EMA (
ema,ta.emain 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | Long and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and nocontrarian | On | 96 |
| Open Short short | Short and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and nocontrarian | On | 99 |
| Open Long long | buySignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and nocontrarian | On | 102 |
| Open Short short | sellSignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and nocontrarian | On | 105 |
| Open Short short | Long and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and usecontrarian | On | 109 |
| Open Long long | Short and time_cond and timetobuy and enableentry and noemafilter and nocmffilter and usesupertrend and usecontrarian | On | 112 |
| Open Short short | buySignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and usecontrarian | On | 115 |
| Open Long long | sellSignal and time_cond and timetobuy and waitentry and noemafilter and nocmffilter and usesupertrend and usecontrarian | On | 118 |
| Open Long long | Long and emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and nocontrarian | On | 122 |
| Open Short short | Short and emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and nocontrarian | On | 125 |
| Open Long long | buySignal and emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and nocontrarian | On | 128 |
| Open Short short | sellSignal and emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and nocontrarian | On | 131 |
| Open Long long | emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and nocontrarian | On | 135 |
| Open Short short | emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and nocontrarian | On | 138 |
| Open Long long | emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and nocontrarian | On | 141 |
| Open Short short | emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and nocontrarian | On | 144 |
| Open Short short | Long and emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and usecontrarian | On | 148 |
| Open Long long | Short and emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and usesupertrend and usecontrarian | On | 151 |
| Open Short short | buySignal and emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and usecontrarian | On | 154 |
| Open Long long | sellSignal and emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and usesupertrend and usecontrarian | On | 157 |
| Open Short short | emapricesrc > ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and usecontrarian | On | 161 |
| Open Long long | emapricesrc < ema and time_cond and timetobuy and enableentry and useemafilter and nocmffilter and nosupertrend and usecontrarian | On | 164 |
| Open Short short | emapricesrc > ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and usecontrarian | On | 167 |
| Open Long long | emapricesrc < ema and time_cond and timetobuy and waitentry and useemafilter and nocmffilter and nosupertrend and usecontrarian | On | 170 |
| Open Long long | Long and mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and nocontrarian | On | 175 |
| Open Short short | Short and mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and nocontrarian | On | 178 |
| Open Long long | buySignal and mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and nocontrarian | On | 181 |
| Open Short short | sellSignal and mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and nocontrarian | On | 184 |
| Open Long long | mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and nocontrarian | On | 187 |
| Open Short short | mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and nocontrarian | On | 190 |
| Open Long long | mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and nocontrarian | On | 193 |
| Open Short short | mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and nocontrarian | On | 196 |
| Open Short short | Long and mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and usecontrarian | On | 200 |
| Open Long long | Short and mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and usesupertrend and usecontrarian | On | 203 |
| Open Short short | buySignal and mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and usecontrarian | On | 206 |
| Open Long long | sellSignal and mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and usesupertrend and usecontrarian | On | 209 |
| Open Short short | mf > 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and usecontrarian | On | 212 |
| Open Long long | mf < 0 and time_cond and timetobuy and enableentry and noemafilter and usecmffilter and nosupertrend and usecontrarian | On | 215 |
| Open Short short | mf > 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and usecontrarian | On | 218 |
| Open Long long | mf < 0 and time_cond and timetobuy and waitentry and noemafilter and usecmffilter and nosupertrend and usecontrarian | On | 221 |
| Open Long long | Long and emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and nocontrarian | On | 225 |
| Open Short short | Short and emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and nocontrarian | On | 228 |
| Open Long long | buySignal and emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and nocontrarian | On | 231 |
| Open Short short | sellSignal and emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and nocontrarian | On | 234 |
| Open Long long | emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and nocontrarian | On | 238 |
| Open Short short | emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and nocontrarian | On | 241 |
| Open Long long | emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and nocontrarian | On | 244 |
| Open Short short | emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and nocontrarian | On | 247 |
| Open Short short | Long and emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and usecontrarian | On | 251 |
| Open Long long | Short and emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and usesupertrend and usecontrarian | On | 254 |
| Open Short short | buySignal and emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and usecontrarian | On | 257 |
| Open Long long | sellSignal and emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and usesupertrend and usecontrarian | On | 260 |
| Open Short short | emapricesrc > ema and mf > 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and usecontrarian | On | 264 |
| Open Long long | emapricesrc < ema and mf < 0 and time_cond and timetobuy and enableentry and useemafilter and usecmffilter and nosupertrend and usecontrarian | On | 267 |
| Open Short short | emapricesrc > ema and mf > 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and usecontrarian | On | 270 |
| Open Long long | emapricesrc < ema and mf < 0 and time_cond and timetobuy and waitentry and useemafilter and usecmffilter and nosupertrend and usecontrarian | On | 273 |
| Close | strategy.position_size > 0 and timetoclose and enableclose | On | 278 |
| Close | strategy.position_size < 0 and timetoclose and enableclose | On | 280 |
| Exit Close Long stop and limit | strategy.position_size > 0 and enablesltp and time_cond and nocontrarian | On | 284 |
| Exit Close Short stop and limit | strategy.position_size < 0 and enablesltp and time_cond and nocontrarian | On | 286 |
| Exit Close Long stop and limit | strategy.position_size > 0 and enablesltp and time_cond and usecontrarian | On | 289 |
| Exit Close Short stop and limit | strategy.position_size < 0 and enablesltp and time_cond and usecontrarian | On | 291 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −20.5% | +102.5% | 26 | 31% | 0.88 | 63.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +7.8% | +5.5% | 24 | 38% | 1.19 | 15.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +60.5% | +9.8% | 23 | 43% | 1.34 | 67.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +11.0% | +8.4% | 24 | 29% | 1.20 | 20.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +105.8% | +16.7% | 23 | 43% | 1.78 | 31.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +13.7% | +21.5% | 24 | 33% | 1.22 | 22.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.5% | +148.3% | 27 | 33% | 1.00 | 75.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.5% | +17.1% | 24 | 38% | 1.04 | 16.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 6 | 17% | −$5,633.46 |
| Sideways market | 14 | 36% | $6,937.72 |
| Falling market | 6 | 33% | −$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.
All 26 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 Feb 2024 42,582.90 | 20 Mar 2024 61,937.40 | 44 | $4,545.14 |
| short | 20 Mar 2024 61,937.40 | 21 May 2024 71,446.60 | 62 | −$1,535.29 |
| long | 21 May 2024 71,446.60 | 22 Jun 2024 64,143.60 | 32 | −$1,022.17 |
| short | 22 Jun 2024 64,143.60 | 16 Jul 2024 64,724.10 | 24 | −$90.50 |
| long | 16 Jul 2024 64,724.10 | 4 Aug 2024 60,698.00 | 19 | −$622.03 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.20 | 20 | −$550.14 |
| long | 24 Aug 2024 64,037.20 | 6 Sep 2024 56,180.00 | 13 | −$1,226.98 |
| short | 6 Sep 2024 56,180.00 | 20 Sep 2024 62,948.00 | 14 | −$1,204.70 |
| long | 20 Sep 2024 62,948.00 | 24 Dec 2024 94,881.50 | 95 | $5,072.99 |
| short | 24 Dec 2024 94,881.50 | 18 Jan 2025 104,077.00 | 25 | −$969.21 |
| long | 18 Jan 2025 104,077.00 | 25 Feb 2025 91,552.90 | 38 | −$1,203.39 |
| short | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | −$296.78 |
| long | 3 Mar 2025 94,270.00 | 11 Mar 2025 78,595.90 | 8 | −$1,662.68 |
| short | 11 Mar 2025 78,595.90 | 23 Apr 2025 93,443.00 | 43 | −$1,889.05 |
| long | 23 Apr 2025 93,443.00 | 23 Jun 2025 100,964.00 | 61 | $804.86 |
| short | 23 Jun 2025 100,964.00 | 10 Jul 2025 111,234.00 | 17 | −$1,017.21 |
| long | 10 Jul 2025 111,234.00 | 22 Aug 2025 112,500.00 | 43 | $113.81 |
| short | 22 Aug 2025 112,500.00 | 2 Oct 2025 118,595.00 | 41 | −$541.78 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$490.79 |
| short | 11 Oct 2025 112,774.00 | 14 Jan 2026 95,414.00 | 95 | $1,539.40 |
| long | 14 Jan 2026 95,414.00 | 21 Jan 2026 88,427.70 | 7 | −$732.21 |
| short | 21 Jan 2026 88,427.70 | 5 Mar 2026 72,666.80 | 43 | $1,782.35 |
| long | 5 Mar 2026 72,666.80 | 30 Mar 2026 66,010.90 | 25 | −$915.94 |
| short | 30 Mar 2026 66,010.90 | 14 Apr 2026 74,418.00 | 15 | −$1,273.59 |
| long | 14 Apr 2026 74,418.00 | 23 May 2026 75,539.50 | 39 | $150.70 |
| short | 23 May 2026 75,539.50 | 22 Jul 2026 66,556.10 | 60 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Supertrend Strategy this page | — | v4 strategy | −20.5% | 26 | 63.5% |
| 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% |
| EMA & Supertrend by bhavikmota | ema sma atr | v4 strategy | +2,123.6% | 13 | 980.9% |
| Koala System EURUSD 15min by SoftKill21 | sma ema atr | v4 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 109 ms | With a workaround 1,000 bars in 304 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © 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)