Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Impulse Strategy Signals V2

A Pine Script v5 strategy built on SMA (src, len), RSI (close, 14) and ATR (14). It has 10 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 commits 100% of equity and pays no commission. 33 settings; defaults include SMMA Length 1 21, SMMA Length 2 50 and SMMA Length 3 200.

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 Impulse Strategy Signals V2 repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Impulse Strategy Signals V2 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 BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
What alerts does Impulse Strategy Signals V2 have?
4
longCond_txt; shortCond_txt; long_sltp_txt; short_sltp_txt.
Does Impulse Strategy Signals V2 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: 12 before, 8 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Impulse Strategy Signals V2 use a stop loss?
Yes
strategy.exit sets a stop on line 144, 145, 146, 147, 148, 149, 150, 151.

BTCUSDT · 1D · default settings

  • MA1
  • MA2
  • MA3
  • 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 (33)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$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.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, $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.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    6 settings have no label

    In the settings dialog i_sl_sw (line 48), i_tsl_sw (line 49), i_tp1_sw (line 52), i_tp2_sw (line 53), i_tp3_sw (line 54), i_tp4_sw (line 55) 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 144, 145, 146, 147, 148, 149, 150, 151. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
SMMA
SMMA Length 1 21intma1
SMMA Length 2 50intma2
SMMA Length 3 200intma3
RSI
RSI Sourceclosesourcersi
RSI Length14intrsi
LONG: RSI Entry Threshold50.0floatlong0
SHORT: RSI Entry Threshold50.0floatshort0
Trading Session 10700-1600sessiont1
Trading Session 21200-2100sessiont2
Backtesting Start Timetimestamp("01 Sep 2002 13:30 +0000")timetimeCond
Backtesting End Timetimestamp("30 Sep 2099 19:30 +0000")timetimeCond
Show SL/TP Lines on CharttrueboolTP Long 1 TP Long 2 TP Long 3 TP Long 4 TP Short 1 TP Short 2 TP Short 3 TP Short 4 SL Long SL Short
strategy settings
ATR Length14intatr
I sl sw (no label in the script)ATRstring · options ["%", "ATR"]sl sl_long0 sl_short0
I tsl sw (no label in the script)ATRstring · options ["ATR", "%"]tsl trail_long_final trail_short_final
● Stop Loss 2.0float · min 0 · step 0.1sl
● Trailing SL0.0float · min 0 · step 0.1tsl
I tp1 sw (no label in the script)%string · options ["%", "ATR", "R:R"]tp1 tp_long1 tp_short1
I tp2 sw (no label in the script)%string · options ["%", "ATR", "R:R"]tp2 tp_long2 tp_short2
I tp3 sw (no label in the script)%string · options ["%", "ATR", "R:R"]tp3 tp_long3 tp_short3
I tp4 sw (no label in the script)%string · options ["%", "ATR", "R:R"]tp4 tp_long4 tp_short4
TP 11.0float · min 0 · step 0.1tp1 last_tp_long last_tp_short
TP 22.0float · min 0 · step 0.1tp2 last_tp_long last_tp_short
TP 33.0float · min 0 · step 0.1tp3 last_tp_long last_tp_short
TP 44.0float · min 0 · step 0.1tp4 last_tp_long last_tp_short
QTY%10.0floatperc_tp1 perc_tp2 perc_tp3 perc_tp4
QTY%10.0floatperc_tp2 perc_tp3 perc_tp4
QTY%30.0floatperc_tp3 perc_tp4
QTY%100.0floatperc_tp4
Alert Message
Alert Msg: LONG Entrystringalert
Alert Msg: SHORT Entrystringalert
Alert Msg: LONG SL/TPstringalert
Alert Msg: SHORT SL/TPstringalert

