Pine Script v4 · Strategy
Tale Indicators Strategy
A Pine Script v4 strategy built on EMA (close, 3), Crossover (fastMA, slowMALEn) and Crossunder (fastMA, slowMASEn). It has 6 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays 0.1% commission. 19 settings; defaults include FAST EMA 3, Source for Fast close and SLOW EMA 15.
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 Tale Indicators 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 Tale Indicators 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 Tale Indicators 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 Tale Indicators Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Tale Indicators Strategy run in Zeal Terminal?
- Yes
- It compiles in 32 ms and runs 1,000 bars in 116 ms, in the browser.
BTCUSDT · 1D · default settings
- Slow EMA
- Fast EMA
- Fast EMA Ex
- Plot Enter Points
- Plot Bull Exit
- Plot Bear Exit
- Plot Bull ReEnter
- Plot Bear ReEnter
- 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, $20,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
“Show Date Range” is declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 81, 82, 83, 84, 85, 86. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 30
iff() on line 30, 30. v5 writes it as the ternary c ? a : b.
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.
- 6 strategy calls use the when = argument (line 81, 82, 83, 84, 85, 86). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
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 8: ema → ta.ema
- Line 12: ema → ta.ema
- Line 16: ema → ta.ema
- Line 19: ema → ta.ema
- Line 21: ema → ta.ema
15 more edits
- Line 23: ema → ta.ema
- Line 25: ema → ta.ema
- Line 26: crossover → ta.crossover
- Line 27: crossunder → ta.crossunder
- Line 28: crossunder → ta.crossunder
- Line 29: crossover → ta.crossover
- Line 30: iff(c, a, b) → (c ? a : b)
- Line 30: iff(c, a, b) → (c ? a : b)
- Line 53: input(type = input.integer) → input.int()
- Line 54: input(type = input.integer) → input.int()
- Line 55: input(type = input.integer) → input.int()
- Line 56: input(type = input.integer) → input.int()
- Line 57: input(type = input.integer) → input.int()
- Line 58: input(type = input.integer) → input.int()
- Line 60: input(type = input.bool) → input.bool()
⋯// © ehaarjee, ECHKAY, JackBauer007-//@version=4+//@version=5//study(title="Tale_indicators", overlay=true)⋯src_fast = input(close, title="Source for Fast")-fastMA = ema(src_fast, len_fast)+fastMA = ta.ema(src_fast, len_fast)plot(fastMA, title="Slow EMA", color=color.orange)⋯src_slow = input(close, title="Source for Slow")-slowMA = ema(src_slow, len_slow)+slowMA = ta.ema(src_slow, len_slow)plot(slowMA, title="Fast EMA", color=color.blue)⋯src_fast_exit = input(close, title="Source for Fast Exit")-fastMAE = ema(src_fast_exit, len_fast_exit)+fastMAE = ta.ema(src_fast_exit, len_fast_exit)plot(fastMAE, title="Fast EMA Ex", color=color.red)src_slow_enter_short = input(low, title="Source for Short Entry")-slowMASEn = ema(src_slow_enter_short, len_slow)+slowMASEn = ta.ema(src_slow_enter_short, len_slow)src_slow_enter_long = input(high, title="Source for Long Entry")-slowMALEn = ema(src_slow_enter_long, len_slow)+slowMALEn = ta.ema(src_slow_enter_long, len_slow)src_slow_exit_short = input(high, title="Source for Short Exit")-slowMASEx = ema(src_slow_exit_short, len_slow)+slowMASEx = ta.ema(src_slow_exit_short, len_slow)src_slow_exit_long = input(low, title="Source for Long Exit")-slowMALEx = ema(src_slow_exit_long, len_slow)+slowMALEx = ta.ema(src_slow_exit_long, len_slow)-enter_long = crossover(fastMA, slowMALEn)+enter_long = ta.crossover(fastMA, slowMALEn)-enter_short = crossunder(fastMA, slowMASEn)+enter_short = ta.crossunder(fastMA, slowMASEn)-exit_long = crossunder(fastMAE, slowMALEx)+exit_long = ta.crossunder(fastMAE, slowMALEx)-exit_short = crossover(fastMAE, slowMASEx)+exit_short = ta.crossover(fastMAE, slowMASEx)-out_enter = iff(enter_long == true, 1, iff(enter_short == true, -1, 0))+out_enter = (enter_long == true ? 1 : (enter_short == true ? -1 : 0))plotarrow(out_enter, "Plot Enter Points", colorup=color.green, colordown=color.red, maxheight = 30)⋯// === INPUT BACKTEST RANGE ===-fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)+fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 2000)+fromYear = input.int(defval = 2020, title = "From Year", minval = 2000)-thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)+thruMonth = input.int(defval = 1, title = "Thru Month", minval = 1, maxval = 12)-thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)+thruDay = input.int(defval = 1, title = "Thru Day", minval = 1, maxval = 31)-thruYear = input(defval = 2100, title = "Thru Year", type = input.integer, minval = 2000)+thruYear = input.int(defval = 2100, title = "Thru Year", minval = 2000)// === INPUT SHOW PLOT ===-showDate = input(defval = true, title = "Show Date Range", type = input.bool)+showDate = input.bool(defval = true, title = "Show Date Range")// === FUNCTION EXAMPLE ===⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 6: input() → input.int()
- Line 7: input() → input.source()
- Line 10: input() → input.int()
- Line 11: input() → input.source()
- Line 14: input() → input.int()
- Line 15: input() → input.source()
12 more edits
- Line 18: input() → input.source()
- Line 20: input() → input.source()
- Line 22: input() → input.source()
- Line 24: input() → input.source()
- Line 36: input() → input.float()
- Line 51: input() → input.bool()
- Line 81: when = (window() and enter_long and not(bull_exit)) → if block
- Line 82: when = (window() and bull_reenter) → if block
- Line 83: when = (window() and bull_exit) → if block
- Line 84: when = (window() and enter_short and not(bear_exit)) → if block
- Line 85: when = (window() and bear_reenter) → if block
- Line 86: when = (window() and bear_exit) → if block
⋯strategy("Tale Indicators Strategy", overlay=true, precision=8, max_bars_back=200, pyramiding=0, initial_capital=20000, commission_type="percent", commission_value=0.1)-len_fast = input(3, minval=1, title="FAST EMA")+len_fast = input.int(3, minval=1, title="FAST EMA")-src_fast = input(close, title="Source for Fast")+src_fast = input.source(close, title="Source for Fast")fastMA = ta.ema(src_fast, len_fast)plot(fastMA, title="Slow EMA", color=color.orange)-len_slow = input(15, minval=1, title="SLOW EMA")+len_slow = input.int(15, minval=1, title="SLOW EMA")-src_slow = input(close, title="Source for Slow")+src_slow = input.source(close, title="Source for Slow")slowMA = ta.ema(src_slow, len_slow)plot(slowMA, title="Fast EMA", color=color.blue)-len_fast_exit = input(3, minval=1, title="FAST EMA Exit")+len_fast_exit = input.int(3, minval=1, title="FAST EMA Exit")-src_fast_exit = input(close, title="Source for Fast Exit")+src_fast_exit = input.source(close, title="Source for Fast Exit")fastMAE = ta.ema(src_fast_exit, len_fast_exit)plot(fastMAE, title="Fast EMA Ex", color=color.red)-src_slow_enter_short = input(low, title="Source for Short Entry")+src_slow_enter_short = input.source(low, title="Source for Short Entry")slowMASEn = ta.ema(src_slow_enter_short, len_slow)-src_slow_enter_long = input(high, title="Source for Long Entry")+src_slow_enter_long = input.source(high, title="Source for Long Entry")slowMALEn = ta.ema(src_slow_enter_long, len_slow)-src_slow_exit_short = input(high, title="Source for Short Exit")+src_slow_exit_short = input.source(high, title="Source for Short Exit")slowMASEx = ta.ema(src_slow_exit_short, len_slow)-src_slow_exit_long = input(low, title="Source for Long Exit")+src_slow_exit_long = input.source(low, title="Source for Long Exit")slowMALEx = ta.ema(src_slow_exit_long, len_slow)⋯bgcolor(c)-exit_tuner = input(0.005, title="Exit Tuner to touch slowEMA")+exit_tuner = input.float(0.005, title="Exit Tuner to touch slowEMA")bull_exit = (low>(fastMAE*(1+exit_tuner))) or exit_long ⋯plotshape(bear_reenter, "Plot Bear ReEnter", style = shape.arrowdown, color=color.red, size=size.small, text="ReS", location=location.abovebar)-run_strategy = input(false, title="Run Strategy")+run_strategy = input.bool(false, title="Run Strategy")// === INPUT BACKTEST RANGE ===⋯if(run_strategy)- strategy.entry("LO", strategy.long, when=(window() and enter_long and not(bull_exit)), qty=4)+ if (window() and enter_long and not(bull_exit))+ strategy.entry("LO", strategy.long, qty=4)- strategy.entry("LO", strategy.long, when=(window() and bull_reenter), qty=1)+ if (window() and bull_reenter)+ strategy.entry("LO", strategy.long, qty=1)- strategy.close("LO", when=(window() and bull_exit))+ if (window() and bull_exit)+ strategy.close("LO")- strategy.entry("SO", strategy.short, when=(window() and enter_short and not(bear_exit)), qty=4)+ if (window() and enter_short and not(bear_exit))+ strategy.entry("SO", strategy.short, qty=4)- strategy.entry("SO", strategy.short, when=(window() and bear_reenter), qty=1)+ if (window() and bear_reenter)+ strategy.entry("SO", strategy.short, qty=1)- strategy.close("SO", when=(window() and bear_exit))+ if (window() and bear_exit)+ strategy.close("SO")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.
⋯// © ehaarjee, ECHKAY, JackBauer007-//@version=5+//@version=6//study(title="Tale_indicators", overlay=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| FAST EMA | 3 | int · min 1 | fastMA |
| Source for Fast | close | source | fastMA |
| SLOW EMA | 15 | int · min 1 | slowMA slowMASEn slowMALEn slowMASEx slowMALEx |
| Source for Slow | close | source | slowMA |
| FAST EMA Exit | 3 | int · min 1 | fastMAE |
| Source for Fast Exit | close | source | fastMAE |
| Source for Short Entry | low | source | slowMASEn |
| Source for Long Entry | high | source | slowMALEn |
| Source for Short Exit | high | source | slowMASEx |
| Source for Long Exit | low | source | slowMALEx |
| Exit Tuner to touch slowEMA | 0.005 | float | bull_exit bear_exit |
| Run Strategy | false | bool | entry LO entry LO close LO entry SO entry SO close SO line 80 |
| From Month | 1 | int (written input.integer) · min 1 · max 12 | start |
| From Day | 1 | int (written input.integer) · min 1 · max 31 | start |
| From Year | 2020 | int (written input.integer) · min 2000 | start |
| Thru Month | 1 | int (written input.integer) · min 1 · max 12 | finish |
| Thru Day | 1 | int (written input.integer) · min 1 · max 31 | finish |
| Thru Year | 2100 | int (written input.integer) · min 2000 | finish |
| Show Date Range | true | bool | unused |
What it calculates
- EMA (
ema,ta.emain v5)Source for Fast (close), FAST EMA (3)fastMA · line 8 - EMA (
ema,ta.emain v5)Source for Slow (close), SLOW EMA (15)slowMA · line 12 - EMA (
ema,ta.emain v5)Source for Fast Exit (close), FAST EMA Exit (3)fastMAE · line 16 - EMA (
ema,ta.emain v5)Source for Short Entry (low), SLOW EMA (15)slowMASEn · line 19 - EMA (
ema,ta.emain v5)Source for Long Entry (high), SLOW EMA (15)slowMALEn · line 21 - EMA (
ema,ta.emain v5)Source for Short Exit (high), SLOW EMA (15)slowMASEx · line 23 - EMA (
ema,ta.emain v5)Source for Long Exit (low), SLOW EMA (15)slowMALEx · line 25 - Crossover (
crossover,ta.crossoverin v5)fastMA, slowMALEnenter_long · line 26 - Crossunder (
crossunder,ta.crossunderin v5)fastMA, slowMASEnenter_short · line 27 - Crossunder (
crossunder,ta.crossunderin v5)fastMAE, slowMALExexit_long · line 28 - Crossover (
crossover,ta.crossoverin v5)fastMAE, slowMASExexit_short · line 29
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 LO long | (window() and enter_long and not(bull_exit)) | On | 81 |
| Open LO long | (window() and bull_reenter) | On | 82 |
| Close LO | (window() and bull_exit) | On | 83 |
| Open SO short | (window() and enter_short and not(bear_exit)) | On | 84 |
| Open SO short | (window() and bear_reenter) | On | 85 |
| Close SO | (window() and bear_exit) | On | 86 |
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 |
|---|---|---|---|---|---|
| Tale Indicators 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 32 ms | Yes 1,000 bars in 116 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © ehaarjee, ECHKAY, JackBauer007//@version=4//study(title="Tale_indicators", overlay=true)strategy("Tale Indicators Strategy", overlay=true, precision=8, max_bars_back=200, pyramiding=0, initial_capital=20000, commission_type="percent", commission_value=0.1)len_fast = input(3, minval=1, title="FAST EMA")src_fast = input(close, title="Source for Fast")fastMA = ema(src_fast, len_fast)plot(fastMA, title="Slow EMA", color=color.orange)len_slow = input(15, minval=1, title="SLOW EMA")src_slow = input(close, title="Source for Slow")slowMA = ema(src_slow, len_slow)plot(slowMA, title="Fast EMA", color=color.blue)len_fast_exit = input(3, minval=1, title="FAST EMA Exit")src_fast_exit = input(close, title="Source for Fast Exit")fastMAE = ema(src_fast_exit, len_fast_exit)plot(fastMAE, title="Fast EMA Ex", color=color.red)src_slow_enter_short = input(low, title="Source for Short Entry")slowMASEn = ema(src_slow_enter_short, len_slow)src_slow_enter_long = input(high, title="Source for Long Entry")slowMALEn = ema(src_slow_enter_long, len_slow)src_slow_exit_short = input(high, title="Source for Short Exit")slowMASEx = ema(src_slow_exit_short, len_slow)src_slow_exit_long = input(low, title="Source for Long Exit")slowMALEx = ema(src_slow_exit_long, len_slow)enter_long = crossover(fastMA, slowMALEn)enter_short = crossunder(fastMA, slowMASEn)exit_long = crossunder(fastMAE, slowMALEx)exit_short = crossover(fastMAE, slowMASEx)out_enter = iff(enter_long == true, 1, iff(enter_short == true, -1, 0))plotarrow(out_enter, "Plot Enter Points", colorup=color.green, colordown=color.red, maxheight = 30)bull = fastMA > slowMALEnbear = fastMA < slowMASEnc = bull ? color.green : bear ? color.red : color.whitebgcolor(c)exit_tuner = input(0.005, title="Exit Tuner to touch slowEMA")bull_exit = (low>(fastMAE*(1+exit_tuner))) or exit_long bear_exit = ((fastMAE*(1-exit_tuner))>high) or exit_short bull_r = (bull and ((bull_exit[1]) or (bull_exit[2] and bull_exit[1])) and (low<=fastMAE))bear_r = (bear and ((bear_exit[1]) or (bull_exit[2] and bull_exit[1])) and (fastMAE<=high))bull_re = (bull and (low<slowMALEn)) and not(enter_long)bear_re = (bear and (high>slowMASEn)) and not(enter_short)bull_ree = (bull and ((low<slowMALEn) and not(bull_re[1] or enter_long[1]))) bear_ree = (bear and ((high>slowMASEn) and not(bear_re[1] or enter_short[1])))bull_reenter = (bull_r or bull_ree) and not(enter_long)bear_reenter = (bear_r or bear_ree) and not(enter_short)plotshape(bull_exit, "Plot Bull Exit", style = shape.arrowdown, color=color.green, size=size.small, text="ExL", location=location.abovebar)plotshape(bear_exit, "Plot Bear Exit", style = shape.arrowup, color=color.red, size=size.small, text="ExS", location=location.belowbar)plotshape(bull_reenter, "Plot Bull ReEnter", style = shape.arrowup, color=color.green, size=size.small, text="ReL", location=location.belowbar)plotshape(bear_reenter, "Plot Bear ReEnter", style = shape.arrowdown, color=color.red, size=size.small, text="ReS", location=location.abovebar)run_strategy = input(false, title="Run Strategy")// === INPUT BACKTEST RANGE ===fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 2000)thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)thruYear = input(defval = 2100, title = "Thru Year", type = input.integer, minval = 2000)// === INPUT SHOW PLOT ===showDate = input(defval = true, title = "Show Date Range", type = input.bool)// === FUNCTION EXAMPLE ===start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start windowfinish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish windowwindow() => time >= start and time <= finish ? true : false // create function "within window of time"var long_position_open = falsevar short_position_open = falseif (enter_long and not(bull_exit) and not(long_position_open)) long_position_open := trueif (bull_reenter and not(long_position_open)) long_position_open := trueif (bull_exit and long_position_open) long_position_open := false if (enter_short and not(bear_exit) and not(short_position_open)) short_position_open := trueif (bear_reenter and not(short_position_open)) short_position_open := trueif (bear_exit and short_position_open) short_position_open := falseif(run_strategy) strategy.entry("LO", strategy.long, when=(window() and enter_long and not(bull_exit)), qty=4) strategy.entry("LO", strategy.long, when=(window() and bull_reenter), qty=1) strategy.close("LO", when=(window() and bull_exit)) strategy.entry("SO", strategy.short, when=(window() and enter_short and not(bear_exit)), qty=4) strategy.entry("SO", strategy.short, when=(window() and bear_reenter), qty=1) strategy.close("SO", when=(window() and bear_exit))