Pine Script v5 · Strategy
3 Candle Strike Stretegy
A Pine Script v5 strategy built on RMA (ta.tr, 14), EMA (src, 8) and SMA (src, 21). It has 9 order rules, 4 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. 31 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 3 Candle Strike Stretegy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
- How did 3 Candle Strike Stretegy 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.
- What alerts does 3 Candle Strike Stretegy have?
- 2
- 3s Bull; 3s Bear.
- Does 3 Candle Strike Stretegy 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.
- Does 3 Candle Strike Stretegy use a stop loss?
- Yes
- strategy.exit sets a stop on line 182, 183, 185, 186.
BTCUSDT · 1D · default settings
- Daily ATR
- Daily % ATR
- 3 Line Strike Up
- 3 Line Strike Down
- Short SL
- Long SL
- Long PT
- Short PT
- 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, $5,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
6 settings have no label
In the settings dialog t1_session (line 16), show_ema1 (line 44), show_smma1 (line 47), show_smma2 (line 52), show_smma3 (line 57), t2_session (line 148) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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)Entry Signal only generated within this period. | 0930-1554:23456 | session | t1 |
| Trading Options | |||
| Margin Requirement / Leverage | 10 | float · step 0.1 | trade_amount |
| % of initial capital per trade | 100 | float | trade_amount |
| Reinvest profit | false | bool | line 26 |
| Reinvest percentage | 20 | float | trade_amount |
| Reward to Risk Ratio | 3.0 | float · min 0.1 · step 0.1 | long_PT short_PT |
| Switch to trailing SL after TP hitSet SL to previous low after TP hit | true | bool | exit Exit exit Exit line 123 line 181 |
| No entry between: | true | bool | line 154 |
| T2 session (no label in the script)To avoid high volatility | 1000-1030 | session | t2 |
| Trade 3s candle patternCan use alert() function calls for all 3 Candle strike signals | true | bool | L_entry1 S_entry1 |
| Trade MA Cross Reversal Signal | true | bool | L_entry2 S_entry2 |
| Daily ATR | |||
| ATR period | 14 | int · min 1 | datr |
| % ATR to use for SL / PT | 5 | float · min 1 · max 100 · step 0.1 | percentage |
| Moving Averages | |||
| Show ema1 (no label in the script) | false | bool | Fast EMA |
| Fast EMA | 8 | int · min 1 | ema1 |
| Show smma1 (no label in the script) | false | bool | Fast SMMA |
| Fast SMMA | 21 | int · min 1 | smma1 sma_1 |
| Show smma2 (no label in the script) | false | bool | Medium SMMA |
| Medium SMMA | 50 | int · min 1 | smma2 sma_2 |
| Show smma3 (no label in the script) | false | bool | Fast SMMA |
| Slow SMMA | 200 | int · min 1 | smma3 sma_3 |
| Linear Regression | |||
| Linear Regression Period | 50 | int · min 1 | lrc |
| LR Slope Period | 50 | int · min 1 | slrs |
| LR Signal Period | 14 | int · min 1 | alrs |
| LR Threshold for Ranging vs Trending | 0.03 | float · min 0 · step 0.001 | LR_ranging LR_trending |
What it calculates
- RMAta.tr, ATR period (14)
datr · line 38 - EMAsrc, Fast EMA (8)
ema1 · line 46 - SMAsrc, Fast SMMA (21)
sma_1 · line 50 - SMAsrc, Medium SMMA (50)
sma_2 · line 55 - SMAsrc, Slow SMMA (200)
sma_3 · line 60 - Linregsrc, Linear Regression Period (50), 0
lrc · line 78 - EMAlrs, LR Slope Period (50)
slrs · line 82 - SMAslrs, LR Signal Period (14)
alrs · line 84
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 94 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 | On | 173 |
| Open Long long | L_entry2 | On | 175 |
| Open Short short | S_entry1 | On | 178 |
| Open Short short | S_entry2 | On | 180 |
| Exit Exit stop | trade_trailing | On “Switch to trailing SL after TP hit” | 182 |
| Exit Exit stop | trade_trailing | On “Switch to trailing SL after TP hit” | 183 |
| Exit Exit stop and limit | barsSinceLastEntry() > 0 | On | 185 |
| Exit Exit stop and limit | barsSinceLastEntry() > 0 | On | 186 |
| Close | strategy.opentrades > 0 and not t1 | On | 188 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | 3s Bull | 99 |
| (no title) | alert | 3s Bear | 101 |
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 | 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 |
|---|---|---|---|---|---|
| 3 Candle Strike Stretegy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Top 40 High Low Strategy for SPY, 5min by PtGambler | rma sma cross linreg ema | v5 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| Linear Regression MA - Strategy by lazy_capitalist | sma linreg ema | v5 strategy | −1,240.4% | 10 | 318.7% |
| Double EMA CROSS by EmreErturk_ | ema cross sma | v4 strategy | +5.1% | 9 | 34.5% |
| Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGambler | ema sma rma | v5 strategy | No trades on this market | ||
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.
- 2 settings use the untyped input() (line 8, 11). 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.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 8: input() → input.int()
- Line 11: input() → input.int()
⋯// ******************** 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")⋯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.
⋯// *****************************************************************************************************************************************************************************************************-//@version=5+//@version=6strategy("3 Candle Strike Strategy", overlay=true, pyramiding=1, initial_capital=5000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 111 ms | With a workaround 1,000 bars in 173 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/// © platsn//// *****************************************************************************************************************************************************************************************************//@version=5strategy("3 Candle Strike Strategy", overlay=true, pyramiding=1, initial_capital=5000)// ******************** 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("0930-1554:23456", "Entry Session", group="Sessions", tooltip = "Entry Signal only generated within this period.") t1 = time(timeframe.period, t1_session)window = time >= timestart and time <= timefinish and t1 ? true : false src = closemargin_req = input.float(10, title="Margin Requirement / Leverage", step=0.1, group = "Trading Options")qty_per_trade = input.float(100, title = "% of initial capital per trade", group = "Trading Options")reinvest = input.bool(defval=false,title="Reinvest profit", group = "Trading Options")reinvest_percent = input.float(defval=20, title = "Reinvest percentage", group="Trading Options")profit = strategy.netprofit trade_amount = math.floor(strategy.initial_capital*margin_req / close) if strategy.netprofit > 0 and reinvest trade_amount := math.floor((strategy.initial_capital* (qty_per_trade/100)+(profit*reinvest_percent*0.01))*margin_req/ close) else trade_amount := math.floor(strategy.initial_capital* (qty_per_trade/100)*margin_req / close) trade_amount := math.min(trade_amount, 1000)// ***************************************************************************************************** Daily ATR *****************************************************// Inputsatrlen = input.int(14, minval=1, title="ATR period", group = "Daily ATR")iPercent = input.float(5, minval=1, maxval=100, step=0.1, title="% ATR to use for SL / PT", group = "Daily ATR")// PTPercent = input.int(100, minval=1, title="% ATR for PT")// Logicpercentage = iPercent * 0.01datr = request.security(syminfo.tickerid, "1D", ta.rma(ta.tr, atrlen))datrp = datr * percentage// datrPT = datr * PTPercent * 0.01plot(datr,"Daily ATR")plot(datrp, "Daily % ATR")// ***************************************************************************************************************** Moving Averages ************************show_ema1 = input.bool(false, "", group = "Moving Averages", inline = "ema1")len0 = input.int(8, minval=1, title='Fast EMA', group= "Moving Averages", inline = "ema1")ema1 = ta.ema(src, len0)show_smma1 = input.bool(false, "", group = "Moving Averages", inline = "smma1")len1 = input.int(21, minval=1, title='Fast SMMA', group= "Moving Averages", inline = "smma1")smma1 = 0.0sma_1 = ta.sma(src, len1)smma1 := na(smma1[1]) ? sma_1 : (smma1[1] * (len1 - 1) + src) / len1show_smma2 = input.bool(false, "", group = "Moving Averages", inline = "smma2")len2 = input.int(50, minval=1, title='Medium SMMA', group= "Moving Averages", inline = "smma2")smma2 = 0.0sma_2 = ta.sma(src, len2)smma2 := na(smma2[1]) ? sma_2 : (smma2[1] * (len2 - 1) + src) / len2show_smma3 = input.bool(false, "", group = "Moving Averages", inline = "smma3")len3 = input.int(200, minval=1, title='Slow SMMA', group= "Moving Averages", inline = "smma3")smma3 = 0.0sma_3 = ta.sma(src, len3)smma3 := na(smma3[1]) ? sma_3 : (smma3[1] * (len3 - 1) + src) / len3ma_bull = smma1 > smma2 and smma1 > smma1[1]ma_bear = smma1 < smma2 and smma1 < smma1[1]ma_bull_macro = smma1 > smma3 and smma2 > smma3ma_bear_macro = smma1 < smma3 and smma2 < smma3plot(show_ema1 ? ema1 : na, 'Fast EMA', color.white, linewidth = 2)plot(show_smma1 ? smma1 : na, 'Fast SMMA', color.yellow, linewidth = 2)plot(show_smma2 ? smma2 : na, 'Medium SMMA', color.orange, linewidth = 2)plot(show_smma3 ? smma3 : na, 'Fast SMMA', color.red, linewidth = 2)// **************************************************************************************************************** Linear Regression *************************//Inputclen = input.int(defval = 50, minval = 1, title = "Linear Regression Period", group = "Linear Regression")slen = input.int(defval=50, minval=1, title="LR Slope Period" , group = "Linear Regression")glen = input.int(defval=14, minval=1, title="LR Signal Period", group = "Linear Regression")LR_thres = input.float(0.03, minval=0, step=0.001, title="LR Threshold for Ranging vs Trending" , group = "Linear Regression") //Linear Regression Curvelrc = ta.linreg(src, clen, 0)//Linear Regression Slopelrs = (lrc-lrc[1])/1//Smooth Linear Regression Slopeslrs = ta.ema(lrs, slen)//Signal Linear Regression Slopealrs = ta.sma(slrs, glen)up_accel = lrs > alrs and lrs > 0 down_accel = lrs < alrs and lrs < 0 LR_ranging = math.abs(slrs) <= LR_thresLR_trending = math.abs(slrs) > LR_thres// plot(slrs, "LR slope")// plot(LR_trending?1:0, "LR Trending")barcolor(LR_ranging? color.gray : na, title = "Ranging")// *********************************************************************************************************************************** Candle conditions **************************bull_3s = close[3] <= open[3] and close[2] <= open[2] and close[1] <= open[1] and close > open[1]bear_3s = close[3] >= open[3] and close[2] >= open[2] and close[1] >= open[1] and close < open[1]plotshape(bull_3s, style=shape.triangleup, color=color.new(color.green, 0), location=location.belowbar, size=size.small, text='3s-Bull', title='3 Line Strike Up')plotshape(bear_3s, style=shape.triangledown, color=color.new(color.red, 0), location=location.abovebar, size=size.small, text='3s-Bear', title='3 Line Strike Down')if barstate.isconfirmed if bull_3s alert(message = "3s Bull") if bear_3s alert(message = "3s Bear")// ***************************************************************************************************************************************** SL & PT ***********************************RR = input.float(3.0, minval = 0.1, step = 0.1, title="Reward to Risk Ratio", group = "Trading Options")trade_trailing = input.bool(true, "Switch to trailing SL after TP hit", group = "Trading Options", tooltip = "Set SL to previous low after TP hit")barsSinceLastEntry()=> strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : na// plot(barsSinceLastEntry(),"BSLE")last_high = math.max(high, high[1], high[2], high[3])last_low = math.min(low, low[1], low[2], low[3])long_SL = last_low - datrpshort_SL = last_high + datrplong_PT = last_highshort_PT = last_lowlast_entry = strategy.opentrades.entry_price(strategy.opentrades-1)risk = last_entry - long_SLif strategy.opentrades > 0 long_SL := math.min(long_SL[barsSinceLastEntry()], last_low) short_SL := math.max(short_SL[barsSinceLastEntry()], last_high) risk := last_entry - long_SL long_PT := last_entry + (last_entry - long_SL) * RR short_PT := last_entry - (short_SL - last_entry) * RRvar PT_hit = falseif trade_trailing if high > long_PT long_SL := low PT_hit := true if low < short_PT short_SL := high PT_hit := true if PT_hit long_SL := math.max(low[1], long_SL[1]) short_SL := math.min(high[1], short_SL[1])PT_hit := strategy.opentrades == 0 ? false : PT_hitSSL = plot(short_SL,title = "Short SL", color= strategy.opentrades.size(0) < 0 and barsSinceLastEntry() > 0 ? color.red: na, linewidth = 3, style = plot.style_linebr)LSL = plot(long_SL,title = "Long SL", color= strategy.opentrades.size(0) > 0 and barsSinceLastEntry() > 0 ? color.red: na, linewidth = 3, style = plot.style_linebr)LPT = plot(long_PT,title = "Long PT", color= strategy.opentrades.size(0) > 0 and barsSinceLastEntry() > 0 ? color.green: na, linewidth = 3, style = plot.style_linebr)SPT = plot(short_PT,title = "Short PT", color= strategy.opentrades.size(0) < 0 and barsSinceLastEntry() > 0 ? color.green: na, linewidth = 3, style = plot.style_linebr)LE = plot(last_entry, title = "Last entry", color = strategy.opentrades > 0 ? color.gray : na, style = plot.style_linebr)plot(risk, title = "Risk")fill(LPT, LE, color = strategy.opentrades.size(0) > 0 ? color.new(color.green,90) : na)fill(LE, LSL, color = strategy.opentrades.size(0) > 0 ? color.new(color.red,90): na)fill(SPT, LE, color = strategy.opentrades.size(0) < 0 ? color.new(color.green,90) : na)fill(LE, SSL, color = strategy.opentrades.size(0) < 0 ? color.new(color.red,90) : na)// **************************************************************************************************************************************** Trade Pauses ****************************************bool trade_pause = falsebool trade_pause2 = falseno_entry = input.bool(true, title="No entry between:", group = "Trading Options", inline = 'no_entry')t2_session = input.session("1000-1030",'', group = "Trading Options", inline = 'no_entry', tooltip = "To avoid high volatility")t2 = time(timeframe.period, t2_session)if high - low > datr*0.3 trade_pause := trueelse trade_pause := falseif no_entry and t2 trade_pause2 := trueelse trade_pause2 := false // ************************************************************************************************************************************ Entry conditions **************************trade_3s = input.bool(title='Trade 3s candle pattern', defval=true, group = "Trading Options", tooltip = "Can use alert() function calls for all 3 Candle strike signals")L_entry1 = trade_3s and bull_3s and ma_bull and LR_trendingS_entry1 = trade_3s and bear_3s and ma_bear and LR_trendingtrade_ma_reversal = input.bool(title='Trade MA Cross Reversal Signal', defval=true, group = "Trading Options")L_entry2 = trade_ma_reversal and ma_bear_macro and ema1 > smma1 and bull_3s and ta.barssince(ta.cross(ema1,smma1)) < 10S_entry2 = trade_ma_reversal and ma_bull_macro and ema1 < smma1 and bear_3s and ta.barssince(ta.cross(ema1,smma1)) < 10// ************************************************************************************************************************************** Exit Conditions ******************************** L_exit1 = bear_3sS_exit1 = bull_3s// ************************************************************************************************************************************ Entry and Exit orders *****************************if not trade_pause and not trade_pause2 and window if L_entry1 strategy.entry("Long", strategy.long, trade_amount, comment="Long 3s") if L_entry2 strategy.entry("Long", strategy.long, trade_amount, comment="Long MA cross") if S_entry1 strategy.entry("Short", strategy.short, trade_amount, comment = "Short 3s") if S_entry2 strategy.entry("Short", strategy.short, trade_amount, comment = "Short MA corss")if trade_trailing strategy.exit("Exit", "Long", stop= long_SL, comment = "Exit Long SL hit") strategy.exit("Exit", "Short", stop= short_SL, comment = "Exit Short SL hit")else if barsSinceLastEntry() > 0 strategy.exit("Exit", "Long",limit = long_PT, stop= long_SL, comment_profit = "Exit Long PT hit", comment_loss = "Exit Long SL hit") strategy.exit("Exit", "Short",limit = short_PT, stop= short_SL, comment_profit = "Exit Short PT hit", comment_loss = "Exit Short SL hit")if strategy.opentrades > 0 and not t1 strategy.close_all(comment = 'End of day')// ************************************************************************************************************************************ Alerts *****************************