What it calculates

  • SMAsrc, lensmma · line 10
  • RSIRSI Source (close), RSI Length (14)rsi · line 21
  • ATRATR Length (14)atr · line 47
  • ValuewhenlongCond, close, 0long_entry · line 74
  • ValuewhenshortCond, close, 0short_entry · line 75
  • ValuewhenlongCond, close -atr * sl, 0sl_long_atr · line 89
  • ValuewhenshortCond, close +atr * sl, 0sl_short_atr · line 90
  • ValuewhenlongCond, close + atr * tp1, 0atr_tp_long1 · line 95
  • ValuewhenlongCond, close+math.abs(close-sl_long )* tp1, 0rr_tp_long1 · line 95
  • ValuewhenlongCond, close + atr * tp2, 0atr_tp_long2 · line 96
  • ValuewhenlongCond, close+math.abs(close-sl_long )* tp2, 0rr_tp_long2 · line 96
  • ValuewhenlongCond, close + atr * tp3, 0atr_tp_long3 · line 97
  • ValuewhenlongCond, close+math.abs(close-sl_long )* tp3, 0rr_tp_long3 · line 97
  • ValuewhenlongCond, close + atr * tp4, 0atr_tp_long4 · line 98
  • ValuewhenlongCond, close+math.abs(close-sl_long )* tp4, 0rr_tp_long4 · line 98
  • ValuewhenshortCond, close - atr * tp1, 0atr_tp_short1 · line 99
  • ValuewhenshortCond, close-math.abs(close-sl_short)*tp1, 0rr_tp_short1 · line 99
  • ValuewhenshortCond, close - atr * tp2, 0atr_tp_short2 · line 100
  • ValuewhenshortCond, close-math.abs(close-sl_short)*tp2, 0rr_tp_short2 · line 100
  • ValuewhenshortCond, close - atr * tp3, 0atr_tp_short3 · line 101
  • ValuewhenshortCond, close-math.abs(close-sl_short)*tp3, 0rr_tp_short3 · line 101
  • ValuewhenshortCond, close - atr * tp4, 0atr_tp_short4 · line 102
  • ValuewhenshortCond, close-math.abs(close-sl_short)*tp4, 0rr_tp_short4 · line 102

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 153 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long longlongCondOn140
Open short shortshortCondOn142
Exit SL/TP1 stop and limitperc_tp1 >0On144
Exit SL/TP2 stop and limitperc_tp2 >0On145
Exit SL/TP3 stop and limitperc_tp3 >0On146
Exit SL/TP4 stop and limitperc_tp4 >0On147
Exit SL/TP1 stop and limitperc_tp1 >0On148
Exit SL/TP2 stop and limitperc_tp2 >0On149
Exit SL/TP3 stop and limitperc_tp3 >0On150
Exit SL/TP4 stop and limitperc_tp4 >0On151

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

Alerts

AlertCallMessageLine
(no title)alertlongCond_txt170
(no title)alertshortCond_txt172
(no title)alertlong_sltp_txt174
(no title)alertshort_sltp_txt176

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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 4h−0.1%+5.5%1242%0.984.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.5%+8.4%850%1.213.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−9.6%+21.5%2025%0.1310.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−5.9%+17.1%120%0.005.9%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
Impulse Strategy Signals V2 this page—v5 strategy0.0%00.0%
Bollinger band & Volume based strategy V2 by Ayden_Csma atr rsi valuewhenv4 strategy−0.1%50.2%
MA cross strategy by Glenn234sma rsi atrv5 strategy−606.2%35656.0%
Estrategia Larry Connors [JoseMetal] by JoseMetalsma rsi atrv5 strategy+2.7%242.4%
[fpemehd] Strategy Template by DuDu95atr sma valuewhenv5 strategy+10.5%4114.8%
3 x EMA + Stochastic RSI + ATR by tomimarsonrsi sma atrv4 strategy−42.3%1844.8%

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.

  • 8 strategy calls use the when = argument (line 144, 145, 146, 147, 148, 149, 150, 151). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 15 settings use the untyped input() (line 5, 6, 7, 19, 20, 46, 60, 61, 62, 63, 152, 165, 166, 167, 168). 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

VerifiedDownload the v5 script

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

  • Line 5: input() → input.int()
  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 19: input() → input.source()
  • Line 20: input() → input.int()
  • Line 46: input() → input.int()
