Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$76,390,000$2,025Equity from $1,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.
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

Verified

Same 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)⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Take Profit Level (no label in the script)400intalertsyntax_golong alertsyntax_goshort exit XLong exit XShort
Entry distance for stop orders10intalertsyntax_golong alertsyntax_goshort entry Long entry Short

What it calculates

  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, periodK), smoothKk · line 14
  • SMA (sma, ta.sma in v5)k, periodDd · line 15
  • Pivothigh (pivothigh, ta.pivothigh in v5)high, 1, 1piv_high · line 25
  • Pivotlow (pivotlow, ta.pivotlow in v5)low, 1, 1piv_low · line 26
  • Valuewhen (valuewhen, ta.valuewhen in v5)piv_low, piv_low, 0pl · line 29
  • Valuewhen (valuewhen, ta.valuewhen in 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.

closecloseprice datahighhighprice datalowlowprice dataentry_distanceEntry distance for stop…setting · 10TakeProfitLevelTake Profit Levelsetting · 400kSMA / Stoch→ kdSMA→ dpiv_highPivothigh→ piv_highpiv_lowPivotlow→ piv_lowplValuewhen→ plphValuewhen→ phstoploss_longstoploss_longvaluestoploss_shortstoploss_shortvaluealertsyntax_golongalertsyntax_golongvaluealertsyntax_goshortalertsyntax_goshortvalueGoLongGoLongconditionGoShortGoShortconditionCancelLongCancelLongconditionCancelShortCancelShortconditionentry:LongOpen Longstrategy.entryexit:XLongexit XLongstrategy.exitcancel:Longcancel Longstrategy.cancelentry:ShortOpen Shortstrategy.entryexit:XShortexit XShortstrategy.exitcancel:Shortcancel Shortstrategy.cancelplot:35stoploss_longplotplot:36stoploss_shortplotplotshape:41plotshapeplotshapeplotshape:42plotshapeplotshapealert:51alertalertalert:54alertalertalert:57alertalertalert:60alertalert

Order rules

OrderFires whenBy defaultLine
Open Long longGoLongcrossover(k,d) and k<80On43
Exit XLong stop and limitevery barOn44
cancel LongCancelLongcrossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0On45
Open Short shortGoShortcrossunder(k,d) and k>20On46
Exit XShort stop and limitevery barOn47
cancel ShortCancelShortcrossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0On48

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

Alerts

AlertCallMessageLine
(no title)alertalertsyntax_golong51
(no title)alertalertsyntax_goshort54
(no title)alertcancel long57
(no title)alertcancel short60

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

62/62trades 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+7,640,000.0%+102.5%191100%—919.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2,505,200.0%+5.5%16799%1.6167.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−2,025,900.0%+9.8%18895%0.786,517.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2,229,200.0%+8.4%18788%1.51359,700.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+563,900.0%+16.7%18666%1.14193.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+455,500.0%+21.5%15044%1.4427,500.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2,202,000.0%+148.3%19387%1.4965,000.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−327,300.0%+17.1%17056%0.92371.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 barsTradesWonP&L
Rising market70100%$28,000,000.00
Sideways market68100%$27,200,000.00
Falling market53100%$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.

0%1%
The first 150 of 191 trades
SideEntryExitBarsP&L
short16 Feb 2024 51,879.9016 Feb 2024 51,875.900$400,000.00
long27 Feb 2024 54,476.6027 Feb 2024 54,480.600$400,000.00
short2 Mar 2024 62,387.802 Mar 2024 62,383.800$400,000.00
short6 Mar 2024 63,723.906 Mar 2024 63,719.900$400,000.00
short15 Mar 2024 71,388.8015 Mar 2024 71,384.800$400,000.00
long24 Mar 2024 63,990.1024 Mar 2024 63,994.100$400,000.00
short3 Apr 2024 65,463.903 Apr 2024 65,459.900$400,000.00
long7 Apr 2024 68,896.107 Apr 2024 68,900.100$400,000.00
short13 Apr 2024 67,116.4013 Apr 2024 67,112.400$400,000.00
long20 Apr 2024 63,818.1020 Apr 2024 63,822.100$400,000.00
short28 Apr 2024 63,461.9028 Apr 2024 63,457.900$400,000.00
long29 Apr 2024 63,118.7029 Apr 2024 63,122.700$400,000.00
short30 Apr 2024 63,865.9030 Apr 2024 63,861.900$400,000.00
long5 May 2024 63,892.105 May 2024 63,896.100$400,000.00
short9 May 2024 61,192.909 May 2024 61,188.900$400,000.00
long14 May 2024 62,940.2014 May 2024 62,944.200$400,000.00
short23 May 2024 69,166.5023 May 2024 69,162.500$400,000.00
long28 May 2024 69,436.5028 May 2024 69,440.500$400,000.00
short29 May 2024 68,398.3029 May 2024 68,394.300$400,000.00
long4 Jun 2024 68,810.004 Jun 2024 68,814.000$400,000.00
short9 Jun 2024 69,310.409 Jun 2024 69,306.400$400,000.00
long18 Jun 2024 66,504.4018 Jun 2024 66,508.400$400,000.00
long26 Jun 2024 61,806.1026 Jun 2024 61,810.100$400,000.00
short30 Jun 2024 60,986.6030 Jun 2024 60,982.600$400,000.00
long1 Jul 2024 62,772.101 Jul 2024 62,776.100$400,000.00
short5 Jul 2024 57,049.905 Jul 2024 57,045.900$400,000.00
long9 Jul 2024 56,714.709 Jul 2024 56,718.700$400,000.00
short20 Jul 2024 66,659.9020 Jul 2024 66,655.900$400,000.00
short24 Jul 2024 65,935.9024 Jul 2024 65,931.900$400,000.00
short30 Jul 2024 66,784.6030 Jul 2024 66,780.600$400,000.00
long7 Aug 2024 56,022.107 Aug 2024 56,026.100$400,000.00
short19 Aug 2024 58,427.3019 Aug 2024 58,423.300$400,000.00
long22 Aug 2024 61,156.1022 Aug 2024 61,160.100$400,000.00
short28 Aug 2024 59,414.9028 Aug 2024 59,410.900$400,000.00
long5 Sep 2024 57,971.005 Sep 2024 57,975.000$400,000.00
long8 Sep 2024 54,161.008 Sep 2024 54,165.000$400,000.00
short18 Sep 2024 60,313.9018 Sep 2024 60,309.900$400,000.00
short23 Sep 2024 63,578.7023 Sep 2024 63,574.700$400,000.00
short1 Oct 2024 63,327.501 Oct 2024 63,323.500$400,000.00
long6 Oct 2024 62,058.106 Oct 2024 62,062.100$400,000.00
short10 Oct 2024 60,635.9010 Oct 2024 60,631.900$400,000.00
long12 Oct 2024 62,540.1012 Oct 2024 62,544.100$400,000.00
short22 Oct 2024 67,377.4022 Oct 2024 67,373.400$400,000.00
long29 Oct 2024 69,962.3029 Oct 2024 69,966.300$400,000.00
short2 Nov 2024 69,495.902 Nov 2024 69,491.900$400,000.00
long7 Nov 2024 75,572.107 Nov 2024 75,576.100$400,000.00
short14 Nov 2024 90,375.1014 Nov 2024 90,371.100$400,000.00
short25 Nov 2024 97,899.9025 Nov 2024 97,895.900$400,000.00
long30 Nov 2024 97,460.101 Dec 2024 97,464.101$400,000.00
short3 Dec 2024 95,840.503 Dec 2024 95,836.500$400,000.00
long5 Dec 2024 98,587.405 Dec 2024 98,591.400$400,000.00
short6 Dec 2024 96,945.506 Dec 2024 96,941.500$400,000.00
long8 Dec 2024 99,832.108 Dec 2024 99,836.100$400,000.00
short9 Dec 2024 101,109.009 Dec 2024 101,105.000$400,000.00
long14 Dec 2024 101,424.0014 Dec 2024 101,428.000$400,000.00
short19 Dec 2024 100,204.0019 Dec 2024 100,200.000$400,000.00
long25 Dec 2024 98,663.7025 Dec 2024 98,667.700$400,000.00
short28 Dec 2024 94,298.9028 Dec 2024 94,294.900$400,000.00
long2 Jan 2025 94,591.902 Jan 2025 94,595.900$400,000.00
short8 Jan 2025 96,954.508 Jan 2025 96,950.500$400,000.00
long14 Jan 2025 94,536.2014 Jan 2025 94,540.200$400,000.00
short21 Jan 2025 102,260.0021 Jan 2025 102,256.000$400,000.00
long25 Jan 2025 104,871.0025 Jan 2025 104,875.000$400,000.00
short26 Jan 2025 104,747.0026 Jan 2025 104,743.000$400,000.00
long5 Feb 2025 97,763.205 Feb 2025 97,767.200$400,000.00
short8 Feb 2025 96,506.708 Feb 2025 96,502.700$400,000.00
long11 Feb 2025 97,430.9011 Feb 2025 97,434.900$400,000.00
short12 Feb 2025 95,778.1012 Feb 2025 95,774.100$400,000.00
long13 Feb 2025 97,870.1013 Feb 2025 97,874.100$400,000.00
short17 Feb 2025 96,118.0017 Feb 2025 96,114.000$400,000.00
long21 Feb 2025 98,305.1021 Feb 2025 98,309.100$400,000.00
short25 Feb 2025 91,552.8025 Feb 2025 91,548.800$400,000.00
long1 Mar 2025 84,350.001 Mar 2025 84,354.000$400,000.00
short7 Mar 2025 89,931.807 Mar 2025 89,927.800$400,000.00
long8 Mar 2025 86,801.908 Mar 2025 86,805.900$400,000.00
short10 Mar 2025 80,734.3010 Mar 2025 80,730.300$400,000.00
long14 Mar 2025 81,115.9014 Mar 2025 81,119.900$400,000.00
short28 Mar 2025 87,231.9028 Mar 2025 87,227.900$400,000.00
long3 Apr 2025 82,516.403 Apr 2025 82,520.400$400,000.00
short6 Apr 2025 83,537.906 Apr 2025 83,533.900$400,000.00
long8 Apr 2025 79,163.308 Apr 2025 79,167.300$400,000.00
short9 Apr 2025 76,322.309 Apr 2025 76,318.300$400,000.00
long10 Apr 2025 82,615.3010 Apr 2025 82,619.300$400,000.00
short27 Apr 2025 94,627.9027 Apr 2025 94,623.900$400,000.00
short4 May 2025 95,856.304 May 2025 95,852.300$400,000.00
long9 May 2025 103,262.009 May 2025 103,266.000$400,000.00
short13 May 2025 102,791.0013 May 2025 102,787.000$400,000.00
short24 May 2025 107,318.0024 May 2025 107,314.000$400,000.00
long28 May 2025 108,938.0028 May 2025 108,942.000$400,000.00
short30 May 2025 105,590.0030 May 2025 105,586.000$400,000.00
long4 Jun 2025 105,377.004 Jun 2025 105,381.000$400,000.00
short5 Jun 2025 104,697.005 Jun 2025 104,693.000$400,000.00
long8 Jun 2025 105,552.008 Jun 2025 105,556.000$400,000.00
short14 Jun 2025 106,066.0014 Jun 2025 106,062.000$400,000.00
long24 Jun 2025 105,334.0024 Jun 2025 105,338.000$400,000.00
short2 Jul 2025 105,681.002 Jul 2025 105,677.000$400,000.00
short4 Jul 2025 109,585.004 Jul 2025 109,581.000$400,000.00
short7 Jul 2025 109,204.007 Jul 2025 109,200.000$400,000.00
long10 Jul 2025 111,234.0010 Jul 2025 111,238.000$400,000.00
short15 Jul 2025 119,841.0015 Jul 2025 119,837.000$400,000.00
long23 Jul 2025 119,955.0023 Jul 2025 119,959.000$400,000.00
short24 Jul 2025 118,756.0024 Jul 2025 118,752.000$400,000.00
long28 Jul 2025 119,416.0028 Jul 2025 119,420.000$400,000.00
short1 Aug 2025 115,764.001 Aug 2025 115,760.000$400,000.00
long5 Aug 2025 115,055.005 Aug 2025 115,059.000$400,000.00
short15 Aug 2025 118,295.0015 Aug 2025 118,291.000$400,000.00
long24 Aug 2025 115,438.0024 Aug 2025 115,442.000$400,000.00
long29 Aug 2025 112,567.0029 Aug 2025 112,571.000$400,000.00
short31 Aug 2025 108,816.0031 Aug 2025 108,812.000$400,000.00
long3 Sep 2025 111,240.003 Sep 2025 111,244.000$400,000.00
short15 Sep 2025 115,268.0015 Sep 2025 115,264.000$400,000.00
short20 Sep 2025 115,632.0020 Sep 2025 115,628.000$400,000.00
long29 Sep 2025 112,164.0029 Sep 2025 112,168.000$400,000.00
short7 Oct 2025 124,658.007 Oct 2025 124,654.000$400,000.00
long16 Oct 2025 110,763.0016 Oct 2025 110,767.000$400,000.00
short17 Oct 2025 108,194.0017 Oct 2025 108,190.000$400,000.00
long21 Oct 2025 110,532.0021 Oct 2025 110,536.000$400,000.00
short30 Oct 2025 110,021.0030 Oct 2025 110,017.000$400,000.00
long9 Nov 2025 102,313.009 Nov 2025 102,317.000$400,000.00
short14 Nov 2025 99,691.9014 Nov 2025 99,687.900$400,000.00
long19 Nov 2025 92,960.9019 Nov 2025 92,964.900$400,000.00
long22 Nov 2025 85,129.5022 Nov 2025 85,133.500$400,000.00
short2 Dec 2025 86,285.902 Dec 2025 86,281.900$400,000.00
long3 Dec 2025 91,278.003 Dec 2025 91,282.000$400,000.00
short7 Dec 2025 89,236.707 Dec 2025 89,232.700$400,000.00
long10 Dec 2025 92,678.9010 Dec 2025 92,682.900$400,000.00
short14 Dec 2025 90,239.9014 Dec 2025 90,235.900$400,000.00
long20 Dec 2025 88,137.0020 Dec 2025 88,141.000$400,000.00
short25 Dec 2025 87,669.4025 Dec 2025 87,665.400$400,000.00
long26 Dec 2025 87,225.4026 Dec 2025 87,229.400$400,000.00
short1 Jan 2026 87,648.101 Jan 2026 87,644.100$400,000.00
long3 Jan 2026 89,995.203 Jan 2026 89,999.200$400,000.00
short8 Jan 2026 91,364.108 Jan 2026 91,360.100$400,000.00
long14 Jan 2026 95,414.1014 Jan 2026 95,418.100$400,000.00
short18 Jan 2026 95,147.7018 Jan 2026 95,143.700$400,000.00
long25 Jan 2026 89,225.4025 Jan 2026 89,229.400$400,000.00
long28 Jan 2026 89,250.1028 Jan 2026 89,254.100$400,000.00
short1 Feb 2026 78,741.001 Feb 2026 78,737.000$400,000.00
long3 Feb 2026 78,738.703 Feb 2026 78,742.700$400,000.00
long7 Feb 2026 70,580.407 Feb 2026 70,584.400$400,000.00
short12 Feb 2026 67,082.4012 Feb 2026 67,078.400$400,000.00
long14 Feb 2026 68,854.1014 Feb 2026 68,858.100$400,000.00
short20 Feb 2026 67,003.6020 Feb 2026 66,999.600$400,000.00
long26 Feb 2026 67,988.1026 Feb 2026 67,992.100$400,000.00
short2 Mar 2026 65,776.402 Mar 2026 65,772.400$400,000.00
long3 Mar 2026 68,830.203 Mar 2026 68,834.200$400,000.00
short7 Mar 2026 68,113.907 Mar 2026 68,109.900$400,000.00
long11 Mar 2026 69,948.7011 Mar 2026 69,952.700$400,000.00
short19 Mar 2026 71,246.4019 Mar 2026 71,242.400$400,000.00
long26 Mar 2026 71,336.6026 Mar 2026 71,340.600$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.

ScriptSharesTypeNetTradesMax drawdown
Alert(), alertcondition() or strategy alerts- this page—v4 strategy+7,640,000.0%191919.9%
Quantitative Trend Strategy- Uptrend long by CheatCode1sma pivothigh pivotlow valuewhenv5 strategy+5.9%2832.8%
Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_Osma pivothigh pivotlow valuewhenv5 strategy−9,857,600.0%1914,436.8%
TradingView Alerts to MT4 MT5 - Forex, indices, commodities by Peter_Osma pivothigh pivotlow valuewhenv4 strategy−699,283.0%3823,138.7%
Qullamaggie Breakout V2 by millerrhsma pivothigh pivotlow valuewhenv5 strategy+35.4%3316.9%
TradePro's 2 EMA + Stoch RSI + ATR Strategy by PtGamblersma pivothigh pivotlow valuewhenv5 strategy−2.7%1822.0%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 38 msYes 1,000 bars in 75 msNot measured
PineTSNo 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)