Pine Script v5 · Strategy
[Pt] Premarket Breakout Strategy
A Pine Script v5 strategy built on RMA (ta.tr, 14), RSI (close, 14) and SMA or Stoch (3). It has 7 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 25 settings; defaults include Start Year 2011, Start Month 1 and Start Day 1.
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 [Pt] Premarket Breakout 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 [Pt] Premarket Breakout 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. On ETHUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Does [Pt] Premarket Breakout Strategy 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: 1 before, 0 after on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does [Pt] Premarket Breakout Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 125, 129.
- Does [Pt] Premarket Breakout Strategy run in Zeal Terminal?
- Yes
- It compiles in 50 ms and runs 1,000 bars in 138 ms, in the browser.
BTCUSDT · 1D · default settings
- Trade direction
- 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, $4,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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog t1_session (line 14), pm_session (line 40) show an empty name. The labels on this page come from the variable names.
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 |
|---|---|---|---|
| Trading window | |||
| Start Year | 2011 | int | timestart |
| Start Month | 1 | int · min 1 · max 12 | timestart |
| Start Day | 1 | int · min 1 · max 31 | timestart |
| Finish Year | 2050 | int | timefinish |
| Finish Month | 12 | int · min 1 · max 12 | timefinish |
| Finish Day | 31 | int · min 1 · max 31 | timefinish |
| Sessions | |||
| T1 session (no label in the script) | 0945-1545 | session | t1 |
| Pm session (no label in the script) | 0900-0930 | session | pm_t |
| Trading Options | |||
| Margin Requirement / Leverage | 11 | float · step 0.1 | trade_amount |
| Reinvest profit | false | bool | line 27 |
| Reinvest percentage | 100 | float | trade_amount |
| Reward to Risk Ratio | 2.0 | float · step 0.1 | L_PT S_PT |
| Daily ATR | |||
| ATR period | 14 | int · min 1 | datr atr |
| % ATR to use for SL / PT | 1.6 | float · min 0.01 · max 100 · step 0.2 | percentage |
| Stochastic RSI | |||
| K | 3 | int · min 1 | k |
| D | 3 | int · min 1 | d |
| RSI LengthFor 1 min time frame, use default 14." + "\nFor 5 min time frame, use 3. | 14 | int · min 1 | rsi1 |
| Stochastic LengthFor 1 min time frame, use default 14." + "\nFor 5 min time frame, use 3. | 14 | int · min 1 | k |
| RSI Source | close | source | rsi1 up down |
| RSI Settings | |||
| RSI Length | 14 | int · min 1 | up down |
| Smooth period | 3 | int | rsiSM |
| MA Type | SMA | string · options ["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"] | rsiMA |
| MA Length | 100 | int | rsiMA |
| Entry parameters | |||
| Stochastic K must be above before entry | 82 | int | S_entry1 |
| Stochastic K must be above before entry | 18 | int | L_entry1 |
What it calculates
- RMAta.tr, ATR period (14)
datr · line 36 - RMAta.tr, ATR period (14)
atr · line 38 - RSIRSI Source (close), RSI Length (14)
rsi1 · line 56 - SMA / Stochta.stoch(rsi1, rsi1, rsi1, lengthStoch), K (3)
k · line 57 - SMAk, D (3)
d · line 58 - RMA / Changemath.max(ta.change(src), 0), RSI Length (14)
up · line 72 - RMA / Change-math.min(ta.change(src), 0), RSI Length (14)
down · line 73 - SMArsi, Smooth period (3)
rsiSM · line 75
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.
The script has 80 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | L_entry1 and window | On | 98 |
| Open Short short | S_entry1 and window | On | 101 |
| Exit Exit stop and limit | strategy.opentrades.size(0) > 0 | On | 125 |
| Close Long | L_exit1 | On | 127 |
| Exit Exit stop and limit | strategy.opentrades.size(0) < 0 | On | 129 |
| Close Short | S_exit1 | On | 131 |
| Close | time(timeframe.period, "1555-1600:23456") or time(timeframe.period, "0755-0800:23456") | On | 133 |
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 data1 request.security call(s), none with lookahead on.
- 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 | −4.2% | +8.4% | 1 | 0% | 0.00 | 14.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +2.2% | +21.5% | 1 | 100% | — | 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 | +1.6% | +17.1% | 1 | 100% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (K 2, D 2) made 0.0% before 26 Dec 2025 and 0.0% after it, against 0.0% for the defaults. 0% of the 16 combinations made money in-sample and 0% out-of-sample.
| D ↓ · K → | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
| 2 | 0% | 0% | 0% | 0% |
| 3 | 0% | 0% | 0% | 0% |
| 4 | 0% | 0% | 0% | 0% |
| 5 | 0% | 0% | 0% | 0% |
| D ↓ · K → | 2 | 3 | 4 | 5 |
|---|---|---|---|---|
| 2 | 0% | 0% | 0% | 0% |
| 3 | 0% | 0% | 0% | 0% |
| 4 | 0% | 0% | 0% | 0% |
| 5 | 0% | 0% | 0% | 0% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| [Pt] Premarket Breakout Strategy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Stoch-RSI 4h-1h-15min by MoonFlag | rsi sma rma stoch | v4 strategy | No trades on this market | ||
| Crypto rsi cci mf stoch rsi oscillators all in one strategy by SoftKill21 | rma sma rsi | v4 strategy | +1.6% | 3 | 26.8% |
| Forex Scalping 1min Bollinger Bands, RSI and ADX Trading System by exlux99 | rsi sma rma | v4 strategy | −0.0% | 3 | 0.0% |
| CCI Level Zone by Naruephat | sma rsi stoch | v5 strategy | No trades on this market | ||
| AVWAP Strategy by asfbhero | rsi stoch sma | v5 strategy | does not run in Zeal Terminal | ||
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 3 settings use the untyped input() (line 6, 9, 55). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 1 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 9: input() → input.int()
- Line 55: input() → input.source()
⋯// ******************** Trade Period **************************************-startY = input(title='Start Year', defval=2011, group = "Trading window")+startY = input.int(title='Start Year', defval=2011, group = "Trading window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")-finishY = input(title='Finish Year', defval=2050, group = "Trading window")+finishY = input.int(title='Finish Year', defval=2050, group = "Trading window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")⋯lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "Stochastic RSI", tooltip = TT_stochLen)-src = input(close, title="RSI Source")+src = input.source(close, title="RSI Source")rsi1 = ta.rsi(src, lengthRSI)⋯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: 1 before, 0 after on ETHUSDT 4h, 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.
⋯// © PtGambler-//@version=5+//@version=6strategy("[Pt] Premarket Breakout Strategy", shorttitle="PM Break Strategy", overlay=true, pyramiding=1, initial_capital=4000, commission_type=strategy.commission.cash_per_contract, slippage = 3) ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 50 ms | With a workaround 1,000 bars in 138 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © PtGambler//@version=5strategy("[Pt] Premarket Breakout Strategy", shorttitle="PM Break Strategy", overlay=true, pyramiding=1, initial_capital=4000, commission_type=strategy.commission.cash_per_contract, slippage = 3) // ******************** Trade Period **************************************startY = input(title='Start Year', defval=2011, group = "Trading window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")finishY = input(title='Finish Year', defval=2050, group = "Trading window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")finishD = input.int(title='Finish Day', defval=31, minval=1, maxval=31, group = "Trading window")timestart = timestamp(startY, startM, startD, 00, 00)timefinish = timestamp(finishY, finishM, finishD, 23, 59)t1_session = input.session("0945-1545", "Entry Session", group="Sessions") t1 = time(timeframe.period, t1_session)window = time >= timestart and time <= timefinish and t1 ? true : false margin_req = input.float(11, title="Margin Requirement / Leverage", step=0.1, group = "Trading Options")reinvest = input.bool(defval=false,title="Reinvest profit", group = "Trading Options")reinvest_percent = input.float(defval=100, title = "Reinvest percentage", group="Trading Options")//-------------------------------------------------------------------------------------profit = strategy.netprofittrade_amount = math.floor(strategy.initial_capital*margin_req / close) BSLE() => strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : naBSLEx() => strategy.opentrades == 0 ? (bar_index - strategy.closedtrades.exit_bar_index(strategy.closedtrades-1)) : naif strategy.netprofit > 0 and reinvest trade_amount := math.floor((strategy.initial_capital+(profit*reinvest_percent*0.01))*margin_req/ close) else trade_amount := math.floor(strategy.initial_capital*margin_req / close) // ***************************************************************************************************** Daily ATR *****************************************************atrlen = input.int(14, minval=1, title="ATR period", group = "Daily ATR")iPercent = input.float(1.6, minval=0.01, maxval=100, step=0.2, title="% ATR to use for SL / PT", group = "Daily ATR") percentage = iPercent * 0.01datr = request.security(syminfo.tickerid, "1D", ta.rma(ta.tr, atrlen))datrp = datr * percentageatr = ta.rma(ta.tr, atrlen)// --------------------------------------------- Pre-market Session HL ------------------------------------====pm_session = input.session("0900-0930", "Pre-Market Session", group="Sessions") pm_t = time(timeframe.period, pm_session)var pm_h = 0.0var pm_l = 9999.9if pm_t pm_h := high > pm_h ? high : pm_h pm_l := low < pm_l ? low : pm_lpm_range = pm_h - pm_lbgcolor(pm_t?color.new(color.white,95):na)// ------------------------------------------------ Stochastic RSI --------------------------------------------------------string TT_stochLen = "For 1 min time frame, use default 14." + "\nFor 5 min time frame, use 3."smoothK = input.int(3, "K", minval=1, group = "Stochastic RSI")smoothD = input.int(3, "D", minval=1, group = "Stochastic RSI")lengthRSI = input.int(14, "RSI Length", minval=1, group = "Stochastic RSI", tooltip = TT_stochLen)lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "Stochastic RSI", tooltip = TT_stochLen)src = input(close, title="RSI Source")rsi1 = ta.rsi(src, lengthRSI)k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)d = ta.sma(k, smoothD)// -------------------------------------------------------- RSI MA Cross -----------------------------------------------------ma(source, length, type) => switch type "SMA" => ta.sma(source, length) "Bollinger Bands" => ta.sma(source, length) "EMA" => ta.ema(source, length) "SMMA (RMA)" => ta.rma(source, length) "WMA" => ta.wma(source, length) "VWMA" => ta.vwma(source, length)len = input.int(14, minval=1, title="RSI Length", group="RSI Settings")len2 = input.int(3, title="Smooth period", group="RSI Settings")maType = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI Settings")malen = input.int(100, title="MA Length", group="RSI Settings")up = ta.rma(math.max(ta.change(src), 0), len)down = ta.rma(-math.min(ta.change(src), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))rsiSM = ta.sma(rsi,len2)rsiMA = ma(rsi, malen, maType)rsi_bull = rsiSM > rsiMA and rsi > 50 and rsi > rsiSMrsi_bear = rsiSM < rsiMA and rsi < 50 and rsi < rsiSM// --------------------------------------------- Define Trend - PM HL breakout -------------------------------------------------------------------var trend = 0// reset trend at PMif pm_t trend := 0else trend := trend == 0 ? (close > pm_h ? 1 : close < pm_l ? -1 : 0) : trend plot(trend,"Trade direction")//---------------------------------------------------------------------------------------------------------------stoch_h_limit = input.int(82, "Stochastic K must be above before entry", group="Entry parameters")stoch_l_limit = input.int(18, "Stochastic K must be above before entry", group="Entry parameters")plot(time(timeframe.period, "0930-1600:23456") or pm_t? pm_h : high, title="PM High", color= time(timeframe.period, "0930-1600:23456") or pm_t? color.blue : color.new(color.black,100), linewidth=2, trackprice = true)plot(time(timeframe.period, "0930-1600:23456") or pm_t? pm_l : low, title="PM Low", color= time(timeframe.period, "0930-1600:23456") or pm_t? color.orange : color.new(color.black,100), linewidth=2, trackprice = true)// ------------------------------------------------------------ Entry --------------------------------------------var traded = falseL_entry1 = trend == 1 and traded == false and d[1] < stoch_l_limit and ta.crossover(k,d)S_entry1 = trend == -1 and traded == false and d[1] > stoch_h_limit and ta.crossunder(k,d)if L_entry1 and window strategy.entry("Long", strategy.long,trade_amount) traded := trueif S_entry1 and window strategy.entry("Short", strategy.short,trade_amount) traded := true// ------------------------------------------------------------- SL & PT -------------------------------------------RRR = input.float(2.0, "Reward to Risk Ratio", step=0.1, group="Trading Options")entry_price = strategy.opentrades.entry_price(0)L_SL = entry_price > pm_h ? pm_l - datrp : entry_price - pm_range - datrpS_SL = entry_price < pm_l ? pm_h + datrp : entry_price + pm_range + datrpL_risk = entry_price - L_SLS_risk = S_SL - entry_priceL_PT = entry_price + L_risk * RRRS_PT = entry_price - S_risk * RRRp0 = plot(strategy.opentrades.size(0) == 0 ? close : entry_price, "Entry Price", color= strategy.opentrades.size(0) == 0 ? na : color.gray, linewidth=1)p1 = plot(strategy.opentrades.size(0) > 0? L_SL : low, "Long SL", color= (t1 or pm_t) and strategy.opentrades.size(0) > 0 and BSLE() > 0? color.red : color.new(color.black,100), linewidth=3)p2 = plot(strategy.opentrades.size(0) > 0? L_PT : high, "Long PT", color= (t1 or pm_t) and strategy.opentrades.size(0) > 0 and BSLE() > 0? color.green : color.new(color.black,100), linewidth=3)p3 = plot(strategy.opentrades.size(0) < 0? S_SL : high, "Long SL", color= (t1 or pm_t) and strategy.opentrades.size(0) < 0 and BSLE() > 0? color.red : color.new(color.black,100), linewidth=3)p4 = plot(strategy.opentrades.size(0) < 0? S_PT : low, "Long PT", color= (t1 or pm_t) and strategy.opentrades.size(0) < 0 and BSLE() > 0? color.green : color.new(color.black,100), linewidth=3)fill(p1, p0, color.new(color.red,95))fill(p2, p0, color.new(color.green,95))fill(p3, p0, color.new(color.red,95))fill(p4, p0, color.new(color.green,95))// ------------------------------------------ Exit ----------------------------------------------------------L_exit1 = d > 80 and strategy.opentrades.profit(0) <=0 and rsi_bearS_exit1 = d < 20 and strategy.opentrades.profit(0) <=0 and rsi_bullif strategy.opentrades.size(0) > 0 strategy.exit("Exit", "Long", limit=L_PT, stop=L_SL) if L_exit1 strategy.close("Long", comment="Exit Early")if strategy.opentrades.size(0) < 0 strategy.exit("Exit", "Short", limit=S_PT, stop=S_SL) if S_exit1 strategy.close("Short", comment="Exit Early") if time(timeframe.period, "1555-1600:23456") or time(timeframe.period, "0755-0800:23456") strategy.close_all() traded := false pm_h := 0.0 pm_l := 9999.9