Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

SL1 Pips after TP2 (MA)

A Pine Script v4 strategy built on EMA (close, 15), WMA (close, 45) and Crossover (ema, wma). It has 6 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 10 contracts and pays no commission. 16 settings; defaults include Start year 2022, 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 SL1 Pips after TP2 (MA) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
How did SL1 Pips after TP2 (MA) do on BTCUSDT 1D with default settings?
+0.44%
From 26 Jan 2024 to 21 Oct 2026, over 33 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can SL1 Pips after TP2 (MA) be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does SL1 Pips after TP2 (MA) use a stop loss?
Yes
strategy.exit sets a stop on line 78, 79, 82, 83.
Does SL1 Pips after TP2 (MA) run in Zeal Terminal?
Yes
It compiles in 26 ms and runs 1,000 bars in 74 ms, in the browser.

BTCUSDT · 1D · default settings

  • ema
  • wma
  • 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 (16)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,437$202,527Equity from $100,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.44%
$437.50
Buy and hold
+102.5%
same period
Closed trades
33
13 won · 20 lost
Profitable
39.4%
of closed trades
Profit factor
2.09
gross profit ÷ gross loss
Max drawdown
0.10%
−$100.10

One run with the author's default settings, $100,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

    3 settings have no label

    In the settings dialog Buy (line 6), Sell (line 7), pip (line 38) 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.

  • Note

    Uses an argument v6 removed

    when = on line 77, 81. The upgraded version below moves each call inside an if block.

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, wma → ta.wma, crossover → ta.crossover, crossunder → ta.crossunder, max → math.max, min → math.min.
  • 2 strategy calls use the when = argument (line 77, 81). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 33 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 23: ema → ta.ema
  • Line 24: wma → ta.wma
  • Line 27: crossover → ta.crossover
  • Line 33: crossunder → ta.crossunder
  • Line 62: max → math.max
5 more edits
  • Line 63: min → math.min
  • Line 64: max → math.max
  • Line 65: min → math.min
  • Line 68: min → math.min
  • Line 72: max → math.max
⋯// © gpadihar-//@version=4+//@version=5strategy("SL1 Pips after TP2 (MA)", commission_type=strategy.commission.cash_per_order, overlay=true, default_qty_value=10, initial_capital=100000)⋯wma_period = input(title='WMA period',defval=45)-ema        = ema(close,ema_period)+ema        = ta.ema(close,ema_period)-wma        = wma(close,wma_period)+wma        = ta.wma(close,wma_period)// Entry Conditionbuy =- crossover(ema,wma) and+ ta.crossover(ema,wma) and nz(strategy.position_size) >= 0 and Buy and⋯sell =- crossunder(ema,wma) and+ ta.crossunder(ema,wma) and nz(strategy.position_size) >= 0 and Sell and⋯// adjust trade parameters and trailing stop calculations-TVL := max(TP1,open) - pip[1]+TVL := math.max(TP1,open) - pip[1]-TVS := min(TP1,open) + pip[1]+TVS := math.min(TP1,open) + pip[1]-TSL := open[1] > TSL[1] ? max(TVL,TSL[1]):TVL +TSL := open[1] > TSL[1] ? math.max(TVL,TSL[1]):TVL -TSS := open[1] < TSS[1] ? min(TVS,TSS[1]):TVS+TSS := open[1] < TSS[1] ? math.min(TVS,TSS[1]):TVSif LS and high > TP1    if open <= TP1-        SL2:=min(EP,TSL)+        SL2:=math.min(EP,TSL)    ⋯    if open >= TP1-        SL2:=max(EP,TSS)+        SL2:=math.max(EP,TSS)// Closing conditions⋯

Clean v5

VerifiedDownload the v5 script

Same 33 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.bool()
  • Line 7: input() → input.bool()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
12 more edits
  • Line 13: input() → input.int()
  • Line 14: input() → input.bool()
  • Line 15: input() → input.int()
  • Line 16: input() → input.int()
  • Line 17: input() → input.int()
  • Line 18: input() → input.int()
  • Line 19: input() → input.int()
  • Line 21: input() → input.int()
  • Line 22: input() → input.int()
  • Line 38: input() → input.int()
  • Line 77: when = buy and not SS → if block
  • Line 81: when = sell and not LS → if block