17 more edits
  • Line 60: input() → input.float()
  • Line 61: input() → input.float()
  • Line 62: input() → input.float()
  • Line 63: input() → input.float()
  • Line 144: when = perc_tp1 >0 → if block
  • Line 145: when = perc_tp2 >0 → if block
  • Line 146: when = perc_tp3 >0 → if block
  • Line 147: when = perc_tp4 >0 → if block
  • Line 148: when = perc_tp1 >0 → if block
  • Line 149: when = perc_tp2 >0 → if block
  • Line 150: when = perc_tp3 >0 → if block
  • Line 151: when = perc_tp4 >0 → if block
  • Line 152: input() → input.bool()
  • Line 165: input() → input.string()
  • Line 166: input() → input.string()
  • Line 167: input() → input.string()
  • Line 168: input() → input.string()
⋯strategy(title = "Impulse Strategy Signals (SMMA Cross)", overlay = true, default_qty_value = 100, initial_capital=100000,default_qty_type=strategy.percent_of_equity, pyramiding=0, process_orders_on_close=true) -ma_len1 = input(21, title="SMMA Length 1 ", group='SMMA')+ma_len1 = input.int(21, title="SMMA Length 1 ", group='SMMA')-ma_len2 = input(50, title="SMMA Length 2 ", group='SMMA')+ma_len2 = input.int(50, title="SMMA Length 2 ", group='SMMA')-ma_len3 = input(200, title="SMMA Length 3 ", group='SMMA')+ma_len3 = input.int(200, title="SMMA Length 3 ", group='SMMA')smma(src, len) =>⋯plot(ma3, title='MA3', color=color.white)-rsi_src = input(close, title="RSI Source", group='RSI')+rsi_src = input.source(close, title="RSI Source", group='RSI')-rsi_len = input(14, title='RSI Length', group='RSI')+rsi_len = input.int(14, title='RSI Length', group='RSI')rsi = ta.rsi(rsi_src, rsi_len)⋯strat_grp = "strategy settings"-atrlen = input(14, title="ATR Length", group=strat_grp)+atrlen = input.int(14, title="ATR Length", group=strat_grp)atr = ta.atr(atrlen)⋯i_tp4   = input.float(4.0, title="TP 4", minval=0, step=0.1, inline="i_tp4 ", group=strat_grp)-perc_tp1_0  = input(10.0 , title="QTY%", inline="i_tp1 ", group=strat_grp)+perc_tp1_0  = input.float(10.0 , title="QTY%", inline="i_tp1 ", group=strat_grp)-perc_tp2_0  = input(10.0 , title="QTY%", inline="i_tp2 ", group=strat_grp)+perc_tp2_0  = input.float(10.0 , title="QTY%", inline="i_tp2 ", group=strat_grp)-perc_tp3_0  = input(30.0 , title="QTY%", inline="i_tp3 ", group=strat_grp)+perc_tp3_0  = input.float(30.0 , title="QTY%", inline="i_tp3 ", group=strat_grp)-perc_tp4_0  = input(100.0, title="QTY%", inline="i_tp4 ", group=strat_grp)+perc_tp4_0  = input.float(100.0, title="QTY%", inline="i_tp4 ", group=strat_grp)perc_tp1 = perc_tp1_0⋯    -strategy.exit("SL/TP1 ", from_entry = "long" , stop=sl_long , limit=tp_long1 , qty_percent=perc_tp1 , when=perc_tp1 >0)+if perc_tp1 >0+    strategy.exit("SL/TP1 ", from_entry = "long" , stop=sl_long , limit=tp_long1 , qty_percent=perc_tp1 )-strategy.exit("SL/TP2 ", from_entry = "long" , stop=sl_long , limit=tp_long2 , qty_percent=perc_tp2 , when=perc_tp2 >0)+if perc_tp2 >0+    strategy.exit("SL/TP2 ", from_entry = "long" , stop=sl_long , limit=tp_long2 , qty_percent=perc_tp2 )-strategy.exit("SL/TP3 ", from_entry = "long" , stop=sl_long , limit=tp_long3 , qty_percent=perc_tp3 , when=perc_tp3 >0)+if perc_tp3 >0+    strategy.exit("SL/TP3 ", from_entry = "long" , stop=sl_long , limit=tp_long3 , qty_percent=perc_tp3 )-strategy.exit("SL/TP4 ", from_entry = "long" , stop=sl_long , limit=tp_long4 , qty_percent=perc_tp4 , when=perc_tp4 >0)+if perc_tp4 >0+    strategy.exit("SL/TP4 ", from_entry = "long" , stop=sl_long , limit=tp_long4 , qty_percent=perc_tp4 )-strategy.exit("SL/TP1 ", from_entry = "short" , stop=sl_short, limit=tp_short1 , qty_percent=perc_tp1 , when=perc_tp1 >0)+if perc_tp1 >0+    strategy.exit("SL/TP1 ", from_entry = "short" , stop=sl_short, limit=tp_short1 , qty_percent=perc_tp1 )-strategy.exit("SL/TP2 ", from_entry = "short" , stop=sl_short, limit=tp_short2 , qty_percent=perc_tp2 , when=perc_tp2 >0)+if perc_tp2 >0+    strategy.exit("SL/TP2 ", from_entry = "short" , stop=sl_short, limit=tp_short2 , qty_percent=perc_tp2 )-strategy.exit("SL/TP3 ", from_entry = "short" , stop=sl_short, limit=tp_short3 , qty_percent=perc_tp3 , when=perc_tp3 >0)+if perc_tp3 >0+    strategy.exit("SL/TP3 ", from_entry = "short" , stop=sl_short, limit=tp_short3 , qty_percent=perc_tp3 )-strategy.exit("SL/TP4 ", from_entry = "short" , stop=sl_short, limit=tp_short4 , qty_percent=perc_tp4 , when=perc_tp4 >0)+if perc_tp4 >0+    strategy.exit("SL/TP4 ", from_entry = "short" , stop=sl_short, limit=tp_short4 , qty_percent=perc_tp4 )-show_sltp = input(true, title="Show SL/TP Lines on Chart")+show_sltp = input.bool(true, title="Show SL/TP Lines on Chart")plot(show_sltp and pos== 1? tp_long1  : na, color=color.green, style=plot.style_linebr, title="TP Long 1")⋯plotshape(shortCond, textcolor=#ffffff, color=color.red , style=shape.labeldown, title="Sell", text="Sell", location=location.abovebar,  offset=0, size=size.small)-longCond_txt         = input("", title='Alert Msg: LONG Entry', group='Alert Message', inline='longCond_txt      ')+longCond_txt         = input.string("", title='Alert Msg: LONG Entry', group='Alert Message', inline='longCond_txt      ')-shortCond_txt        = input("", title='Alert Msg: SHORT Entry', group='Alert Message', inline='shortCond_txt     ')+shortCond_txt        = input.string("", title='Alert Msg: SHORT Entry', group='Alert Message', inline='shortCond_txt     ')-long_sltp_txt        = input("", title='Alert Msg: LONG SL/TP', group='Alert Message', inline='long_sltp_txt       ')+long_sltp_txt        = input.string("", title='Alert Msg: LONG SL/TP', group='Alert Message', inline='long_sltp_txt       ')-short_sltp_txt       = input("", title='Alert Msg: SHORT SL/TP', group='Alert Message', inline='short_sltp_txt      ')+short_sltp_txt       = input.string("", title='Alert Msg: SHORT SL/TP', group='Alert Message', inline='short_sltp_txt      ')if longCond⋯

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: 12 before, 8 after on BTCUSDT 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.

⋯// © Hiubris_Indicators-//@version=5+//@version=6strategy(title = "Impulse Strategy Signals (SMMA Cross)", overlay = true, default_qty_value = 100, initial_capital=100000,default_qty_type=strategy.percent_of_equity, pyramiding=0, process_orders_on_close=true) ⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 73 msWith a workaround 1,000 bars in 176 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/// © Hiubris_Indicators//@version=5strategy(title = "Impulse Strategy Signals (SMMA Cross)", overlay = true, default_qty_value = 100, initial_capital=100000,default_qty_type=strategy.percent_of_equity, pyramiding=0, process_orders_on_close=true) ma_len1 = input(21, title="SMMA Length 1 ", group='SMMA')ma_len2 = input(50, title="SMMA Length 2 ", group='SMMA')ma_len3 = input(200, title="SMMA Length 3 ", group='SMMA')smma(src, len) =>    smma = 0.0    smma := na(smma[1]) ? ta.sma(src, len) : (smma[1] * (len - 1) + src) / len    smma    ma1 = smma(close, ma_len1)ma2 = smma(close, ma_len2)ma3 = smma(close, ma_len3)plot(ma1, title='MA1', color=color.green)plot(ma2, title='MA2', color=color.orange)plot(ma3, title='MA3', color=color.white)rsi_src = input(close, title="RSI Source", group='RSI')rsi_len = input(14, title='RSI Length', group='RSI')rsi = ta.rsi(rsi_src, rsi_len)rsi_long = input.float(50.0, title="LONG: RSI Entry Threshold", group='RSI')rsi_short= input.float(50.0, title="SHORT: RSI Entry Threshold", group='RSI')// Trading Session 1session1 = input.session("0700-1600", title="Trading Session 1")+":1234567"t1 = time(timeframe.period, session1)trading_session_filter1 = na(t1) ? 0 : 1// Trading Session 2session2 = input.session("1200-2100", title="Trading Session 2")+":1234567"t2 = time(timeframe.period, session2)trading_session_filter2 = na(t2) ? 0 : 1bgcolor(trading_session_filter1? color.new(color.blue, 90):na, title="Trading Session 1")bgcolor(trading_session_filter2? color.new(color.blue, 90):na, title="Trading Session 2")trading_session_cond = (trading_session_filter1 or trading_session_filter2) and not (trading_session_filter1 and trading_session_filter2)long0 = rsi>rsi_long and close>ma1 and close>ma2 and close>ma3 and ((ta.crossover (ma1, ma2) or ta.crossover (close, ma3)))short0= rsi<rsi_short and close<ma1 and close<ma2 and close<ma3 and ((ta.crossunder(ma1, ma2) or ta.crossunder(close, ma3)))long = long0  and not long0 [1] and trading_session_condshort= short0 and not short0[1] and trading_session_cond// Position Management Toolspos = 0.0pos:= long? 1 : short? -1 : pos[1]longCond  = long  and (pos[1]!= 1 or na(pos[1]))shortCond = short and (pos[1]!=-1 or na(pos[1]))// EXIT FUNCTIONS //strat_grp = "strategy settings"atrlen = input(14, title="ATR Length", group=strat_grp)atr = ta.atr(atrlen)i_sl_sw  = input.string("ATR", title="", inline="i_sl ", options=["%", "ATR"], group=strat_grp)i_tsl_sw = input.string("ATR", title="", inline="i_tsl", options=["ATR", "%"], group=strat_grp)i_sl  = input.float(2.0, title="● Stop Loss  ", minval=0, inline="i_sl ", group=strat_grp,step=0.1)i_tsl = input.float(0.0, title="● Trailing SL", minval=0, inline="i_tsl", group=strat_grp,step=0.1)i_tp1_sw   = input.string("%", title="", inline="i_tp1 ", options=["%", "ATR", "R:R"], group=strat_grp)i_tp2_sw   = input.string("%", title="", inline="i_tp2 ", options=["%", "ATR", "R:R"], group=strat_grp)i_tp3_sw   = input.string("%", title="", inline="i_tp3 ", options=["%", "ATR", "R:R"], group=strat_grp)i_tp4_sw   = input.string("%", title="", inline="i_tp4 ", options=["%", "ATR", "R:R"], group=strat_grp)i_tp1   = input.float(1.0, title="TP 1", minval=0, step=0.1, inline="i_tp1 ", group=strat_grp)i_tp2   = input.float(2.0, title="TP 2", minval=0, step=0.1, inline="i_tp2 ", group=strat_grp)i_tp3   = input.float(3.0, title="TP 3", minval=0, step=0.1, inline="i_tp3 ", group=strat_grp)i_tp4   = input.float(4.0, title="TP 4", minval=0, step=0.1, inline="i_tp4 ", group=strat_grp)perc_tp1_0  = input(10.0 , title="QTY%", inline="i_tp1 ", group=strat_grp)perc_tp2_0  = input(10.0 , title="QTY%", inline="i_tp2 ", group=strat_grp)perc_tp3_0  = input(30.0 , title="QTY%", inline="i_tp3 ", group=strat_grp)perc_tp4_0  = input(100.0, title="QTY%", inline="i_tp4 ", group=strat_grp)perc_tp1 = perc_tp1_0perc_tp2 = perc_tp1_0+perc_tp2_0==100? 100 : perc_tp2_0perc_tp3 = perc_tp1_0+perc_tp2_0+perc_tp3_0==100? 100 : perc_tp3_0perc_tp4 = perc_tp1_0+perc_tp2_0+perc_tp3_0+perc_tp4_0==100? 100 : perc_tp4_0sl  = i_sl >0? (i_sl_sw =="%"? i_sl /100 : i_sl ) : 99999tsl = i_tsl>0? (i_tsl_sw=="%"? i_tsl/100 : i_tsl) : 99999tp1   = i_tp1  >0? (i_tp1_sw  =="%"? i_tp1  /100 : i_tp1  ) : 99999tp2   = i_tp2  >0? (i_tp2_sw  =="%"? i_tp2  /100 : i_tp2  ) : 99999tp3   = i_tp3  >0? (i_tp3_sw  =="%"? i_tp3  /100 : i_tp3  ) : 99999tp4   = i_tp4  >0? (i_tp4_sw  =="%"? i_tp4  /100 : i_tp4  ) : 99999long_entry  = ta.valuewhen(longCond , close, 0)short_entry = ta.valuewhen(shortCond, close, 0)// Trailing Stop Losstrail_long = 0.0, trail_short = 0.0trail_long  := longCond? high : high>trail_long[1]? high : pos<1 ? 0  : trail_long[1]trail_short := shortCond? low : low<trail_short[1]? low : pos>-1 ? 99999  : trail_short[1]trail_long_final_atr    = trail_long  - atr*tsltrail_short_final_atr   = trail_short + atr*tsltrail_long_final_perc   = trail_long  * (1-tsl)trail_short_final_perc  = trail_short * (1+tsl)trail_long_final  = i_tsl_sw=="ATR"? trail_long_final_atr  : trail_long_final_perc trail_short_final = i_tsl_sw=="ATR"? trail_short_final_atr : trail_short_final_perc// Stop Loss Functionssl_long_perc   = long_entry  * (1 - sl)sl_short_perc  = short_entry * (1 + sl)sl_long_atr   = ta.valuewhen(longCond , close -atr * sl, 0)sl_short_atr  = ta.valuewhen(shortCond, close +atr * sl, 0)sl_long0  = i_sl_sw =="%"? sl_long_perc  : i_sl_sw =="ATR"? sl_long_atr  : 0 sl_short0 = i_sl_sw =="%"? sl_short_perc : i_sl_sw =="ATR"? sl_short_atr : 99999sl_long  = math.max(sl_long0 , trail_long_final )sl_short = math.min(sl_short0, trail_short_final)perc_tp_long1   = long_entry  * (1 + tp1 ),   atr_tp_long1   = ta.valuewhen(longCond , close + atr * tp1 , 0),   rr_tp_long1   = ta.valuewhen(longCond , close+math.abs(close-sl_long )* tp1 , 0)perc_tp_long2   = long_entry  * (1 + tp2 ),   atr_tp_long2   = ta.valuewhen(longCond , close + atr * tp2 , 0),   rr_tp_long2   = ta.valuewhen(longCond , close+math.abs(close-sl_long )* tp2 , 0)perc_tp_long3   = long_entry  * (1 + tp3 ),   atr_tp_long3   = ta.valuewhen(longCond , close + atr * tp3 , 0),   rr_tp_long3   = ta.valuewhen(longCond , close+math.abs(close-sl_long )* tp3 , 0)perc_tp_long4   = long_entry  * (1 + tp4 ),   atr_tp_long4   = ta.valuewhen(longCond , close + atr * tp4 , 0),   rr_tp_long4   = ta.valuewhen(longCond , close+math.abs(close-sl_long )* tp4 , 0)perc_tp_short1  = short_entry * (1 - tp1 ),   atr_tp_short1  = ta.valuewhen(shortCond , close - atr * tp1 , 0),   rr_tp_short1  = ta.valuewhen(shortCond, close-math.abs(close-sl_short)*tp1 , 0)perc_tp_short2  = short_entry * (1 - tp2 ),   atr_tp_short2  = ta.valuewhen(shortCond , close - atr * tp2 , 0),   rr_tp_short2  = ta.valuewhen(shortCond, close-math.abs(close-sl_short)*tp2 , 0)perc_tp_short3  = short_entry * (1 - tp3 ),   atr_tp_short3  = ta.valuewhen(shortCond , close - atr * tp3 , 0),   rr_tp_short3  = ta.valuewhen(shortCond, close-math.abs(close-sl_short)*tp3 , 0)perc_tp_short4  = short_entry * (1 - tp4 ),   atr_tp_short4  = ta.valuewhen(shortCond , close - atr * tp4 , 0),   rr_tp_short4  = ta.valuewhen(shortCond, close-math.abs(close-sl_short)*tp4 , 0)tp_long1   = i_tp1_sw  =="%"? perc_tp_long1   : i_tp1_sw  =="ATR"? atr_tp_long1   : rr_tp_long1  tp_long2   = i_tp2_sw  =="%"? perc_tp_long2   : i_tp2_sw  =="ATR"? atr_tp_long2   : rr_tp_long2  tp_long3   = i_tp3_sw  =="%"? perc_tp_long3   : i_tp3_sw  =="ATR"? atr_tp_long3   : rr_tp_long3  tp_long4   = i_tp4_sw  =="%"? perc_tp_long4   : i_tp4_sw  =="ATR"? atr_tp_long4   : rr_tp_long4  tp_short1  = i_tp1_sw  =="%"? perc_tp_short1  : i_tp1_sw  =="ATR"? atr_tp_short1  : rr_tp_short1 tp_short2  = i_tp2_sw  =="%"? perc_tp_short2  : i_tp2_sw  =="ATR"? atr_tp_short2  : rr_tp_short2 tp_short3  = i_tp3_sw  =="%"? perc_tp_short3  : i_tp3_sw  =="ATR"? atr_tp_short3  : rr_tp_short3 tp_short4  = i_tp4_sw  =="%"? perc_tp_short4  : i_tp4_sw  =="ATR"? atr_tp_short4  : rr_tp_short4 // Take Profits %sum_tp4 = perc_tp1 + perc_tp2 + perc_tp3 + perc_tp4sum_tp3 = perc_tp1 + perc_tp2 + perc_tp3sum_tp2 = perc_tp1 + perc_tp2sum_tp1 = perc_tp1last_tp_long = i_tp4>0 and sum_tp4>=100?  tp_long4 :  i_tp3>0 and sum_tp3>=100?  tp_long3 :  i_tp2>0 and sum_tp2>=100?  tp_long2 :  i_tp1>0 and sum_tp1>=100?  tp_long1 : na last_tp_short = i_tp4>0 and sum_tp4>=100?  tp_short4 :  i_tp3>0 and sum_tp3>=100?  tp_short3 :  i_tp2>0 and sum_tp2>=100?  tp_short2 :  i_tp1>0 and sum_tp1>=100?  tp_short1 : na // Position Adjustmentlong_sl  = low <sl_long[1]  and pos[1]==1short_sl = high>sl_short[1] and pos[1]==-1final_long_tp  = high>last_tp_long [1]  and pos[1]==1final_short_tp = low <last_tp_short[1] and pos[1]==-1if ((long_sl or final_long_tp) and not shortCond) or ((short_sl or final_short_tp) and not longCond)    pos:=0//  Strategy Backtest Limiting Algorithmi_startTime = input.time(defval = timestamp("01 Sep 2002 13:30 +0000"), title = "Backtesting Start Time")i_endTime   = input.time(defval = timestamp("30 Sep 2099 19:30 +0000"), title = "Backtesting End Time"  )timeCond   = (time > i_startTime) and (time < i_endTime)equity = strategy.initial_capital + strategy.netprofitif equity>0 and timeCond    if longCond        strategy.entry("long" , strategy.long )    if shortCond        strategy.entry("short", strategy.short)    strategy.exit("SL/TP1 ", from_entry = "long" , stop=sl_long , limit=tp_long1 , qty_percent=perc_tp1 , when=perc_tp1 >0)strategy.exit("SL/TP2 ", from_entry = "long" , stop=sl_long , limit=tp_long2 , qty_percent=perc_tp2 , when=perc_tp2 >0)strategy.exit("SL/TP3 ", from_entry = "long" , stop=sl_long , limit=tp_long3 , qty_percent=perc_tp3 , when=perc_tp3 >0)strategy.exit("SL/TP4 ", from_entry = "long" , stop=sl_long , limit=tp_long4 , qty_percent=perc_tp4 , when=perc_tp4 >0)strategy.exit("SL/TP1 ", from_entry = "short" , stop=sl_short, limit=tp_short1 , qty_percent=perc_tp1 , when=perc_tp1 >0)strategy.exit("SL/TP2 ", from_entry = "short" , stop=sl_short, limit=tp_short2 , qty_percent=perc_tp2 , when=perc_tp2 >0)strategy.exit("SL/TP3 ", from_entry = "short" , stop=sl_short, limit=tp_short3 , qty_percent=perc_tp3 , when=perc_tp3 >0)strategy.exit("SL/TP4 ", from_entry = "short" , stop=sl_short, limit=tp_short4 , qty_percent=perc_tp4 , when=perc_tp4 >0)show_sltp = input(true, title="Show SL/TP Lines on Chart")plot(show_sltp and pos== 1? tp_long1  : na, color=color.green, style=plot.style_linebr, title="TP Long 1")plot(show_sltp and pos== 1? tp_long2  : na, color=color.green, style=plot.style_linebr, title="TP Long 2")plot(show_sltp and pos== 1? tp_long3  : na, color=color.green, style=plot.style_linebr, title="TP Long 3")plot(show_sltp and pos== 1? tp_long4  : na, color=color.green, style=plot.style_linebr, title="TP Long 4")plot(show_sltp and pos==-1? tp_short1 : na, color=color.green, style=plot.style_linebr, title="TP Short 1")plot(show_sltp and pos==-1? tp_short2 : na, color=color.green, style=plot.style_linebr, title="TP Short 2")plot(show_sltp and pos==-1? tp_short3 : na, color=color.green, style=plot.style_linebr, title="TP Short 3")plot(show_sltp and pos==-1? tp_short4 : na, color=color.green, style=plot.style_linebr, title="TP Short 4")plot(show_sltp and pos== 1? sl_long  : na, color=color.red  , style=plot.style_linebr, title="SL Long ")plot(show_sltp and pos==-1? sl_short : na, color=color.red  , style=plot.style_linebr, title="SL Short")plotshape(longCond,  textcolor=#ffffff, color=color.lime, style=shape.labelup  , title="Buy" , text="Buy" , location=location.belowbar,  offset=0, size=size.small)plotshape(shortCond, textcolor=#ffffff, color=color.red , style=shape.labeldown, title="Sell", text="Sell", location=location.abovebar,  offset=0, size=size.small)longCond_txt         = input("", title='Alert Msg: LONG Entry', group='Alert Message', inline='longCond_txt      ')shortCond_txt        = input("", title='Alert Msg: SHORT Entry', group='Alert Message', inline='shortCond_txt     ')long_sltp_txt        = input("", title='Alert Msg: LONG SL/TP', group='Alert Message', inline='long_sltp_txt       ')short_sltp_txt       = input("", title='Alert Msg: SHORT SL/TP', group='Alert Message', inline='short_sltp_txt      ')if longCond    alert(longCond_txt, alert.freq_once_per_bar_close)if shortCond    alert(shortCond_txt, alert.freq_once_per_bar_close)if long_sl  or final_long_tp    alert(long_sltp_txt, alert.freq_once_per_bar_close)if short_sl or final_short_tp    alert(short_sltp_txt, alert.freq_once_per_bar_close)