Pine Script v4 · Strategy
TradingView Alerts to MT4 MT5 - Forex, indices, commodities
A Pine Script v4 strategy built on SMA or Stoch (4), SMA (k, 3) 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 20000 contracts and pays 0.00003 commission. 5 settings; defaults include Take Profit Level 400, Take Partial Profit Level 150 and K 13.
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 TradingView Alerts to MT4 MT5 - Forex, indices, commodities repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 124 of 124 trades.
- How did TradingView Alerts to MT4 MT5 - Forex, indices, commodities do on BTCUSDT 1D with default settings?
- −699,283.00%
- From 26 Jan 2024 to 21 Oct 2026, over 382 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can TradingView Alerts to MT4 MT5 - Forex, indices, commodities 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 TradingView Alerts to MT4 MT5 - Forex, indices, commodities have?
- 4
- alertsyntax_golong; alertsyntax_goshort; closepart tradeid=' + tostring(trade_id) + ' part=0.5; closepart tradeid=' + tostring(trade_id) + ' part=0.5.
- Does TradingView Alerts to MT4 MT5 - Forex, indices, commodities use a stop loss?
- Yes
- strategy.exit sets a stop on line 52, 55.
BTCUSDT · 1D · default settings
- %K
- %D
- HLine
- HLine
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −699,283.00%
- −$6,992,830.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 382
- 380 won · 2 lost
- Profitable
- 99.5%
- of closed trades
- Profit factor
- 0.60
- gross profit ÷ gross loss
- Max drawdown
- 3,138.68%
- −$20,746,200.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
2 settings have no label
In the settings dialog TakeProfitLevel (line 14), TakePartialProfitLevel (line 15) 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 50, 53. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 26
transp = on line 26. v5 folds the transparency into the colour with color.new(c, transp).
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, barssince → ta.barssince, tostring → str.tostring.
- 2 strategy calls use the when = argument (line 50, 53). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 382 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 20: sma → ta.sma
- Line 20: stoch → ta.stoch
- Line 21: sma → ta.sma
- Line 26: transp = 75 → color.new(color.purple, 75)
- Line 27: crossover → ta.crossover
21 more edits
- Line 28: crossunder → ta.crossunder
- Line 32: pivothigh → ta.pivothigh
- Line 33: pivotlow → ta.pivotlow
- Line 36: valuewhen → ta.valuewhen
- Line 37: valuewhen → ta.valuewhen
- Line 47: barssince → ta.barssince
- Line 47: barssince → ta.barssince
- Line 47: crossover → ta.crossover
- Line 47: valuewhen → ta.valuewhen
- Line 48: barssince → ta.barssince
- Line 48: barssince → ta.barssince
- Line 48: crossunder → ta.crossunder
- Line 48: valuewhen → ta.valuewhen
- Line 57: tostring → str.tostring
- Line 57: tostring → str.tostring
- Line 57: tostring → str.tostring
- Line 60: tostring → str.tostring
- Line 60: tostring → str.tostring
- Line 60: tostring → str.tostring
- Line 63: tostring → str.tostring
- Line 66: tostring → str.tostring
⋯// © Peter_O-//@version=4+//@version=5strategy(title="TradingView Alerts to MT4 MT5 - Forex, indices, commodities, stocks, crypto", commission_type=strategy.commission.cash_per_contract, commission_value=0.00003, overlay=false, default_qty_value=20000, initial_capital=1000)⋯smoothK = 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)⋯h1 = hline(20)-fill(h0, h1, color=color.purple, transp=75)+fill(h0, h1, color=color.new(color.purple, 75))-GoLong=crossover(k,d) and k<80 and year>2009+GoLong=ta.crossover(k,d) and k<80 and year>2009-GoShort=crossunder(k,d) and k>20 and year>2009+GoShort=ta.crossunder(k,d) and k>20 and year>2009AlertTest=open>close or open<close or open==close⋯// **** 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 ⋯ trade_id:=trade_id+1-TakePartialProfitLong = barssince(GoLong)<barssince(GoShort) and crossover(high,(valuewhen(GoLong,close,0)+TakePartialProfitLevel*syminfo.mintick))+TakePartialProfitLong = ta.barssince(GoLong)<ta.barssince(GoShort) and ta.crossover(high,(ta.valuewhen(GoLong,close,0)+TakePartialProfitLevel*syminfo.mintick))-TakePartialProfitShort = barssince(GoLong)>barssince(GoShort) and crossunder(low,(valuewhen(GoShort,close,0)-TakePartialProfitLevel*syminfo.mintick))+TakePartialProfitShort = ta.barssince(GoLong)>ta.barssince(GoShort) and ta.crossunder(low,(ta.valuewhen(GoShort,close,0)-TakePartialProfitLevel*syminfo.mintick))// } End of Trade counter and partial closing mechanism⋯if GoLong- alertsyntax_golong='long slprice=' + tostring(stoploss_long) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel)+ alertsyntax_golong='long slprice=' + str.tostring(stoploss_long) + ' tradeid=' + str.tostring(trade_id) + ' tp=' + str.tostring(TakeProfitLevel) alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)if GoShort- alertsyntax_goshort='short slprice=' + tostring(stoploss_short) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel)+ alertsyntax_goshort='short slprice=' + str.tostring(stoploss_short) + ' tradeid=' + str.tostring(trade_id) + ' tp=' + str.tostring(TakeProfitLevel) alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)if TakePartialProfitLong- alertsyntax_closepartlong='closepart tradeid=' + tostring(trade_id) + ' part=0.5'+ alertsyntax_closepartlong='closepart tradeid=' + str.tostring(trade_id) + ' part=0.5' alert(message=alertsyntax_closepartlong, freq=alert.freq_once_per_bar_close)if TakePartialProfitShort- alertsyntax_closepartshort='closepart tradeid=' + tostring(trade_id) + ' part=0.5'+ alertsyntax_closepartshort='closepart tradeid=' + str.tostring(trade_id) + ' part=0.5' alert(message=alertsyntax_closepartshort, freq=alert.freq_once_per_bar_close)Same 382 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 14: input() → input.int()
- Line 15: input() → input.int()
- Line 17: input() → input.int()
- Line 18: input() → input.int()
- Line 19: input() → input.int()
- Line 50: when = GoLong → if block
- Line 53: when = GoShort → if block
⋯ -TakeProfitLevel=input(400)+TakeProfitLevel=input.int(400)-TakePartialProfitLevel=input(150)+TakePartialProfitLevel=input.int(150)// **** Entries logic **** {-periodK = input(13, title="K", minval=1)+periodK = input.int(13, title="K", minval=1)-periodD = input(3, title="D", minval=1)+periodD = input.int(3, title="D", minval=1)-smoothK = input(4, title="Smooth", minval=1)+smoothK = input.int(4, title="Smooth", minval=1)k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)⋯// } End of Trade counter and partial closing mechanism-strategy.entry("Long", strategy.long, when=GoLong)+if GoLong+ strategy.entry("Long", strategy.long)strategy.exit("XPartLong", from_entry="Long", qty_percent=50, profit=TakePartialProfitLevel)strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)-strategy.entry("Short", strategy.short, when=GoShort)+if GoShort+ strategy.entry("Short", strategy.short)strategy.exit("XPartShort", from_entry="Short", qty_percent=50, profit=TakePartialProfitLevel)⋯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: 382 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 - Forex, indices, commodities, stocks, crypto", commission_type=strategy.commission.cash_per_contract, commission_value=0.00003, overlay=false, default_qty_value=20000, 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 |
| Take Partial Profit Level (no label in the script) | 150 | int | TakePartialProfitLong TakePartialProfitShort exit XPartLong exit XPartShort |
| K | 13 | int · min 1 | k |
| D | 3 | int · min 1 | d |
| Smooth | 4 | int · min 1 | k |
What it calculates
- SMA / Stoch (
sma,ta.smain v5)stoch(close, high, low, periodK), Smooth (4)k · line 20 - SMA (
sma,ta.smain v5)k, D (3)d · line 21 - Pivothigh (
pivothigh,ta.pivothighin v5)high, 1, 1piv_high · line 32 - Pivotlow (
pivotlow,ta.pivotlowin v5)low, 1, 1piv_low · line 33 - Valuewhen (
valuewhen,ta.valuewhenin v5)piv_low, piv_low, 0pl · line 36 - Valuewhen (
valuewhen,ta.valuewhenin v5)piv_high, piv_high, 0ph · line 37
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 and year>2009 | On | 50 |
| Exit XPartLong limit | every bar | On | 51 |
| Exit XLong stop and limit | every bar | On | 52 |
| Open Short short | GoShortcrossunder(k,d) and k>20 and year>2009 | On | 53 |
| Exit XPartShort limit | every bar | On | 54 |
| Exit XShort stop and limit | every bar | On | 55 |
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 | 58 |
| (no title) | alert | alertsyntax_goshort | 61 |
| (no title) | alert | closepart tradeid=' + tostring(trade_id) + ' part=0.5 | 64 |
| (no title) | alert | closepart tradeid=' + tostring(trade_id) + ' part=0.5 | 67 |
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 | −699,283.0% | +102.5% | 382 | 99% | 0.60 | 3,138.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −6,442,630.0% | +5.5% | 337 | 98% | 0.12 | 4,057.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +14,097.4% | +9.8% | 376 | 97% | 1.01 | 3,769.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −328,183.0% | +8.4% | 370 | 92% | 0.74 | 80,750.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +117,858.0% | +16.7% | 348 | 79% | 1.21 | 91.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +46,851.3% | +21.5% | 261 | 56% | 1.22 | 11,490.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +436,287.0% | +148.3% | 385 | 93% | 1.84 | 12,800.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −58,089.5% | +17.1% | 315 | 72% | 0.91 | 673.8% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (K 7, D 2) made +1,000,980.0% before 26 Dec 2025 and +478,490.0% after it, against +340,993.0% for the defaults. 72% of the 32 combinations made money in-sample and 88% out-of-sample.
| D ↓ · K → | 7 | 8 | 9 | 11 | 13 | 16 | 18 | 22 |
|---|---|---|---|---|---|---|---|---|
| 2 | +1,000,980% | +945,979% | +890,981% | +890,981% | +448,979% | +918,480% | −23,589% | +753,484% |
| 3 | +309,153% | +758,983% | +709,485% | −543,275% | −1,040,280% | +208,955% | +203,455% | +153,957% |
| 4 | −548,775% | −570,775% | −631,273% | +615,987% | +137,457% | +555,488% | +343,179% | +527,988% |
| 5 | +659,986% | +593,987% | +566,488% | −931,753% | +63,988% | +516,989% | −19,690% | −590,720% |
| D ↓ · K → | 7 | 8 | 9 | 11 | 13 | 16 | 18 | 22 |
|---|---|---|---|---|---|---|---|---|
| 2 | +478,490% | +467,490% | +450,990% | +461,990% | +384,992% | +373,992% | +384,992% | +373,992% |
| 3 | +406,991% | +384,992% | +401,491% | +362,992% | +340,993% | +318,993% | +313,493% | −600,956% |
| 4 | +340,993% | +340,993% | +329,993% | −511,277% | +285,994% | +263,994% | −9,706,390% | −8,920,120% |
| 5 | +318,993% | +285,994% | +313,493% | +296,994% | +263,994% | +247,495% | +258,494% | +225,495% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 140 | 99% | −$1,230,080.00 |
| Sideways market | 136 | 100% | $3,739,920.00 |
| Falling market | 106 | 99% | −$9,502,660.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
11,938,100.0%
The 95th percentile of the worst drawdown when the same 382 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 687.1% to 11,938,100.0%; the tick is what actually happened, 2,167.5%. Order luck alone moves it this much.
The first 150 of 382 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Feb 2024 51,880.00 | 16 Feb 2024 51,878.50 | 0 | $14,999.40 |
| short | 16 Feb 2024 51,880.00 | 16 Feb 2024 51,876.00 | 0 | $39,999.40 |
| long | 27 Feb 2024 54,476.50 | 27 Feb 2024 54,478.00 | 0 | $14,999.40 |
| long | 27 Feb 2024 54,476.50 | 27 Feb 2024 54,480.50 | 0 | $39,999.40 |
| short | 2 Mar 2024 62,387.90 | 2 Mar 2024 62,386.40 | 0 | $14,999.40 |
| short | 2 Mar 2024 62,387.90 | 2 Mar 2024 62,383.90 | 0 | $39,999.40 |
| short | 6 Mar 2024 63,724.00 | 6 Mar 2024 63,722.50 | 0 | $14,999.40 |
| short | 6 Mar 2024 63,724.00 | 6 Mar 2024 63,720.00 | 0 | $39,999.40 |
| short | 15 Mar 2024 71,388.90 | 15 Mar 2024 71,387.40 | 0 | $14,999.40 |
| short | 15 Mar 2024 71,388.90 | 15 Mar 2024 71,384.90 | 0 | $39,999.40 |
| long | 24 Mar 2024 63,990.00 | 24 Mar 2024 63,991.50 | 0 | $14,999.40 |
| long | 24 Mar 2024 63,990.00 | 24 Mar 2024 63,994.00 | 0 | $39,999.40 |
| short | 3 Apr 2024 65,464.00 | 3 Apr 2024 65,462.50 | 0 | $14,999.40 |
| short | 3 Apr 2024 65,464.00 | 3 Apr 2024 65,460.00 | 0 | $39,999.40 |
| long | 7 Apr 2024 68,896.00 | 7 Apr 2024 68,897.50 | 0 | $14,999.40 |
| long | 7 Apr 2024 68,896.00 | 7 Apr 2024 68,900.00 | 0 | $39,999.40 |
| short | 13 Apr 2024 67,116.50 | 13 Apr 2024 67,115.00 | 0 | $14,999.40 |
| short | 13 Apr 2024 67,116.50 | 13 Apr 2024 67,112.50 | 0 | $39,999.40 |
| long | 20 Apr 2024 63,818.00 | 20 Apr 2024 63,819.50 | 0 | $14,999.40 |
| long | 20 Apr 2024 63,818.00 | 20 Apr 2024 63,822.00 | 0 | $39,999.40 |
| short | 28 Apr 2024 63,462.00 | 28 Apr 2024 63,460.50 | 0 | $14,999.40 |
| short | 28 Apr 2024 63,462.00 | 28 Apr 2024 63,458.00 | 0 | $39,999.40 |
| long | 29 Apr 2024 63,118.60 | 29 Apr 2024 63,120.10 | 0 | $14,999.40 |
| long | 29 Apr 2024 63,118.60 | 29 Apr 2024 63,122.60 | 0 | $39,999.40 |
| short | 30 Apr 2024 63,866.00 | 30 Apr 2024 64,370.00 | 0 | −$5,040,000.00 |
| short | 30 Apr 2024 63,866.00 | 30 Apr 2024 63,864.50 | 0 | $14,999.40 |
| long | 5 May 2024 63,892.00 | 5 May 2024 63,893.50 | 0 | $14,999.40 |
| long | 5 May 2024 63,892.00 | 5 May 2024 63,896.00 | 0 | $39,999.40 |
| short | 9 May 2024 61,193.00 | 9 May 2024 61,191.50 | 0 | $14,999.40 |
| short | 9 May 2024 61,193.00 | 9 May 2024 61,189.00 | 0 | $39,999.40 |
| long | 14 May 2024 62,940.10 | 14 May 2024 62,941.60 | 0 | $14,999.40 |
| long | 14 May 2024 62,940.10 | 14 May 2024 62,944.10 | 0 | $39,999.40 |
| short | 23 May 2024 69,166.60 | 23 May 2024 69,165.10 | 0 | $14,999.40 |
| short | 23 May 2024 69,166.60 | 23 May 2024 69,162.60 | 0 | $39,999.40 |
| long | 28 May 2024 69,436.40 | 28 May 2024 69,437.90 | 0 | $14,999.40 |
| long | 28 May 2024 69,436.40 | 28 May 2024 69,440.40 | 0 | $39,999.40 |
| short | 29 May 2024 68,398.40 | 29 May 2024 68,396.90 | 0 | $14,999.40 |
| short | 29 May 2024 68,398.40 | 29 May 2024 68,394.40 | 0 | $39,999.40 |
| long | 4 Jun 2024 68,809.90 | 4 Jun 2024 68,811.40 | 0 | $14,999.40 |
| long | 4 Jun 2024 68,809.90 | 4 Jun 2024 68,813.90 | 0 | $39,999.40 |
| short | 9 Jun 2024 69,310.50 | 9 Jun 2024 69,309.00 | 0 | $14,999.40 |
| short | 9 Jun 2024 69,310.50 | 9 Jun 2024 69,306.50 | 0 | $39,999.40 |
| long | 18 Jun 2024 66,504.30 | 18 Jun 2024 66,505.80 | 0 | $14,999.40 |
| long | 18 Jun 2024 66,504.30 | 18 Jun 2024 66,508.30 | 0 | $39,999.40 |
| long | 26 Jun 2024 61,806.00 | 26 Jun 2024 61,807.50 | 0 | $14,999.40 |
| long | 26 Jun 2024 61,806.00 | 26 Jun 2024 61,810.00 | 0 | $39,999.40 |
| short | 30 Jun 2024 60,986.70 | 30 Jun 2024 60,985.20 | 0 | $14,999.40 |
| short | 30 Jun 2024 60,986.70 | 30 Jun 2024 60,982.70 | 0 | $39,999.40 |
| long | 1 Jul 2024 62,772.00 | 1 Jul 2024 62,773.50 | 0 | $14,999.40 |
| long | 1 Jul 2024 62,772.00 | 1 Jul 2024 62,776.00 | 0 | $39,999.40 |
| short | 5 Jul 2024 57,050.00 | 5 Jul 2024 57,048.50 | 0 | $14,999.40 |
| short | 5 Jul 2024 57,050.00 | 5 Jul 2024 57,046.00 | 0 | $39,999.40 |
| long | 9 Jul 2024 56,714.60 | 9 Jul 2024 56,716.10 | 0 | $14,999.40 |
| long | 9 Jul 2024 56,714.60 | 9 Jul 2024 56,718.60 | 0 | $39,999.40 |
| short | 20 Jul 2024 66,660.00 | 20 Jul 2024 66,658.50 | 0 | $14,999.40 |
| short | 20 Jul 2024 66,660.00 | 20 Jul 2024 66,656.00 | 0 | $39,999.40 |
| short | 24 Jul 2024 65,936.00 | 24 Jul 2024 65,934.50 | 0 | $14,999.40 |
| short | 24 Jul 2024 65,936.00 | 24 Jul 2024 65,932.00 | 0 | $39,999.40 |
| short | 30 Jul 2024 66,784.70 | 30 Jul 2024 66,783.20 | 0 | $14,999.40 |
| short | 30 Jul 2024 66,784.70 | 30 Jul 2024 66,780.70 | 0 | $39,999.40 |
| long | 7 Aug 2024 56,022.00 | 7 Aug 2024 56,023.50 | 0 | $14,999.40 |
| long | 7 Aug 2024 56,022.00 | 7 Aug 2024 56,026.00 | 0 | $39,999.40 |
| short | 19 Aug 2024 58,427.30 | 19 Aug 2024 58,425.80 | 0 | $14,999.40 |
| short | 19 Aug 2024 58,427.30 | 19 Aug 2024 58,423.30 | 0 | $39,999.40 |
| long | 22 Aug 2024 61,156.00 | 22 Aug 2024 61,157.50 | 0 | $14,999.40 |
| long | 22 Aug 2024 61,156.00 | 22 Aug 2024 61,160.00 | 0 | $39,999.40 |
| short | 28 Aug 2024 59,415.00 | 28 Aug 2024 59,413.50 | 0 | $14,999.40 |
| short | 28 Aug 2024 59,415.00 | 28 Aug 2024 59,411.00 | 0 | $39,999.40 |
| long | 5 Sep 2024 57,970.90 | 5 Sep 2024 57,972.40 | 0 | $14,999.40 |
| long | 5 Sep 2024 57,970.90 | 5 Sep 2024 57,974.90 | 0 | $39,999.40 |
| long | 8 Sep 2024 54,160.90 | 8 Sep 2024 54,162.40 | 0 | $14,999.40 |
| long | 8 Sep 2024 54,160.90 | 8 Sep 2024 54,164.90 | 0 | $39,999.40 |
| short | 18 Sep 2024 60,314.00 | 18 Sep 2024 60,312.50 | 0 | $14,999.40 |
| short | 18 Sep 2024 60,314.00 | 18 Sep 2024 60,310.00 | 0 | $39,999.40 |
| short | 23 Sep 2024 63,578.80 | 23 Sep 2024 63,577.30 | 0 | $14,999.40 |
| short | 23 Sep 2024 63,578.80 | 23 Sep 2024 63,574.80 | 0 | $39,999.40 |
| short | 1 Oct 2024 63,327.60 | 1 Oct 2024 63,326.10 | 0 | $14,999.40 |
| short | 1 Oct 2024 63,327.60 | 1 Oct 2024 63,323.60 | 0 | $39,999.40 |
| long | 6 Oct 2024 62,058.00 | 6 Oct 2024 62,059.50 | 0 | $14,999.40 |
| long | 6 Oct 2024 62,058.00 | 6 Oct 2024 62,062.00 | 0 | $39,999.40 |
| short | 10 Oct 2024 60,636.00 | 10 Oct 2024 60,634.50 | 0 | $14,999.40 |
| short | 10 Oct 2024 60,636.00 | 10 Oct 2024 60,632.00 | 0 | $39,999.40 |
| long | 12 Oct 2024 62,540.00 | 12 Oct 2024 62,541.50 | 0 | $14,999.40 |
| long | 12 Oct 2024 62,540.00 | 12 Oct 2024 62,544.00 | 0 | $39,999.40 |
| short | 22 Oct 2024 67,377.50 | 22 Oct 2024 67,376.00 | 0 | $14,999.40 |
| short | 22 Oct 2024 67,377.50 | 22 Oct 2024 67,373.50 | 0 | $39,999.40 |
| long | 29 Oct 2024 69,962.20 | 29 Oct 2024 69,963.70 | 0 | $14,999.40 |
| long | 29 Oct 2024 69,962.20 | 29 Oct 2024 69,966.20 | 0 | $39,999.40 |
| short | 2 Nov 2024 69,496.00 | 2 Nov 2024 69,494.50 | 0 | $14,999.40 |
| short | 2 Nov 2024 69,496.00 | 2 Nov 2024 69,492.00 | 0 | $39,999.40 |
| long | 7 Nov 2024 75,572.00 | 7 Nov 2024 75,573.50 | 0 | $14,999.40 |
| long | 7 Nov 2024 75,572.00 | 7 Nov 2024 75,576.00 | 0 | $39,999.40 |
| short | 14 Nov 2024 90,375.20 | 14 Nov 2024 90,373.70 | 0 | $14,999.40 |
| short | 14 Nov 2024 90,375.20 | 14 Nov 2024 90,371.20 | 0 | $39,999.40 |
| short | 25 Nov 2024 97,900.10 | 25 Nov 2024 97,898.60 | 0 | $14,999.40 |
| short | 25 Nov 2024 97,900.10 | 25 Nov 2024 97,896.10 | 0 | $39,999.40 |
| long | 30 Nov 2024 97,460.00 | 30 Nov 2024 97,461.50 | 0 | $14,999.40 |
| long | 30 Nov 2024 97,460.00 | 1 Dec 2024 97,464.00 | 1 | $39,999.40 |
| short | 3 Dec 2024 95,840.60 | 3 Dec 2024 95,839.10 | 0 | $14,999.40 |
| short | 3 Dec 2024 95,840.60 | 3 Dec 2024 95,836.60 | 0 | $39,999.40 |
| long | 5 Dec 2024 98,587.30 | 5 Dec 2024 98,588.80 | 0 | $14,999.40 |
| long | 5 Dec 2024 98,587.30 | 5 Dec 2024 98,591.30 | 0 | $39,999.40 |
| short | 6 Dec 2024 96,945.60 | 6 Dec 2024 96,944.10 | 0 | $14,999.40 |
| short | 6 Dec 2024 96,945.60 | 6 Dec 2024 96,941.60 | 0 | $39,999.40 |
| long | 8 Dec 2024 99,832.00 | 8 Dec 2024 99,833.50 | 0 | $14,999.40 |
| long | 8 Dec 2024 99,832.00 | 8 Dec 2024 99,836.00 | 0 | $39,999.40 |
| short | 9 Dec 2024 101,110.00 | 9 Dec 2024 101,108.00 | 0 | $14,999.40 |
| short | 9 Dec 2024 101,110.00 | 9 Dec 2024 101,106.00 | 0 | $39,999.40 |
| long | 14 Dec 2024 101,424.00 | 14 Dec 2024 101,426.00 | 0 | $14,999.40 |
| long | 14 Dec 2024 101,424.00 | 14 Dec 2024 101,428.00 | 0 | $39,999.40 |
| short | 19 Dec 2024 100,204.00 | 19 Dec 2024 100,203.00 | 0 | $14,999.40 |
| short | 19 Dec 2024 100,204.00 | 19 Dec 2024 100,200.00 | 0 | $39,999.40 |
| long | 25 Dec 2024 98,663.60 | 25 Dec 2024 98,665.10 | 0 | $14,999.40 |
| long | 25 Dec 2024 98,663.60 | 25 Dec 2024 98,667.60 | 0 | $39,999.40 |
| short | 28 Dec 2024 94,299.00 | 28 Dec 2024 94,297.50 | 0 | $14,999.40 |
| short | 28 Dec 2024 94,299.00 | 28 Dec 2024 94,295.00 | 0 | $39,999.40 |
| long | 2 Jan 2025 94,591.80 | 2 Jan 2025 94,593.30 | 0 | $14,999.40 |
| long | 2 Jan 2025 94,591.80 | 2 Jan 2025 94,595.80 | 0 | $39,999.40 |
| short | 8 Jan 2025 96,954.60 | 8 Jan 2025 96,953.10 | 0 | $14,999.40 |
| short | 8 Jan 2025 96,954.60 | 8 Jan 2025 96,950.60 | 0 | $39,999.40 |
| long | 14 Jan 2025 94,536.10 | 14 Jan 2025 94,537.60 | 0 | $14,999.40 |
| long | 14 Jan 2025 94,536.10 | 14 Jan 2025 94,540.10 | 0 | $39,999.40 |
| short | 21 Jan 2025 102,260.00 | 21 Jan 2025 102,259.00 | 0 | $14,999.40 |
| short | 21 Jan 2025 102,260.00 | 21 Jan 2025 102,256.00 | 0 | $39,999.40 |
| long | 25 Jan 2025 104,871.00 | 25 Jan 2025 104,872.00 | 0 | $14,999.40 |
| long | 25 Jan 2025 104,871.00 | 25 Jan 2025 104,875.00 | 0 | $39,999.40 |
| short | 26 Jan 2025 104,747.00 | 26 Jan 2025 104,745.00 | 0 | $14,999.40 |
| short | 26 Jan 2025 104,747.00 | 26 Jan 2025 104,743.00 | 0 | $39,999.40 |
| long | 5 Feb 2025 97,763.10 | 5 Feb 2025 97,764.60 | 0 | $14,999.40 |
| long | 5 Feb 2025 97,763.10 | 5 Feb 2025 97,767.10 | 0 | $39,999.40 |
| short | 8 Feb 2025 96,506.80 | 8 Feb 2025 96,505.30 | 0 | $14,999.40 |
| short | 8 Feb 2025 96,506.80 | 8 Feb 2025 96,502.80 | 0 | $39,999.40 |
| long | 11 Feb 2025 97,430.80 | 11 Feb 2025 97,432.30 | 0 | $14,999.40 |
| long | 11 Feb 2025 97,430.80 | 11 Feb 2025 97,434.80 | 0 | $39,999.40 |
| short | 12 Feb 2025 95,778.20 | 12 Feb 2025 95,776.70 | 0 | $14,999.40 |
| short | 12 Feb 2025 95,778.20 | 12 Feb 2025 95,774.20 | 0 | $39,999.40 |
| long | 13 Feb 2025 97,870.00 | 13 Feb 2025 97,871.50 | 0 | $14,999.40 |
| long | 13 Feb 2025 97,870.00 | 13 Feb 2025 97,874.00 | 0 | $39,999.40 |
| short | 17 Feb 2025 96,118.10 | 17 Feb 2025 96,116.60 | 0 | $14,999.40 |
| short | 17 Feb 2025 96,118.10 | 17 Feb 2025 96,114.10 | 0 | $39,999.40 |
| long | 21 Feb 2025 98,305.00 | 21 Feb 2025 98,306.50 | 0 | $14,999.40 |
| long | 21 Feb 2025 98,305.00 | 21 Feb 2025 98,309.00 | 0 | $39,999.40 |
| short | 25 Feb 2025 91,552.90 | 25 Feb 2025 91,551.40 | 0 | $14,999.40 |
| short | 25 Feb 2025 91,552.90 | 25 Feb 2025 91,548.90 | 0 | $39,999.40 |
| long | 1 Mar 2025 84,349.90 | 1 Mar 2025 84,351.40 | 0 | $14,999.40 |
| long | 1 Mar 2025 84,349.90 | 1 Mar 2025 84,353.90 | 0 | $39,999.40 |
| short | 7 Mar 2025 89,931.90 | 7 Mar 2025 89,930.40 | 0 | $14,999.40 |
| short | 7 Mar 2025 89,931.90 | 7 Mar 2025 89,927.90 | 0 | $39,999.40 |
| long | 8 Mar 2025 86,801.70 | 8 Mar 2025 86,803.20 | 0 | $14,999.40 |
| long | 8 Mar 2025 86,801.70 | 8 Mar 2025 86,805.70 | 0 | $39,999.40 |
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 |
|---|---|---|---|---|---|
| TradingView Alerts to MT4 MT5 - Forex, indices, commodities this page | — | v4 strategy | −699,283.0% | 382 | 3,138.7% |
| Alert(), alertcondition() or strategy alerts- by Peter_O | sma pivothigh pivotlow valuewhen | 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% |
| 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 43 ms | Yes 1,000 bars in 49 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 - Forex, indices, commodities, stocks, crypto", commission_type=strategy.commission.cash_per_contract, commission_value=0.00003, overlay=false, default_qty_value=20000, initial_capital=1000)//// This script was created for educational purposes only.// It is showing how to use Alerts-Straight-From-Strategies and// dynamic variables in TradingView alerts.// And how to auto-execute them in Forex, indices, commodities markets// // (This method will also work with stocks and crypto - anything your // broker is offering via their MT4/MT5 platform). TakeProfitLevel=input(400)TakePartialProfitLevel=input(150)// **** Entries logic **** {periodK = input(13, title="K", minval=1)periodD = input(3, title="D", minval=1)smoothK = 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<80 and year>2009GoShort=crossunder(k,d) and k>20 and year>2009AlertTest=open>close or open<close or open==close// } 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 : ph// } End of Pivot-points and stop-loss logic// **** Trade counter and partial closing mechanism **** {var int trade_id=0if GoLong or GoShort trade_id:=trade_id+1TakePartialProfitLong = barssince(GoLong)<barssince(GoShort) and crossover(high,(valuewhen(GoLong,close,0)+TakePartialProfitLevel*syminfo.mintick))TakePartialProfitShort = barssince(GoLong)>barssince(GoShort) and crossunder(low,(valuewhen(GoShort,close,0)-TakePartialProfitLevel*syminfo.mintick))// } End of Trade counter and partial closing mechanismstrategy.entry("Long", strategy.long, when=GoLong)strategy.exit("XPartLong", from_entry="Long", qty_percent=50, profit=TakePartialProfitLevel)strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)strategy.entry("Short", strategy.short, when=GoShort)strategy.exit("XPartShort", from_entry="Short", qty_percent=50, profit=TakePartialProfitLevel)strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)if GoLong alertsyntax_golong='long slprice=' + tostring(stoploss_long) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel) alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)if GoShort alertsyntax_goshort='short slprice=' + tostring(stoploss_short) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel) alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)if TakePartialProfitLong alertsyntax_closepartlong='closepart tradeid=' + tostring(trade_id) + ' part=0.5' alert(message=alertsyntax_closepartlong, freq=alert.freq_once_per_bar_close)if TakePartialProfitShort alertsyntax_closepartshort='closepart tradeid=' + tostring(trade_id) + ' part=0.5' alert(message=alertsyntax_closepartshort, freq=alert.freq_once_per_bar_close)