⋯// Strategy-Buy  = input(true)+Buy  = input.bool(true)-Sell = input(true)+Sell = input.bool(true)// Date Range-start_year    = input(title='Start year'   ,defval=2022)+start_year    = input.int(title='Start year'   ,defval=2022)-start_month   = input(title='Start month'  ,defval=1)+start_month   = input.int(title='Start month'  ,defval=1)-start_day     = input(title='Start day'    ,defval=1)+start_day     = input.int(title='Start day'    ,defval=1)-start_hour    = input(title='Start hour'   ,defval=0)+start_hour    = input.int(title='Start hour'   ,defval=0)-start_minute  = input(title='Start minute' ,defval=0)+start_minute  = input.int(title='Start minute' ,defval=0)-end_time      = input(title='set end time?',defval=false)+end_time      = input.bool(title='set end time?',defval=false)-end_year      = input(title='end year'     ,defval=2019)+end_year      = input.int(title='end year'     ,defval=2019)-end_month     = input(title='end month'    ,defval=12)+end_month     = input.int(title='end month'    ,defval=12)-end_day       = input(title='end day'      ,defval=31)+end_day       = input.int(title='end day'      ,defval=31)-end_hour      = input(title='end hour'     ,defval=23)+end_hour      = input.int(title='end hour'     ,defval=23)-end_minute    = input(title='end minute'   ,defval=59)+end_minute    = input.int(title='end minute'   ,defval=59)// MA-ema_period = input(title='EMA period',defval=15)+ema_period = input.int(title='EMA period',defval=15)-wma_period = input(title='WMA period',defval=45)+wma_period = input.int(title='WMA period',defval=45)ema        = ta.ema(close,ema_period)⋯// Pips-pip = input(20)*10*syminfo.mintick+pip = input.int(20)*10*syminfo.mintick// Trading parameters //⋯// Buy-strategy.entry("buy"  , strategy.long, when=buy and not SS)+if buy and not SS+    strategy.entry("buy"  , strategy.long)strategy.exit ("exit1", from_entry="buy", stop=SL1, limit=TP1, qty_percent=100)⋯// Sell-strategy.entry("sell" , strategy.short, when=sell and not LS)+if sell and not LS+    strategy.entry("sell" , strategy.short)strategy.exit ("exit3", from_entry="sell", stop=SL1, limit=TP1, qty_percent=100)⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L40:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © gpadihar-//@version=5+//@version=6strategy("SL1 Pips after TP2 (MA)", commission_type=strategy.commission.cash_per_order, overlay=true, default_qty_value=10, initial_capital=100000)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Buy (no label in the script)trueboolbuy
Sell (no label in the script)trueboolsell
Start year2022intbuy sell
Start month1intbuy sell
Start day1intbuy sell
Start hour0intbuy sell
Start minute0intbuy sell
set end time?falseboolbuy sell
end year2019intbuy sell
end month12intbuy sell
end day31intbuy sell
end hour23intbuy sell
end minute59intbuy sell
EMA period15intema
WMA period45intwma
Pip (no label in the script)20intTVL TVS TP1 TP2 SL1 SL2

What it calculates

  • EMA (ema, ta.ema in v5)close, EMA period (15)ema · line 23
  • WMA (wma, ta.wma in v5)close, WMA period (45)wma · line 24
  • Crossover (crossover, ta.crossover in v5)ema, wmabuy · line 26
  • Crossunder (crossunder, ta.crossunder in v5)ema, wmasell · line 32

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.

closecloseprice dataema_periodEMA periodsetting · 15wma_periodWMA periodsetting · 45timetimeprice datastart_yearStart yearsetting · 2022start_monthStart monthsetting · 1start_dayStart daysetting · 1start_hourStart hoursetting · 0start_minuteStart minutesetting · 0end_yearend yearsetting · 2019end_monthend monthsetting · 12end_dayend daysetting · 31end_hourend hoursetting · 23end_minuteend minutesetting · 59openopenprice datapipPipsetting · 20emaEMA→ emawmaWMA→ wmabuyCrossover→ buysellCrossunder→ sellEPEPvalueTVL, TVSTVL · TVS2 valuesTSLTSLvalueTSSTSSvalueTP1, TP2, SL1TP1 · TP2 +13 valuesSL2SL2valueLSLSconditionSSSSconditionclose_longclose_longconditionclose_shortclose_shortconditionentry:buyOpen buystrategy.entryexit:exit1exit exit1strategy.exitexit:exit2exit exit2strategy.exitentry:sellOpen sellstrategy.entryexit:exit3exit exit3strategy.exitexit:exit4exit exit4strategy.exitplot:85plotplotplot:86plotplotplot:87plotplotplot:88plotplotplot:89plotplotplot:90plotplotplot:91plotplotplot:92plotplotplot:93emaplotplot:94wmaplot

