Pine Script v4 · Strategy
Alert(), alertcondition() or strategy alerts-
A Pine Script v4 strategy built on SMA or Stoch (smoothK), SMA (k, periodD) and Pivothigh (high, 1). 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 100000 contracts and pays 0.00003 commission. 2 settings; defaults include Take Profit Level 400 and Entry distance for stop orders 10.
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 Alert(), alertcondition() or strategy alerts- repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 62 of 62 trades.
- Can Alert(), alertcondition() or strategy alerts- 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.
- What alerts does Alert(), alertcondition() or strategy alerts- have?
- 4
- alertsyntax_golong; alertsyntax_goshort; cancel long; cancel short.
- Does Alert(), alertcondition() or strategy alerts- use a stop loss?
- Yes
- strategy.exit sets a stop on line 44, 47.
- Does Alert(), alertcondition() or strategy alerts- run in Zeal Terminal?
- Yes
- It compiles in 38 ms and runs 1,000 bars in 75 ms, in the browser.
BTCUSDT · 1D · default settings
- stoploss_long
- stoploss_short
- Shape
- Shape
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +7,640,000.00%
- $76,400,000.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 191
- 191 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 919.86%
- −$176,622,000.00
One run with the author's default settings, $1,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.
-
Note
1 setting has no label
In the settings dialog TakeProfitLevel (line 9) shows 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 43, 45, 46, 48. 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 sma → ta.sma, stoch → ta.stoch, crossover → ta.crossover, crossunder → ta.crossunder, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, valuewhen → ta.valuewhen, tostring → str.tostring.
- 4 strategy calls use the when = argument (line 43, 45, 46, 48). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 191 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 14: sma → ta.sma
- Line 14: stoch → ta.stoch
- Line 15: sma → ta.sma
- Line 21: crossover → ta.crossover
- Line 22: crossunder → ta.crossunder
12 more edits
- Line 25: pivothigh → ta.pivothigh
- Line 26: pivotlow → ta.pivotlow
- Line 29: valuewhen → ta.valuewhen
- Line 30: valuewhen → ta.valuewhen
- Line 38: crossunder → ta.crossunder
- Line 39: crossover → ta.crossover
- Line 50: tostring → str.tostring
- Line 50: tostring → str.tostring
- Line 50: tostring → str.tostring
- Line 53: tostring → str.tostring
- Line 53: tostring → str.tostring
- Line 53: tostring → str.tostring
⋯// © Peter_O-//@version=4+//@version=5strategy(title="TradingView Alerts to MT4 MT5 example with cancelling pending orders", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=true, default_qty_value=100000, initial_capital=1000)⋯smoothK = 4 //input(4, title="Smooth", minval=1)-k = sma(stoch(close, high, low, periodK), smoothK)+k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)-d = sma(k, periodD)+d = ta.sma(k, periodD)// plot(k, title="%K", color=color.blue)⋯// fill(h0, h1, color=color.purple, transp=75)-GoLong=crossover(k,d) and k<80+GoLong=ta.crossover(k,d) and k<80-GoShort=crossunder(k,d) and k>20+GoShort=ta.crossunder(k,d) and k>20// } End of entries logic// **** Pivot-points and stop-loss logic **** {-piv_high = pivothigh(high,1,1)+piv_high = ta.pivothigh(high,1,1)-piv_low = pivotlow(low,1,1)+piv_low = ta.pivotlow(low,1,1)var float stoploss_long=lowvar float stoploss_short=high-pl=valuewhen(piv_low,piv_low,0)+pl=ta.valuewhen(piv_low,piv_low,0)-ph=valuewhen(piv_high,piv_high,0)+ph=ta.valuewhen(piv_high,piv_high,0)if GoLong ⋯// } End of Pivot-points and stop-loss logic-CancelLong=crossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0+CancelLong=ta.crossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0-CancelShort=crossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0+CancelShort=ta.crossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0entry_distance=input(10, title="Entry distance for stop orders")⋯if GoLong- alertsyntax_golong='long offset=' + tostring(entry_distance) + ' slprice=' + tostring(stoploss_long) + ' tp=' + tostring(TakeProfitLevel)+ alertsyntax_golong='long offset=' + str.tostring(entry_distance) + ' slprice=' + str.tostring(stoploss_long) + ' tp=' + str.tostring(TakeProfitLevel) alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)if GoShort- alertsyntax_goshort='short offset=' + tostring(-entry_distance) + ' slprice=' + tostring(stoploss_short) + ' tp=' + tostring(TakeProfitLevel)+ alertsyntax_goshort='short offset=' + str.tostring(-entry_distance) + ' slprice=' + str.tostring(stoploss_short) + ' tp=' + str.tostring(TakeProfitLevel) alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)⋯Same 191 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 9: input() → input.int()
- Line 40: input() → input.int()
- Line 43: when = GoLong → if block
- Line 45: when = CancelLong → if block
- Line 46: when = GoShort → if block
- Line 48: when = CancelShort → if block
⋯// All the way to brokers for execution-TakeProfitLevel=input(400)+TakeProfitLevel=input.int(400)// **** Entries logic **** {⋯CancelShort=ta.crossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0-entry_distance=input(10, title="Entry distance for stop orders")+entry_distance=input.int(10, title="Entry distance for stop orders")plotshape(CancelLong ? stoploss_long[1]-10*syminfo.mintick : na, location=location.absolute, style=shape.labelup, color=color.gray, textcolor=color.white, text="cancel\nlong", size=size.tiny)plotshape(CancelShort ? stoploss_short[1]+10*syminfo.mintick : na, location=location.absolute, style=shape.labeldown, color=color.gray, textcolor=color.white, text="cancel\nshort", size=size.tiny)-strategy.entry("Long", strategy.long, when=GoLong, stop=close+entry_distance*syminfo.mintick)+if GoLong+ strategy.entry("Long", strategy.long, stop=close+entry_distance*syminfo.mintick)strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)-strategy.cancel("Long", when = CancelLong)+if CancelLong+ strategy.cancel("Long")-strategy.entry("Short", strategy.short, when=GoShort, stop=close-entry_distance*syminfo.mintick)+if GoShort+ strategy.entry("Short", strategy.short, stop=close-entry_distance*syminfo.mintick)strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)-strategy.cancel("Short", when = CancelShort)+if CancelShort+ strategy.cancel("Short")if GoLong⋯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: 191 before, 0 after on BTCUSDT 1D, 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.
⋯// © Peter_O-//@version=5+//@version=6strategy(title="TradingView Alerts to MT4 MT5 example with cancelling pending orders", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=true, default_qty_value=100000, initial_capital=1000)⋯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 |
|---|---|---|---|
| Take Profit Level (no label in the script) | 400 | int | alertsyntax_golong alertsyntax_goshort exit XLong exit XShort |
| Entry distance for stop orders | 10 | int | alertsyntax_golong alertsyntax_goshort entry Long entry Short |
What it calculates
- SMA / Stoch (
sma,ta.smain v5)stoch(close, high, low, periodK), smoothKk · line 14 - SMA (
sma,ta.smain v5)k, periodDd · line 15 - Pivothigh (
pivothigh,ta.pivothighin v5)high, 1, 1piv_high · line 25 - Pivotlow (
pivotlow,ta.pivotlowin v5)low, 1, 1piv_low · line 26 - Valuewhen (
valuewhen,ta.valuewhenin v5)piv_low, piv_low, 0pl · line 29 - Valuewhen (
valuewhen,ta.valuewhenin v5)piv_high, piv_high, 0ph · line 30
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | GoLongcrossover(k,d) and k<80 | On | 43 |
| Exit XLong stop and limit | every bar | On | 44 |
| cancel Long | CancelLongcrossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0 | On | 45 |
| Open Short short | GoShortcrossunder(k,d) and k>20 | On | 46 |
| Exit XShort stop and limit | every bar | On | 47 |
| cancel Short | CancelShortcrossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0 | On | 48 |
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 | alertsyntax_golong | 51 |
| (no title) | alert | alertsyntax_goshort | 54 |
| (no title) | alert | cancel long | 57 |
| (no title) | alert | cancel short | 60 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +7,640,000.0% | +102.5% | 191 | 100% | — | 919.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2,505,200.0% | +5.5% | 167 | 99% | 1.61 | 67.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −2,025,900.0% | +9.8% | 188 | 95% | 0.78 | 6,517.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2,229,200.0% | +8.4% | 187 | 88% | 1.51 | 359,700.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +563,900.0% | +16.7% | 186 | 66% | 1.14 | 193.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +455,500.0% | +21.5% | 150 | 44% | 1.44 | 27,500.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +2,202,000.0% | +148.3% | 193 | 87% | 1.49 | 65,000.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −327,300.0% | +17.1% | 170 | 56% | 0.92 | 371.7% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 70 | 100% | $28,000,000.00 |
| Sideways market | 68 | 100% | $27,200,000.00 |
| Falling market | 53 | 100% | $21,200,000.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 191 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
The first 150 of 191 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Feb 2024 51,879.90 | 16 Feb 2024 51,875.90 | 0 | $400,000.00 |
| long | 27 Feb 2024 54,476.60 | 27 Feb 2024 54,480.60 | 0 | $400,000.00 |
| short | 2 Mar 2024 62,387.80 | 2 Mar 2024 62,383.80 | 0 | $400,000.00 |
| short | 6 Mar 2024 63,723.90 | 6 Mar 2024 63,719.90 | 0 | $400,000.00 |
| short | 15 Mar 2024 71,388.80 | 15 Mar 2024 71,384.80 | 0 | $400,000.00 |
| long | 24 Mar 2024 63,990.10 | 24 Mar 2024 63,994.10 | 0 | $400,000.00 |
| short | 3 Apr 2024 65,463.90 | 3 Apr 2024 65,459.90 | 0 | $400,000.00 |
| long | 7 Apr 2024 68,896.10 | 7 Apr 2024 68,900.10 | 0 | $400,000.00 |
| short | 13 Apr 2024 67,116.40 | 13 Apr 2024 67,112.40 | 0 | $400,000.00 |
| long | 20 Apr 2024 63,818.10 | 20 Apr 2024 63,822.10 | 0 | $400,000.00 |
| short | 28 Apr 2024 63,461.90 | 28 Apr 2024 63,457.90 | 0 | $400,000.00 |
| long | 29 Apr 2024 63,118.70 | 29 Apr 2024 63,122.70 | 0 | $400,000.00 |
| short | 30 Apr 2024 63,865.90 | 30 Apr 2024 63,861.90 | 0 | $400,000.00 |
| long | 5 May 2024 63,892.10 | 5 May 2024 63,896.10 | 0 | $400,000.00 |
| short | 9 May 2024 61,192.90 | 9 May 2024 61,188.90 | 0 | $400,000.00 |
| long | 14 May 2024 62,940.20 | 14 May 2024 62,944.20 | 0 | $400,000.00 |
| short | 23 May 2024 69,166.50 | 23 May 2024 69,162.50 | 0 | $400,000.00 |
| long | 28 May 2024 69,436.50 | 28 May 2024 69,440.50 | 0 | $400,000.00 |
| short | 29 May 2024 68,398.30 | 29 May 2024 68,394.30 | 0 | $400,000.00 |
| long | 4 Jun 2024 68,810.00 | 4 Jun 2024 68,814.00 | 0 | $400,000.00 |
| short | 9 Jun 2024 69,310.40 | 9 Jun 2024 69,306.40 | 0 | $400,000.00 |
| long | 18 Jun 2024 66,504.40 | 18 Jun 2024 66,508.40 | 0 | $400,000.00 |
| long | 26 Jun 2024 61,806.10 | 26 Jun 2024 61,810.10 | 0 | $400,000.00 |
| short | 30 Jun 2024 60,986.60 | 30 Jun 2024 60,982.60 | 0 | $400,000.00 |
| long | 1 Jul 2024 62,772.10 | 1 Jul 2024 62,776.10 | 0 | $400,000.00 |
| short | 5 Jul 2024 57,049.90 | 5 Jul 2024 57,045.90 | 0 | $400,000.00 |
| long | 9 Jul 2024 56,714.70 | 9 Jul 2024 56,718.70 | 0 | $400,000.00 |
| short | 20 Jul 2024 66,659.90 | 20 Jul 2024 66,655.90 | 0 | $400,000.00 |
| short | 24 Jul 2024 65,935.90 | 24 Jul 2024 65,931.90 | 0 | $400,000.00 |
| short | 30 Jul 2024 66,784.60 | 30 Jul 2024 66,780.60 | 0 | $400,000.00 |
| long | 7 Aug 2024 56,022.10 | 7 Aug 2024 56,026.10 | 0 | $400,000.00 |
| short | 19 Aug 2024 58,427.30 | 19 Aug 2024 58,423.30 | 0 | $400,000.00 |
| long | 22 Aug 2024 61,156.10 | 22 Aug 2024 61,160.10 | 0 | $400,000.00 |
| short | 28 Aug 2024 59,414.90 | 28 Aug 2024 59,410.90 | 0 | $400,000.00 |
| long | 5 Sep 2024 57,971.00 | 5 Sep 2024 57,975.00 | 0 | $400,000.00 |
| long | 8 Sep 2024 54,161.00 | 8 Sep 2024 54,165.00 | 0 | $400,000.00 |
| short | 18 Sep 2024 60,313.90 | 18 Sep 2024 60,309.90 | 0 | $400,000.00 |
| short | 23 Sep 2024 63,578.70 | 23 Sep 2024 63,574.70 | 0 | $400,000.00 |
| short | 1 Oct 2024 63,327.50 | 1 Oct 2024 63,323.50 | 0 | $400,000.00 |
| long | 6 Oct 2024 62,058.10 | 6 Oct 2024 62,062.10 | 0 | $400,000.00 |
| short | 10 Oct 2024 60,635.90 | 10 Oct 2024 60,631.90 | 0 | $400,000.00 |
| long | 12 Oct 2024 62,540.10 | 12 Oct 2024 62,544.10 | 0 | $400,000.00 |
| short | 22 Oct 2024 67,377.40 | 22 Oct 2024 67,373.40 | 0 | $400,000.00 |
| long | 29 Oct 2024 69,962.30 | 29 Oct 2024 69,966.30 | 0 | $400,000.00 |
| short | 2 Nov 2024 69,495.90 | 2 Nov 2024 69,491.90 | 0 | $400,000.00 |
| long | 7 Nov 2024 75,572.10 | 7 Nov 2024 75,576.10 | 0 | $400,000.00 |
| short | 14 Nov 2024 90,375.10 | 14 Nov 2024 90,371.10 | 0 | $400,000.00 |
| short | 25 Nov 2024 97,899.90 | 25 Nov 2024 97,895.90 | 0 | $400,000.00 |
| long | 30 Nov 2024 97,460.10 | 1 Dec 2024 97,464.10 | 1 | $400,000.00 |
| short | 3 Dec 2024 95,840.50 | 3 Dec 2024 95,836.50 | 0 | $400,000.00 |
| long | 5 Dec 2024 98,587.40 | 5 Dec 2024 98,591.40 | 0 | $400,000.00 |
| short | 6 Dec 2024 96,945.50 | 6 Dec 2024 96,941.50 | 0 | $400,000.00 |
| long | 8 Dec 2024 99,832.10 | 8 Dec 2024 99,836.10 | 0 | $400,000.00 |
| short | 9 Dec 2024 101,109.00 | 9 Dec 2024 101,105.00 | 0 | $400,000.00 |
| long | 14 Dec 2024 101,424.00 | 14 Dec 2024 101,428.00 | 0 | $400,000.00 |
| short | 19 Dec 2024 100,204.00 | 19 Dec 2024 100,200.00 | 0 | $400,000.00 |
| long | 25 Dec 2024 98,663.70 | 25 Dec 2024 98,667.70 | 0 | $400,000.00 |
| short | 28 Dec 2024 94,298.90 | 28 Dec 2024 94,294.90 | 0 | $400,000.00 |
| long | 2 Jan 2025 94,591.90 | 2 Jan 2025 94,595.90 | 0 | $400,000.00 |
| short | 8 Jan 2025 96,954.50 | 8 Jan 2025 96,950.50 | 0 | $400,000.00 |
| long | 14 Jan 2025 94,536.20 | 14 Jan 2025 94,540.20 | 0 | $400,000.00 |
| short | 21 Jan 2025 102,260.00 | 21 Jan 2025 102,256.00 | 0 | $400,000.00 |
| long | 25 Jan 2025 104,871.00 | 25 Jan 2025 104,875.00 | 0 | $400,000.00 |
| short | 26 Jan 2025 104,747.00 | 26 Jan 2025 104,743.00 | 0 | $400,000.00 |
| long | 5 Feb 2025 97,763.20 | 5 Feb 2025 97,767.20 | 0 | $400,000.00 |
| short | 8 Feb 2025 96,506.70 | 8 Feb 2025 96,502.70 | 0 | $400,000.00 |
| long | 11 Feb 2025 97,430.90 | 11 Feb 2025 97,434.90 | 0 | $400,000.00 |
| short | 12 Feb 2025 95,778.10 | 12 Feb 2025 95,774.10 | 0 | $400,000.00 |
| long | 13 Feb 2025 97,870.10 | 13 Feb 2025 97,874.10 | 0 | $400,000.00 |
| short | 17 Feb 2025 96,118.00 | 17 Feb 2025 96,114.00 | 0 | $400,000.00 |
| long | 21 Feb 2025 98,305.10 | 21 Feb 2025 98,309.10 | 0 | $400,000.00 |
| short | 25 Feb 2025 91,552.80 | 25 Feb 2025 91,548.80 | 0 | $400,000.00 |
| long | 1 Mar 2025 84,350.00 | 1 Mar 2025 84,354.00 | 0 | $400,000.00 |
| short | 7 Mar 2025 89,931.80 | 7 Mar 2025 89,927.80 | 0 | $400,000.00 |
| long | 8 Mar 2025 86,801.90 | 8 Mar 2025 86,805.90 | 0 | $400,000.00 |
| short | 10 Mar 2025 80,734.30 | 10 Mar 2025 80,730.30 | 0 | $400,000.00 |
| long | 14 Mar 2025 81,115.90 | 14 Mar 2025 81,119.90 | 0 | $400,000.00 |
| short | 28 Mar 2025 87,231.90 | 28 Mar 2025 87,227.90 | 0 | $400,000.00 |
| long | 3 Apr 2025 82,516.40 | 3 Apr 2025 82,520.40 | 0 | $400,000.00 |
| short | 6 Apr 2025 83,537.90 | 6 Apr 2025 83,533.90 | 0 | $400,000.00 |
| long | 8 Apr 2025 79,163.30 | 8 Apr 2025 79,167.30 | 0 | $400,000.00 |
| short | 9 Apr 2025 76,322.30 | 9 Apr 2025 76,318.30 | 0 | $400,000.00 |
| long | 10 Apr 2025 82,615.30 | 10 Apr 2025 82,619.30 | 0 | $400,000.00 |
| short | 27 Apr 2025 94,627.90 | 27 Apr 2025 94,623.90 | 0 | $400,000.00 |
| short | 4 May 2025 95,856.30 | 4 May 2025 95,852.30 | 0 | $400,000.00 |
| long | 9 May 2025 103,262.00 | 9 May 2025 103,266.00 | 0 | $400,000.00 |
| short | 13 May 2025 102,791.00 | 13 May 2025 102,787.00 | 0 | $400,000.00 |
| short | 24 May 2025 107,318.00 | 24 May 2025 107,314.00 | 0 | $400,000.00 |
| long | 28 May 2025 108,938.00 | 28 May 2025 108,942.00 | 0 | $400,000.00 |
| short | 30 May 2025 105,590.00 | 30 May 2025 105,586.00 | 0 | $400,000.00 |
| long | 4 Jun 2025 105,377.00 | 4 Jun 2025 105,381.00 | 0 | $400,000.00 |
| short | 5 Jun 2025 104,697.00 | 5 Jun 2025 104,693.00 | 0 | $400,000.00 |
| long | 8 Jun 2025 105,552.00 | 8 Jun 2025 105,556.00 | 0 | $400,000.00 |
| short | 14 Jun 2025 106,066.00 | 14 Jun 2025 106,062.00 | 0 | $400,000.00 |
| long | 24 Jun 2025 105,334.00 | 24 Jun 2025 105,338.00 | 0 | $400,000.00 |
| short | 2 Jul 2025 105,681.00 | 2 Jul 2025 105,677.00 | 0 | $400,000.00 |
| short | 4 Jul 2025 109,585.00 | 4 Jul 2025 109,581.00 | 0 | $400,000.00 |
| short | 7 Jul 2025 109,204.00 | 7 Jul 2025 109,200.00 | 0 | $400,000.00 |
| long | 10 Jul 2025 111,234.00 | 10 Jul 2025 111,238.00 | 0 | $400,000.00 |
| short | 15 Jul 2025 119,841.00 | 15 Jul 2025 119,837.00 | 0 | $400,000.00 |
| long | 23 Jul 2025 119,955.00 | 23 Jul 2025 119,959.00 | 0 | $400,000.00 |
| short | 24 Jul 2025 118,756.00 | 24 Jul 2025 118,752.00 | 0 | $400,000.00 |
| long | 28 Jul 2025 119,416.00 | 28 Jul 2025 119,420.00 | 0 | $400,000.00 |
| short | 1 Aug 2025 115,764.00 | 1 Aug 2025 115,760.00 | 0 | $400,000.00 |
| long | 5 Aug 2025 115,055.00 | 5 Aug 2025 115,059.00 | 0 | $400,000.00 |
| short | 15 Aug 2025 118,295.00 | 15 Aug 2025 118,291.00 | 0 | $400,000.00 |
| long | 24 Aug 2025 115,438.00 | 24 Aug 2025 115,442.00 | 0 | $400,000.00 |
| long | 29 Aug 2025 112,567.00 | 29 Aug 2025 112,571.00 | 0 | $400,000.00 |
| short | 31 Aug 2025 108,816.00 | 31 Aug 2025 108,812.00 | 0 | $400,000.00 |
| long | 3 Sep 2025 111,240.00 | 3 Sep 2025 111,244.00 | 0 | $400,000.00 |
| short | 15 Sep 2025 115,268.00 | 15 Sep 2025 115,264.00 | 0 | $400,000.00 |
| short | 20 Sep 2025 115,632.00 | 20 Sep 2025 115,628.00 | 0 | $400,000.00 |
| long | 29 Sep 2025 112,164.00 | 29 Sep 2025 112,168.00 | 0 | $400,000.00 |
| short | 7 Oct 2025 124,658.00 | 7 Oct 2025 124,654.00 | 0 | $400,000.00 |
| long | 16 Oct 2025 110,763.00 | 16 Oct 2025 110,767.00 | 0 | $400,000.00 |
| short | 17 Oct 2025 108,194.00 | 17 Oct 2025 108,190.00 | 0 | $400,000.00 |
| long | 21 Oct 2025 110,532.00 | 21 Oct 2025 110,536.00 | 0 | $400,000.00 |
| short | 30 Oct 2025 110,021.00 | 30 Oct 2025 110,017.00 | 0 | $400,000.00 |
| long | 9 Nov 2025 102,313.00 | 9 Nov 2025 102,317.00 | 0 | $400,000.00 |
| short | 14 Nov 2025 99,691.90 | 14 Nov 2025 99,687.90 | 0 | $400,000.00 |
| long | 19 Nov 2025 92,960.90 | 19 Nov 2025 92,964.90 | 0 | $400,000.00 |
| long | 22 Nov 2025 85,129.50 | 22 Nov 2025 85,133.50 | 0 | $400,000.00 |
| short | 2 Dec 2025 86,285.90 | 2 Dec 2025 86,281.90 | 0 | $400,000.00 |
| long | 3 Dec 2025 91,278.00 | 3 Dec 2025 91,282.00 | 0 | $400,000.00 |
| short | 7 Dec 2025 89,236.70 | 7 Dec 2025 89,232.70 | 0 | $400,000.00 |
| long | 10 Dec 2025 92,678.90 | 10 Dec 2025 92,682.90 | 0 | $400,000.00 |
| short | 14 Dec 2025 90,239.90 | 14 Dec 2025 90,235.90 | 0 | $400,000.00 |
| long | 20 Dec 2025 88,137.00 | 20 Dec 2025 88,141.00 | 0 | $400,000.00 |
| short | 25 Dec 2025 87,669.40 | 25 Dec 2025 87,665.40 | 0 | $400,000.00 |
| long | 26 Dec 2025 87,225.40 | 26 Dec 2025 87,229.40 | 0 | $400,000.00 |
| short | 1 Jan 2026 87,648.10 | 1 Jan 2026 87,644.10 | 0 | $400,000.00 |
| long | 3 Jan 2026 89,995.20 | 3 Jan 2026 89,999.20 | 0 | $400,000.00 |
| short | 8 Jan 2026 91,364.10 | 8 Jan 2026 91,360.10 | 0 | $400,000.00 |
| long | 14 Jan 2026 95,414.10 | 14 Jan 2026 95,418.10 | 0 | $400,000.00 |
| short | 18 Jan 2026 95,147.70 | 18 Jan 2026 95,143.70 | 0 | $400,000.00 |
| long | 25 Jan 2026 89,225.40 | 25 Jan 2026 89,229.40 | 0 | $400,000.00 |
| long | 28 Jan 2026 89,250.10 | 28 Jan 2026 89,254.10 | 0 | $400,000.00 |
| short | 1 Feb 2026 78,741.00 | 1 Feb 2026 78,737.00 | 0 | $400,000.00 |
| long | 3 Feb 2026 78,738.70 | 3 Feb 2026 78,742.70 | 0 | $400,000.00 |
| long | 7 Feb 2026 70,580.40 | 7 Feb 2026 70,584.40 | 0 | $400,000.00 |
| short | 12 Feb 2026 67,082.40 | 12 Feb 2026 67,078.40 | 0 | $400,000.00 |
| long | 14 Feb 2026 68,854.10 | 14 Feb 2026 68,858.10 | 0 | $400,000.00 |
| short | 20 Feb 2026 67,003.60 | 20 Feb 2026 66,999.60 | 0 | $400,000.00 |
| long | 26 Feb 2026 67,988.10 | 26 Feb 2026 67,992.10 | 0 | $400,000.00 |
| short | 2 Mar 2026 65,776.40 | 2 Mar 2026 65,772.40 | 0 | $400,000.00 |
| long | 3 Mar 2026 68,830.20 | 3 Mar 2026 68,834.20 | 0 | $400,000.00 |
| short | 7 Mar 2026 68,113.90 | 7 Mar 2026 68,109.90 | 0 | $400,000.00 |
| long | 11 Mar 2026 69,948.70 | 11 Mar 2026 69,952.70 | 0 | $400,000.00 |
| short | 19 Mar 2026 71,246.40 | 19 Mar 2026 71,242.40 | 0 | $400,000.00 |
| long | 26 Mar 2026 71,336.60 | 26 Mar 2026 71,340.60 | 0 | $400,000.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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Alert(), alertcondition() or strategy alerts- this page | — | v4 strategy | +7,640,000.0% | 191 | 919.9% |
| Quantitative Trend Strategy- Uptrend long by CheatCode1 | sma pivothigh pivotlow valuewhen | v5 strategy | +5.9% | 28 | 32.8% |
| Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_O | sma pivothigh pivotlow valuewhen | v5 strategy | −9,857,600.0% | 191 | 4,436.8% |
| TradingView Alerts to MT4 MT5 - Forex, indices, commodities by Peter_O | sma pivothigh pivotlow valuewhen | v4 strategy | −699,283.0% | 382 | 3,138.7% |
| Qullamaggie Breakout V2 by millerrh | sma pivothigh pivotlow valuewhen | v5 strategy | +35.4% | 33 | 16.9% |
| TradePro's 2 EMA + Stoch RSI + ATR Strategy by PtGambler | sma pivothigh pivotlow valuewhen | v5 strategy | −2.7% | 18 | 22.0% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 38 ms | Yes 1,000 bars in 75 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“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/// © Peter_O//@version=4strategy(title="TradingView Alerts to MT4 MT5 example with cancelling pending orders", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=true, default_qty_value=100000, initial_capital=1000)// This script was created for educational purposes only.// It is showing how to create pending orders and cancel them// Together with syntax to send these events through TradingView alerts system// All the way to brokers for executionTakeProfitLevel=input(400)// **** Entries logic **** {periodK = 13 //input(13, title="K", minval=1)periodD = 3 //input(3, title="D", minval=1)smoothK = 4 //input(4, title="Smooth", minval=1)k = sma(stoch(close, high, low, periodK), smoothK)d = sma(k, periodD)// plot(k, title="%K", color=color.blue)// plot(d, title="%D", color=color.orange)// h0 = hline(80)// h1 = hline(20)// fill(h0, h1, color=color.purple, transp=75)GoLong=crossover(k,d) and k<80GoShort=crossunder(k,d) and k>20// } End of entries logic// **** Pivot-points and stop-loss logic **** {piv_high = pivothigh(high,1,1)piv_low = pivotlow(low,1,1)var float stoploss_long=lowvar float stoploss_short=highpl=valuewhen(piv_low,piv_low,0)ph=valuewhen(piv_high,piv_high,0)if GoLong stoploss_long := low<pl ? low : plif GoShort stoploss_short := high>ph ? high : phplot(stoploss_long, color=color.lime, title="stoploss_long")plot(stoploss_short, color=color.red, title="stoploss_short")// } End of Pivot-points and stop-loss logicCancelLong=crossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0CancelShort=crossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0entry_distance=input(10, title="Entry distance for stop orders")plotshape(CancelLong ? stoploss_long[1]-10*syminfo.mintick : na, location=location.absolute, style=shape.labelup, color=color.gray, textcolor=color.white, text="cancel\nlong", size=size.tiny)plotshape(CancelShort ? stoploss_short[1]+10*syminfo.mintick : na, location=location.absolute, style=shape.labeldown, color=color.gray, textcolor=color.white, text="cancel\nshort", size=size.tiny)strategy.entry("Long", strategy.long, when=GoLong, stop=close+entry_distance*syminfo.mintick)strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)strategy.cancel("Long", when = CancelLong)strategy.entry("Short", strategy.short, when=GoShort, stop=close-entry_distance*syminfo.mintick)strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)strategy.cancel("Short", when = CancelShort)if GoLong alertsyntax_golong='long offset=' + tostring(entry_distance) + ' slprice=' + tostring(stoploss_long) + ' tp=' + tostring(TakeProfitLevel) alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)if GoShort alertsyntax_goshort='short offset=' + tostring(-entry_distance) + ' slprice=' + tostring(stoploss_short) + ' tp=' + tostring(TakeProfitLevel) alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)if CancelLong alertsyntax_cancellong='cancel long' alert(message=alertsyntax_cancellong, freq=alert.freq_once_per_bar_close)if CancelShort alertsyntax_cancelshort='cancel short' alert(message=alertsyntax_cancelshort, freq=alert.freq_once_per_bar_close)