Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (31)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$5,000$10,126Equity from $5,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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.

SettingDefaultType and rangeFeeds
Trading window
Start Year2011inttimestart
Start Month1int · min 1 · max 12timestart
Start Day1int · min 1 · max 31timestart
Finish Year2050inttimefinish
Finish Month12int · min 1 · max 12timefinish
Finish Day31int · min 1 · max 31timefinish
Sessions
T1 session (no label in the script)Entry Signal only generated within this period.0930-1554:23456sessiont1
Trading Options
Margin Requirement / Leverage10float · step 0.1trade_amount
% of initial capital per trade100floattrade_amount
Reinvest profitfalseboolline 26
Reinvest percentage20floattrade_amount
Reward to Risk Ratio3.0float · min 0.1 · step 0.1long_PT short_PT
Switch to trailing SL after TP hitSet SL to previous low after TP hittrueboolexit Exit exit Exit line 123 line 181
No entry between:trueboolline 154
T2 session (no label in the script)To avoid high volatility1000-1030sessiont2
Trade 3s candle patternCan use alert() function calls for all 3 Candle strike signalstrueboolL_entry1 S_entry1
Trade MA Cross Reversal SignaltrueboolL_entry2 S_entry2
Daily ATR
ATR period14int · min 1datr
% ATR to use for SL / PT5float · min 1 · max 100 · step 0.1percentage
Moving Averages
Show ema1 (no label in the script)falseboolFast EMA
Fast EMA8int · min 1ema1
Show smma1 (no label in the script)falseboolFast SMMA
Fast SMMA21int · min 1smma1 sma_1
Show smma2 (no label in the script)falseboolMedium SMMA
Medium SMMA50int · min 1smma2 sma_2
Show smma3 (no label in the script)falseboolFast SMMA
Slow SMMA200int · min 1smma3 sma_3
Linear Regression
Linear Regression Period50int · min 1lrc
LR Slope Period50int · min 1slrs
LR Signal Period14int · min 1alrs
LR Threshold for Ranging vs Trending0.03float · min 0 · step 0.001LR_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), 0lrc · 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

OrderFires whenBy defaultLine
Open Long longL_entry1On173
Open Long longL_entry2On175
Open Short shortS_entry1On178
Open Short shortS_entry2On180
Exit Exit stoptrade_trailingOn “Switch to trailing SL after TP hit”182
Exit Exit stoptrade_trailingOn “Switch to trailing SL after TP hit”183
Exit Exit stop and limitbarsSinceLastEntry() > 0On185
Exit Exit stop and limitbarsSinceLastEntry() > 0On186
Close strategy.opentrades > 0 and not t1On188

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(no title)alert3s Bull99
(no title)alert3s Bear101

Does it repaint?

No

No repainting patterns in the source.

Not measuredAn engine gap, not the scriptThe 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. The answer comes from the checks on the source alone.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

ScriptSharesTypeNetTradesMax drawdown
3 Candle Strike Stretegy this page—v5 strategy0.0%00.0%
Top 40 High Low Strategy for SPY, 5min by PtGamblerrma sma cross linreg emav5 strategyNo trades on this market
Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10ksma ema rmav4 strategy−19.4%3670.0%
Linear Regression MA - Strategy by lazy_capitalistsma linreg emav5 strategy−1,240.4%10318.7%
Double EMA CROSS by EmreErturk_ema cross smav4 strategy+5.1%934.5%
Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGamblerema sma rmav5 strategyNo 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 verified

Neither 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 111 msWith a workaround 1,000 bars in 173 msNot measured
PineTSNot testedNot testedNot 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 *****************************