Pine Script v4 · Strategy
Open Price Strategy
A Pine Script v4 strategy built on EMA (close, 15), Crossover (wait_ema, OpenPA) and Crossunder (wait_ema, OpenPA). It has 38 order rules, 32 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. 40 settings; defaults include Time Frame For Enter ASAP 0930-0931, Time Frame For Wait To Enter 0930-1555 and Time Frame To Exit Trades 0930-1555.
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 Open Price Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Open Price Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Open Price Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- Does Open Price Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 244, 246.
- Does Open Price Strategy run in Zeal Terminal?
- Yes
- It compiles in 75 ms and runs 1,000 bars in 168 ms, in the browser.
BTCUSDT · 1D · default settings
- Open Price
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
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 ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, sum → math.sum.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 10: input(type = input.time) → input.time()
- Line 11: input(type = input.time) → input.time()
- Line 43: ema → ta.ema
- Line 45: crossover → ta.crossover
- Line 46: crossunder → ta.crossunder
13 more edits
- Line 53: ema → ta.ema
- Line 62: ema → ta.ema
- Line 69: input(type = input.integer) → input.int()
- Line 71: sum → math.sum
- Line 71: sum → math.sum
- Line 76: input(type = input.integer) → input.int()
- Line 78: sum → math.sum
- Line 78: sum → math.sum
- Line 84: ema → ta.ema
- Line 87: crossover → ta.crossover
- Line 88: crossunder → ta.crossunder
- Line 92: input(type = input.float) → input.float()
- Line 93: 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⋯wait_emasrc = input(close, title="EMA Source", group="Wait To Enter Settings")-wait_ema = ema(wait_emasrc, wait_ema_length)+wait_ema = ta.ema(wait_emasrc, wait_ema_length)plot(waittoenter ? wait_ema : na, "EMA - Wait To Enter", style=plot.style_linebr, color=#2962ff, linewidth=1)-emacrossup = crossover(wait_ema, OpenPA)+emacrossup = ta.crossover(wait_ema, OpenPA)-emacrossdown = crossunder(wait_ema, OpenPA)+emacrossdown = ta.crossunder(wait_ema, OpenPA)//------------------------------------------------------------------------------ ⋯emasrc_asap = input(close, title="EMA Source", group="EMA Filter (Enter ASAP)")-ema_asap = ema(emasrc_asap, ema_length_asap)+ema_asap = ta.ema(emasrc_asap, ema_length_asap)//plot(ema_asap, "EMA (Enter ASAP)", style=plot.style_linebr, color=#cad850, linewidth=2)⋯emasrc = input(close, title="EMA Source", group="EMA Filter (Wait To Enter)")-ema = ema(emasrc, ema_length)+ema = ta.ema(emasrc, ema_length)//plot(ema, "EMA (Wait To Enter)", style=plot.style_linebr, color=#cad850, linewidth=2)⋯usecmffilter_asap = input(false, title="Use CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")-mflength_asap = input(title="CMF length", group="CMF Filter (Enter ASAP)", type=input.integer, defval=20)+mflength_asap = input.int(title="CMF length", group="CMF Filter (Enter ASAP)", defval=20)ad_asap = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume-mf_asap = sum(ad_asap, mflength_asap) / sum(volume, mflength_asap)+mf_asap = math.sum(ad_asap, mflength_asap) / math.sum(volume, mflength_asap)//------------------------------------------------------------------------------ ⋯usecmffilter = input(false, title="Use CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")-mflength = input(title="CMF length", group="CMF Filter (Wait To Enter)", type=input.integer, defval=20)+mflength = input.int(title="CMF length", group="CMF Filter (Wait To Enter)", defval=20)ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume-mf = sum(ad, mflength) / sum(volume, mflength)+mf = math.sum(ad, mflength) / math.sum(volume, mflength)//------------------------------------------------------------------------------ ⋯stop_emasrc = input(close, title="EMA Source", group="Open Line As Stop Loss")-stop_ema = ema(stop_emasrc, stop_ema_length)+stop_ema = ta.ema(stop_emasrc, stop_ema_length)//plot(stop_ema, "EMA - Wait To Enter", style=plot.style_linebr, color=#2962ff, linewidth=1)plot(openlineclose ? stop_ema : na, "EMA - Wait To Enter", style=plot.style_linebr, color=#2962ff, linewidth=1)-pricecrossup = crossover(stop_ema, OpenPA)+pricecrossup = ta.crossover(stop_ema, OpenPA)-pricecrossdown = crossunder(stop_ema, OpenPA)+pricecrossdown = ta.crossunder(stop_ema, OpenPA)//------------------------------------------------------------------------------ ⋯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
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 7: input() → input.string()
- Line 15: input() → input.string()
- Line 16: input() → input.string()
- Line 17: input() → input.string()
- Line 18: input() → input.bool()
- Line 24: input() → input.bool()
28 more edits
- Line 25: input() → input.bool()
- Line 28: input() → input.string()
- Line 29: input() → input.source()
- Line 30: input() → input.source()
- Line 39: input() → input.bool()
- Line 40: input() → input.bool()
- Line 41: input() → input.int()
- Line 42: input() → input.source()
- Line 49: input() → input.bool()
- Line 50: input() → input.bool()
- Line 51: input() → input.int()
- Line 52: input() → input.source()
- Line 58: input() → input.bool()
- Line 59: input() → input.bool()
- Line 60: input() → input.int()
- Line 61: input() → input.source()
- Line 67: input() → input.bool()
- Line 68: input() → input.bool()
- Line 74: input() → input.bool()
- Line 75: input() → input.bool()
- Line 81: input() → input.bool()
- Line 82: input() → input.int()
- Line 83: input() → input.source()
- Line 91: input() → input.bool()
- Line 104: input() → input.string()
- Line 105: input() → input.string()
- Line 106: input() → input.string()
- Line 107: input() → input.string()
⋯strategy("Open Price 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-firsttradetime = input("0930-0931", title='Time Frame For Enter ASAP', group="Time Restriction")+firsttradetime = input.string("0930-0931", title='Time Frame For Enter ASAP', group="Time Restriction")-startendtime = input("0930-1555", title='Time Frame For Wait To Enter', group="Time Restriction")+startendtime = input.string("0930-1555", title='Time Frame For Wait To Enter', group="Time Restriction")-endtime = input("0930-1555", title='Time Frame To Exit Trades', group="Time Restriction")+endtime = input.string("0930-1555", title='Time Frame To Exit Trades', group="Time Restriction")-enableclose = input(true, title='Enable Close Trade At End Of Exit Time Frame', group="Time Restriction")+enableclose = input.bool(true, title='Enable Close Trade At End Of Exit Time Frame', group="Time Restriction")firsttradetimetobuy = (time(timeframe.period, firsttradetime))⋯// 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")//------------------------------------------------------------------------------ // Open Price Code-openpricetime = input('0930-0931', title="Time To Get Open Price", group="Strategy Settings")+openpricetime = input.string('0930-0931', title="Time To Get Open Price", group="Strategy Settings")-opencondition = input(open, title="Open Price Source", group="Strategy Settings")+opencondition = input.source(open, title="Open Price Source", group="Strategy Settings")-entrycondition = input(close, title="Entry Price Source", group="Strategy Settings")+entrycondition = input.source(close, title="Entry Price Source", group="Strategy Settings")OpenValueTime = time("1", openpricetime)⋯// EMA Open Line Cross Condition (Wait To Enter)-enterasap = input(true, title="Enter Trade ASAP", inline="1", group="Wait To Enter Settings")+enterasap = input.bool(true, title="Enter Trade ASAP", inline="1", group="Wait To Enter Settings")-waittoenter = input(false, title="Wait For EMA To Cross Open Line", inline="1", group="Wait To Enter Settings")+waittoenter = input.bool(false, title="Wait For EMA To Cross Open Line", inline="1", group="Wait To Enter Settings")-wait_ema_length = input(defval=15, minval=1, title="EMA Length", group="Wait To Enter Settings")+wait_ema_length = input.int(defval=15, minval=1, title="EMA Length", group="Wait To Enter Settings")-wait_emasrc = input(close, title="EMA Source", group="Wait To Enter Settings")+wait_emasrc = input.source(close, title="EMA Source", group="Wait To Enter Settings")wait_ema = ta.ema(wait_emasrc, wait_ema_length)⋯// EMA Filter (Enter ASAP)-noemafilter_asap = input(true, title="No EMA Filter", inline="1", group="EMA Filter (Enter ASAP)")+noemafilter_asap = input.bool(true, title="No EMA Filter", inline="1", group="EMA Filter (Enter ASAP)")-useemafilter_asap = input(false, title="Use EMA Filter", inline="1", group="EMA Filter (Enter ASAP)")+useemafilter_asap = input.bool(false, title="Use EMA Filter", inline="1", group="EMA Filter (Enter ASAP)")-ema_length_asap = input(defval=15, minval=1, title="EMA Length", group="EMA Filter (Enter ASAP)")+ema_length_asap = input.int(defval=15, minval=1, title="EMA Length", group="EMA Filter (Enter ASAP)")-emasrc_asap = input(close, title="EMA Source", group="EMA Filter (Enter ASAP)")+emasrc_asap = input.source(close, title="EMA Source", group="EMA Filter (Enter ASAP)")ema_asap = ta.ema(emasrc_asap, ema_length_asap)⋯// EMA Filter (Wait To Enter)-noemafilter = input(true, title="No EMA Filter", inline="1", group="EMA Filter (Wait To Enter)")+noemafilter = input.bool(true, title="No EMA Filter", inline="1", group="EMA Filter (Wait To Enter)")-useemafilter = input(false, title="Use EMA Filter", inline="1", group="EMA Filter (Wait To Enter)")+useemafilter = input.bool(false, title="Use EMA Filter", inline="1", group="EMA Filter (Wait To Enter)")-ema_length = input(defval=15, minval=1, title="EMA Length", group="EMA Filter (Wait To Enter)")+ema_length = input.int(defval=15, minval=1, title="EMA Length", group="EMA Filter (Wait To Enter)")-emasrc = input(close, title="EMA Source", group="EMA Filter (Wait To Enter)")+emasrc = input.source(close, title="EMA Source", group="EMA Filter (Wait To Enter)")ema = ta.ema(emasrc, ema_length)⋯// CMF Filter (Enter ASAP)-nocmffilter_asap = input(true, title="No CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")+nocmffilter_asap = input.bool(true, title="No CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")-usecmffilter_asap = input(false, title="Use CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")+usecmffilter_asap = input.bool(false, title="Use CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")mflength_asap = input.int(title="CMF length", group="CMF Filter (Enter ASAP)", defval=20)⋯// CMF Filter (Wait To Enter)-nocmffilter = input(true, title="No CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")+nocmffilter = input.bool(true, title="No CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")-usecmffilter = input(false, title="Use CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")+usecmffilter = input.bool(false, title="Use CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")mflength = input.int(title="CMF length", group="CMF Filter (Wait To Enter)", defval=20)⋯// EMA For Cross Over Open Line Stop Loss-openlineclose = input(false, title='Exit When Stop Loss EMA Crosses Open Line', group="Open Line As Stop Loss")+openlineclose = input.bool(false, title='Exit When Stop Loss EMA Crosses Open Line', group="Open Line As Stop Loss")-stop_ema_length = input(defval=15, minval=1, title="EMA Length", group="Open Line As Stop Loss")+stop_ema_length = input.int(defval=15, minval=1, title="EMA Length", group="Open Line As Stop Loss")-stop_emasrc = input(close, title="EMA Source", group="Open Line As Stop Loss")+stop_emasrc = input.source(close, title="EMA Source", group="Open Line As Stop Loss")stop_ema = ta.ema(stop_emasrc, stop_ema_length)⋯// 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?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version 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 For Enter ASAP | 0930-0931 | string | firsttradetimetobuy |
| Time Frame For Wait To Enter | 0930-1555 | string | timetobuy |
| Time Frame To Exit Trades | 0930-1555 | string | timetoclose |
| Enable Close Trade At End Of Exit Time Frame | true | bool | close_all close_all line 230 line 232 |
| 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 line 112 line 115 line 119 line 122 line 142 line 145 line 148 line 151 line 170 line 173 line 177 line 180 line 200 line 203 line 207 line 210 |
| 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 line 127 line 130 line 134 line 137 line 156 line 159 line 162 line 165 line 185 line 188 line 192 line 195 line 215 line 218 line 222 line 225 |
| Strategy Settings | |||
| Time To Get Open Price | 0930-0931 | string | OpenValueTime |
| Open Price Source | open | source | OpenPA |
| Entry Price Source | close | source | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 112 line 115 line 127 line 130 line 142 line 145 line 156 line 159 line 170 line 173 line 185 line 188 line 200 line 203 line 215 line 218 |
| Wait To Enter Settings | |||
| Enter Trade ASAP | true | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 112 line 115 line 127 line 130 line 142 line 145 line 156 line 159 line 170 line 173 line 185 line 188 line 200 line 203 line 215 line 218 |
| Wait For EMA To Cross Open Line | false | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long EMA - Wait To Enter line 119 line 122 line 134 line 137 line 148 line 151 line 162 line 165 line 177 line 180 line 192 line 195 line 207 line 210 line 222 line 225 |
| EMA Length | 15 | int · min 1 | wait_ema |
| EMA Source | close | source | wait_ema |
| EMA Filter (Enter ASAP) | |||
| No EMA Filter | true | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 112 line 115 line 127 line 130 line 170 line 173 line 185 line 188 |
| Use EMA Filter | false | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long EMA (Enter ASAP) line 142 line 145 line 156 line 159 line 200 line 203 line 215 line 218 |
| EMA Length | 15 | int · min 1 | ema_asap |
| EMA Source | close | source | ema_asap |
| EMA Filter (Wait To Enter) | |||
| No EMA Filter | true | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 119 line 122 line 134 line 137 line 177 line 180 line 192 line 195 |
| Use EMA Filter | false | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long EMA (Wait To Enter) line 148 line 151 line 162 line 165 line 207 line 210 line 222 line 225 |
| EMA Length | 15 | int · min 1 | ema |
| EMA Source | close | source | ema |
| CMF Filter (Enter ASAP) | |||
| No CMF Filter | true | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 112 line 115 line 127 line 130 line 142 line 145 line 156 line 159 |
| Use CMF Filter | false | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 170 line 173 line 185 line 188 line 200 line 203 line 215 line 218 |
| CMF length | 20 | int (written input.integer) | mf_asap |
| CMF Filter (Wait To Enter) | |||
| No CMF Filter | true | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 119 line 122 line 134 line 137 line 148 line 151 line 162 line 165 |
| Use CMF Filter | false | bool | entry Long entry Short entry Short entry Long entry Long entry Short entry Short entry Long line 177 line 180 line 192 line 195 line 207 line 210 line 222 line 225 |
| CMF length | 20 | int (written input.integer) | mf |
| Open Line As Stop Loss | |||
| Exit When Stop Loss EMA Crosses Open Line | false | bool | close_all close_all EMA - Wait To Enter line 237 line 239 |
| EMA Length | 15 | int · min 1 | stop_ema |
| EMA Source | close | source | stop_ema |
| % Stop Loss & Take Profit | |||
| Enable Stop Loss & Take Profit | false | bool | exit Close Long exit Close Short Long Stop Loss Short Stop Loss Long Take Profit Short Take Profit line 243 line 245 |
| 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
- EMA (
ema,ta.emain v5)EMA Source (close), EMA Length (15)wait_ema · line 43 - Crossover (
crossover,ta.crossoverin v5)wait_ema, OpenPAemacrossup · line 45 - Crossunder (
crossunder,ta.crossunderin v5)wait_ema, OpenPAemacrossdown · line 46 - EMA (
ema,ta.emain v5)EMA Source (close), EMA Length (15)ema_asap · line 53 - EMA (
ema,ta.emain v5)EMA Source (close), EMA Length (15)ema · line 62 - EMA (
ema,ta.emain v5)EMA Source (close), EMA Length (15)stop_ema · line 84 - Crossover (
crossover,ta.crossoverin v5)stop_ema, OpenPApricecrossup · line 87 - Crossunder (
crossunder,ta.crossunderin v5)stop_ema, OpenPApricecrossdown · line 88
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 | entrycondition > OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and nocontrarian | On | 113 |
| Open Short short | entrycondition < OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and nocontrarian | On | 116 |
| Open Long long | emacrossup and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and nocontrarian | On | 120 |
| Open Short short | emacrossdown and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and nocontrarian | On | 123 |
| Open Short short | entrycondition > OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and usecontrarian | On | 128 |
| Open Long long | entrycondition < OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and usecontrarian | On | 131 |
| Open Short short | emacrossup and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and usecontrarian | On | 135 |
| Open Long long | emacrossdown and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and usecontrarian | On | 138 |
| Open Long long | entrycondition > OpenPA and close > ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and nocontrarian | On | 143 |
| Open Short short | entrycondition < OpenPA and close < ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and nocontrarian | On | 146 |
| Open Long long | emacrossup and close > ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and nocontrarian | On | 149 |
| Open Short short | emacrossdown and close < ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and nocontrarian | On | 152 |
| Open Short short | entrycondition > OpenPA and close > ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and usecontrarian | On | 157 |
| Open Long long | entrycondition < OpenPA and close < ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and usecontrarian | On | 160 |
| Open Short short | emacrossup and close > ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and usecontrarian | On | 163 |
| Open Long long | emacrossdown and close < ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and usecontrarian | On | 166 |
| Open Long long | entrycondition > OpenPA and mf_asap > 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and nocontrarian | On | 171 |
| Open Short short | entrycondition < OpenPA and mf_asap < 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and nocontrarian | On | 174 |
| Open Long long | emacrossup and mf > 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and nocontrarian | On | 178 |
| Open Short short | emacrossdown and mf < 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and nocontrarian | On | 181 |
| Open Short short | entrycondition > OpenPA and mf_asap > 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and usecontrarian | On | 186 |
| Open Long long | entrycondition < OpenPA and mf_asap < 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and usecontrarian | On | 189 |
| Open Short short | emacrossup and mf > 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and usecontrarian | On | 193 |
| Open Long long | emacrossdown and mf < 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and usecontrarian | On | 196 |
| Open Long long | entrycondition > OpenPA and close > ema_asap and mf_asap > 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and nocontrarian | On | 201 |
| Open Short short | entrycondition < OpenPA and close < ema_asap and mf_asap < 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and nocontrarian | On | 204 |
| Open Long long | emacrossup and close > ema and mf > 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and nocontrarian | On | 208 |
| Open Short short | emacrossdown and close < ema and mf < 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and nocontrarian | On | 211 |
| Open Short short | entrycondition > OpenPA and close > ema_asap and mf_asap > 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and usecontrarian | On | 216 |
| Open Long long | entrycondition < OpenPA and close < ema_asap and mf_asap < 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and usecontrarian | On | 219 |
| Open Short short | emacrossup and close > ema and mf > 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and usecontrarian | On | 223 |
| Open Long long | emacrossdown and close < ema and mf < 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and usecontrarian | On | 226 |
| Close | strategy.position_size > 0 and timetoclose and enableclose | On | 231 |
| Close | strategy.position_size < 0 and timetoclose and enableclose | On | 233 |
| Close | strategy.position_size > 0 and pricecrossdown and openlineclose | On | 238 |
| Close | strategy.position_size < 0 and pricecrossup and openlineclose | On | 240 |
| Exit Close Long stop and limit | strategy.position_size > 0 and enablesltp and time_cond | On | 244 |
| Exit Close Short stop and limit | strategy.position_size < 0 and enablesltp and time_cond | On | 246 |
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.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| Open Price Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 75 ms | With a workaround 1,000 bars in 168 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("Open Price 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 Settingsfirsttradetime = input("0930-0931", title='Time Frame For Enter ASAP', group="Time Restriction")startendtime = input("0930-1555", title='Time Frame For Wait To Enter', group="Time Restriction")endtime = input("0930-1555", title='Time Frame To Exit Trades', group="Time Restriction")enableclose = input(true, title='Enable Close Trade At End Of Exit Time Frame', group="Time Restriction")firsttradetimetobuy = (time(timeframe.period, firsttradetime))timetobuy = (time(timeframe.period, startendtime))timetoclose = na(time(timeframe.period, endtime))//------------------------------------------------------------------------------ // 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")//------------------------------------------------------------------------------ // Open Price Codeopenpricetime = input('0930-0931', title="Time To Get Open Price", group="Strategy Settings")opencondition = input(open, title="Open Price Source", group="Strategy Settings")entrycondition = input(close, title="Entry Price Source", group="Strategy Settings")OpenValueTime = time("1", openpricetime)var OpenPA = 0.0if OpenValueTime if not OpenValueTime[1] OpenPA := openconditionplot(not OpenValueTime ? OpenPA : na, title="Open Price", color=color.red, linewidth=2, style=plot.style_linebr)//------------------------------------------------------------------------------ // EMA Open Line Cross Condition (Wait To Enter)enterasap = input(true, title="Enter Trade ASAP", inline="1", group="Wait To Enter Settings")waittoenter = input(false, title="Wait For EMA To Cross Open Line", inline="1", group="Wait To Enter Settings")wait_ema_length = input(defval=15, minval=1, title="EMA Length", group="Wait To Enter Settings")wait_emasrc = input(close, title="EMA Source", group="Wait To Enter Settings")wait_ema = ema(wait_emasrc, wait_ema_length)plot(waittoenter ? wait_ema : na, "EMA - Wait To Enter", style=plot.style_linebr, color=#2962ff, linewidth=1)emacrossup = crossover(wait_ema, OpenPA)emacrossdown = crossunder(wait_ema, OpenPA)//------------------------------------------------------------------------------ // EMA Filter (Enter ASAP)noemafilter_asap = input(true, title="No EMA Filter", inline="1", group="EMA Filter (Enter ASAP)")useemafilter_asap = input(false, title="Use EMA Filter", inline="1", group="EMA Filter (Enter ASAP)")ema_length_asap = input(defval=15, minval=1, title="EMA Length", group="EMA Filter (Enter ASAP)")emasrc_asap = input(close, title="EMA Source", group="EMA Filter (Enter ASAP)")ema_asap = ema(emasrc_asap, ema_length_asap)//plot(ema_asap, "EMA (Enter ASAP)", style=plot.style_linebr, color=#cad850, linewidth=2)plot(useemafilter_asap ? ema_asap : na, "EMA (Enter ASAP)", style=plot.style_linebr, color=#cad850, linewidth=2)//------------------------------------------------------------------------------ // EMA Filter (Wait To Enter)noemafilter = input(true, title="No EMA Filter", inline="1", group="EMA Filter (Wait To Enter)")useemafilter = input(false, title="Use EMA Filter", inline="1", group="EMA Filter (Wait To Enter)")ema_length = input(defval=15, minval=1, title="EMA Length", group="EMA Filter (Wait To Enter)")emasrc = input(close, title="EMA Source", group="EMA Filter (Wait To Enter)")ema = ema(emasrc, ema_length)//plot(ema, "EMA (Wait To Enter)", style=plot.style_linebr, color=#cad850, linewidth=2)plot(useemafilter ? ema : na, "EMA (Wait To Enter)", style=plot.style_linebr, color=#cad850, linewidth=2)//------------------------------------------------------------------------------ // CMF Filter (Enter ASAP)nocmffilter_asap = input(true, title="No CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")usecmffilter_asap = input(false, title="Use CMF Filter", inline="1", group="CMF Filter (Enter ASAP)")mflength_asap = input(title="CMF length", group="CMF Filter (Enter ASAP)", type=input.integer, defval=20)ad_asap = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volumemf_asap = sum(ad_asap, mflength_asap) / sum(volume, mflength_asap)//------------------------------------------------------------------------------ // CMF Filter (Wait To Enter)nocmffilter = input(true, title="No CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")usecmffilter = input(false, title="Use CMF Filter", inline="1", group="CMF Filter (Wait To Enter)")mflength = input(title="CMF length", group="CMF Filter (Wait To Enter)", type=input.integer, defval=20)ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volumemf = sum(ad, mflength) / sum(volume, mflength)//------------------------------------------------------------------------------ // EMA For Cross Over Open Line Stop Lossopenlineclose = input(false, title='Exit When Stop Loss EMA Crosses Open Line', group="Open Line As Stop Loss")stop_ema_length = input(defval=15, minval=1, title="EMA Length", group="Open Line As Stop Loss")stop_emasrc = input(close, title="EMA Source", group="Open Line As Stop Loss")stop_ema = ema(stop_emasrc, stop_ema_length)//plot(stop_ema, "EMA - Wait To Enter", style=plot.style_linebr, color=#2962ff, linewidth=1)plot(openlineclose ? stop_ema : na, "EMA - Wait To Enter", style=plot.style_linebr, color=#2962ff, linewidth=1)pricecrossup = crossover(stop_ema, OpenPA)pricecrossdown = crossunder(stop_ema, OpenPA)//------------------------------------------------------------------------------ // 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 ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")plot(strategy.position_size < 0 and enablesltp ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Stop Loss")plot(strategy.position_size > 0 and enablesltp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")plot(strategy.position_size < 0 and enablesltp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="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//------------------------------------------------------------------------------ // Entry Alerts - No EMA or CMFif entrycondition > OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if entrycondition < OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) // Entry Alerts (Wait To Enter) - No EMA or CMFif emacrossup and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if emacrossdown and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) //------------------------------------------------------------------------------ // Contrarian - Entry Alerts - No EMA or CMFif entrycondition > OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if entrycondition < OpenPA and time_cond and firsttradetimetobuy and noemafilter_asap and nocmffilter_asap and enterasap and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) // Contrarian - Entry Alerts (Wait To Enter) - No EMA or CMFif emacrossup and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if emacrossdown and time_cond and timetobuy and noemafilter and nocmffilter and waittoenter and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) //------------------------------------------------------------------------------ // Entry Alerts - Use EMA but No CMFif entrycondition > OpenPA and close > ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if entrycondition < OpenPA and close < ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort)// Entry Alerts (Wait To Enter) - Use EMA but No CMFif emacrossup and close > ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if emacrossdown and close < ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) //------------------------------------------------------------------------------ // Contrarian - Entry Alerts - Use EMA but No CMFif entrycondition > OpenPA and close > ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if entrycondition < OpenPA and close < ema_asap and time_cond and firsttradetimetobuy and useemafilter_asap and nocmffilter_asap and enterasap and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong)// Contrarian - Entry Alerts (Wait To Enter) - Use EMA but No CMFif emacrossup and close > ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if emacrossdown and close < ema and time_cond and timetobuy and useemafilter and nocmffilter and waittoenter and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) //------------------------------------------------------------------------------ // Entry Alerts - Use CMF but No EMAif entrycondition > OpenPA and mf_asap > 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if entrycondition < OpenPA and mf_asap < 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) // Entry Alerts (Wait To Enter) - Use CMF but No EMAif emacrossup and mf > 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if emacrossdown and mf < 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) //------------------------------------------------------------------------------ // Contrarian - Entry Alerts - Use CMF but No EMAif entrycondition > OpenPA and mf_asap > 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if entrycondition < OpenPA and mf_asap < 0 and time_cond and firsttradetimetobuy and noemafilter_asap and usecmffilter_asap and enterasap and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) // Contrarian - Entry Alerts (Wait To Enter) - Use CMF but No EMAif emacrossup and mf > 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if emacrossdown and mf < 0 and time_cond and timetobuy and noemafilter and usecmffilter and waittoenter and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) //------------------------------------------------------------------------------ // Entry Alerts - Use EMA and CMFif entrycondition > OpenPA and close > ema_asap and mf_asap > 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if entrycondition < OpenPA and close < ema_asap and mf_asap < 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) // Entry Alerts (Wait To Enter) - Use EMA and CMFif emacrossup and close > ema and mf > 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and nocontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) if emacrossdown and close < ema and mf < 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and nocontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) //------------------------------------------------------------------------------ // Contrarian - Entry Alerts - Use EMA and CMFif entrycondition > OpenPA and close > ema_asap and mf_asap > 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if entrycondition < OpenPA and close < ema_asap and mf_asap < 0 and time_cond and firsttradetimetobuy and useemafilter_asap and usecmffilter_asap and enterasap and usecontrarian strategy.entry("Long", strategy.long, alert_message = message_enterlong) // Contrarian - Entry Alerts (Wait To Enter) - Use EMA and CMFif emacrossup and close > ema and mf > 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter and usecontrarian strategy.entry("Short", strategy.short, alert_message = message_entershort) if emacrossdown and close < ema and mf < 0 and time_cond and timetobuy and useemafilter and usecmffilter and waittoenter 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) //------------------------------------------------------------------------------ // Open Line exitsif strategy.position_size > 0 and pricecrossdown and openlineclose strategy.close_all(alert_message = message_closelong)if strategy.position_size < 0 and pricecrossup and openlineclose strategy.close_all(alert_message = message_closeshort)//------------------------------------------------------------------------------ // % TP and SL exits if strategy.position_size > 0 and enablesltp and time_cond strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)if strategy.position_size < 0 and enablesltp and time_cond strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)