Order rules

OrderFires whenBy defaultLine
Open buy longbuy and not SSOn77
Exit exit1 stop and limitevery barOn78
Exit exit2 stop and limitevery barOn79
Open sell shortsell and not LSOn81
Exit exit3 stop and limitevery barOn82
Exit exit4 stop and limitevery barOn83

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, and the live replay matched history.

10/10trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+0.4%+102.5%3339%2.090.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.1%+5.5%3931%1.190.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.4%+9.8%2941%2.120.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%3531%1.080.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%2931%1.100.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.1%+21.5%2129%1.280.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%3132%1.330.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%2825%0.950.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market967%$300.30
Sideways market1735%$177.40
Falling market714%−$40.20

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

0.2%

The 95th percentile of the worst drawdown when the same 33 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.1% to 0.2%; the tick is what actually happened, 0.1%. Order luck alone moves it this much.

0%1%
All 33 trades
SideEntryExitBarsP&L
short14 Apr 2024 63,924.5014 Apr 2024 63,916.500$80.10
long18 May 2024 67,024.0018 May 2024 67,028.000$40.00
short17 Jun 2024 66,676.9017 Jun 2024 66,678.900−$20.10
long20 Jul 2024 66,660.0020 Jul 2024 66,658.000−$20.10
short6 Aug 2024 54,018.806 Aug 2024 54,010.800$80.10
long27 Aug 2024 62,834.0027 Aug 2024 62,838.000$40.00
short28 Aug 2024 59,415.0028 Aug 2024 59,417.000−$20.00
long19 Sep 2024 61,760.0019 Sep 2024 61,758.000−$19.90
short28 Dec 2024 94,299.0028 Dec 2024 94,291.000$80.00
long18 Jan 2025 104,077.0018 Jan 2025 104,081.000$40.10
short7 Feb 2025 96,554.407 Feb 2025 96,546.400$80.00
long19 Apr 2025 84,474.7019 Apr 2025 84,472.700−$20.10
short19 Jun 2025 104,887.0019 Jun 2025 104,889.000−$19.90
long30 Jun 2025 108,357.0030 Jun 2025 108,361.000$40.00
short7 Aug 2025 114,992.007 Aug 2025 114,984.000$80.00
long8 Aug 2025 117,472.008 Aug 2025 117,476.000$39.90
short10 Aug 2025 116,462.0010 Aug 2025 116,464.000−$20.00
long11 Aug 2025 119,294.0011 Aug 2025 119,292.000−$22.60
short20 Aug 2025 112,873.0020 Aug 2025 112,865.000$80.10
long15 Sep 2025 115,268.0015 Sep 2025 115,266.000−$20.00
short27 Sep 2025 109,643.0027 Sep 2025 109,645.000−$20.00
long2 Oct 2025 118,595.002 Oct 2025 118,593.000−$20.00
short16 Oct 2025 110,763.0016 Oct 2025 110,765.000−$20.00
long5 Jan 2026 91,529.705 Jan 2026 91,527.700−$20.10
short26 Jan 2026 86,670.4026 Jan 2026 86,662.400$80.00
long13 Mar 2026 70,541.3013 Mar 2026 70,539.300−$20.00
short29 Mar 2026 66,377.0029 Mar 2026 66,379.000−$19.90
long10 Apr 2026 71,788.0010 Apr 2026 71,786.000−$20.10
short23 May 2026 75,539.5023 May 2026 75,531.500$80.00
long12 Jul 2026 63,819.0012 Jul 2026 63,817.000−$20.10
short13 Aug 2026 63,480.0013 Aug 2026 63,482.000−$20.00
long20 Aug 2026 69,334.8020 Aug 2026 69,332.800−$19.90
short18 Oct 2026 81,491.0018 Oct 2026 81,493.000−$20.00

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
SL1 Pips after TP2 (MA) this page—v4 strategy+0.4%330.1%
Escaping of Rate from Avarage By Mustafa OZVER Strategy by Mustafaozverwma emav4 strategy+122.0%9679.1%
Forex SWING Trader by SoftKill21wma emav4 strategyNo trades on this market
No-lose trading targets (Based on EoRfA) By Mustafa ÖZVER by Mustafaozverwma emav4 strategyNo trades on this market
EDMA Scalping Strategy (Exponentially Deviating Moving Average) by MightyZingerwma emav5 strategydoes not run in Zeal Terminal
tvbot Trend Following with Mean Reversion algo by tvbot-ema wmav5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 26 msWith a workaround 1,000 bars in 74 msNot measured
PineTSNo 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/// © gpadihar//@version=4strategy("SL1 Pips after TP2 (MA)", commission_type=strategy.commission.cash_per_order, overlay=true, default_qty_value=10, initial_capital=100000)// StrategyBuy  = input(true)Sell = input(true)// Date Rangestart_year    = input(title='Start year'   ,defval=2022)start_month   = input(title='Start month'  ,defval=1)start_day     = input(title='Start day'    ,defval=1)start_hour    = input(title='Start hour'   ,defval=0)start_minute  = input(title='Start minute' ,defval=0)end_time      = input(title='set end time?',defval=false)end_year      = input(title='end year'     ,defval=2019)end_month     = input(title='end month'    ,defval=12)end_day       = input(title='end day'      ,defval=31)end_hour      = input(title='end hour'     ,defval=23)end_minute    = input(title='end minute'   ,defval=59)// MAema_period = input(title='EMA period',defval=15)wma_period = input(title='WMA period',defval=45)ema        = ema(close,ema_period)wma        = wma(close,wma_period)// Entry Conditionbuy = crossover(ema,wma) and nz(strategy.position_size) >= 0 and Buy and time > timestamp(start_year, start_month, start_day, start_hour, start_minute) and (end_time?(time < timestamp(end_year, end_month, end_day, end_hour, end_minute)):true) sell = crossunder(ema,wma) and nz(strategy.position_size) >= 0 and Sell and time > timestamp(start_year, start_month, start_day, start_hour, start_minute) and (end_time?(time < timestamp(end_year, end_month, end_day, end_hour, end_minute)):true)// Pipspip = input(20)*10*syminfo.mintick// Trading parameters //var bool  LS  = navar bool  SS  = navar float EP  = navar float TVL = navar float TVS = navar float TSL = navar float TSS = navar float TP1 = navar float TP2 = navar float SL1 = navar float SL2 = naif buy or sell and strategy.position_size == 0    EP  := close    SL1 := EP - pip * 1 * (sell?-1:1)    SL2 := EP - pip     * (sell?-1:1)    TP1 := EP + pip * 2 * (sell?-2:1)    TP2 := EP + pip * 3 * (sell?-2:1)    // current trade direction    LS := buy  or strategy.position_size > 0SS := sell or strategy.position_size < 0// adjust trade parameters and trailing stop calculationsTVL := max(TP1,open) - pip[1]TVS := min(TP1,open) + pip[1]TSL := open[1] > TSL[1] ? max(TVL,TSL[1]):TVL TSS := open[1] < TSS[1] ? min(TVS,TSS[1]):TVSif LS and high > TP1    if open <= TP1        SL2:=min(EP,TSL)    if SS and low < TP1    if open >= TP1        SL2:=max(EP,TSS)// Closing conditionsclose_long  = LS and open < SL2close_short = SS and open > SL2// Buystrategy.entry("buy"  , strategy.long, when=buy and not SS)strategy.exit ("exit1", from_entry="buy", stop=SL1, limit=TP1, qty_percent=100)strategy.exit ("exit2", from_entry="buy", stop=SL2, limit=TP2)// Sellstrategy.entry("sell" , strategy.short, when=sell and not LS)strategy.exit ("exit3", from_entry="sell", stop=SL1, limit=TP1, qty_percent=100)strategy.exit ("exit4", from_entry="sell", stop=SL2, limit=TP2)// Plotsa=plot(strategy.position_size >  0 ? SL1 : na, color=#dc143c, style=plot.style_linebr)b=plot(strategy.position_size <  0 ? SL1 : na, color=#dc143c, style=plot.style_linebr) c=plot(strategy.position_size >  0 ? TP1 : na, color=#00ced1, style=plot.style_linebr) d=plot(strategy.position_size <  0 ? TP1 : na, color=#00ced1, style=plot.style_linebr) e=plot(strategy.position_size >  0 ? TP2 : na, color=#00ced1, style=plot.style_linebr) f=plot(strategy.position_size <  0 ? TP2 : na, color=#00ced1, style=plot.style_linebr) g=plot(strategy.position_size >= 0 ? na  : EP, color=#ffffff, style=plot.style_linebr) h=plot(strategy.position_size <= 0 ? na  : EP, color=#ffffff, style=plot.style_linebr) plot(ema,title="ema",color=#fff176)plot(wma,title="wma",color=#00ced1)