Pine Script v4 · Strategy
TrianglePoint strategy
A Pine Script v4 strategy built on Highest (close, 9), Lowest (close, 9) and EMA (close, 13). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is 3 contracts and pays no commission. 5 settings; defaults include Number of Bars 9, fast EMA 13 and slow EMA 65.
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 TrianglePoint strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did TrianglePoint strategy do on BTCUSDT 1D with default settings?
- +45.40%
- From 26 Jan 2024 to 21 Oct 2026, over 11 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can TrianglePoint strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does TrianglePoint strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does TrianglePoint strategy run in Zeal Terminal?
- Yes
- It compiles in 17 ms and runs 1,000 bars in 48 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +45.40%
- $4,540.47
- Buy and hold
- +102.5%
- same period
- Closed trades
- 11
- 2 won · 8 lost
- Profitable
- 18.2%
- of closed trades
- Profit factor
- 1.03
- gross profit ÷ gross loss
- Max drawdown
- 101.92%
- −$115,657.00
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.
-
Likely bug
ema(close, 200) ignores the settings line 40
Line 40 hard-codes 200 where line 38 uses “fast EMA”. Changing those settings moves one band but not this one.
ema(close, 200)ema(close, fastEMA) -
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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 57, 59, 66, 70. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 42
transp = on line 42, 43, 44. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 57
long = on line 57, 59. v5 writes it as direction = strategy.long or strategy.short.
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 highest → ta.highest, lowest → ta.lowest, ema → ta.ema, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 57, 59, 66, 70). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 11 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 33: highest → ta.highest
- Line 34: lowest → ta.lowest
- Line 38: ema → ta.ema
- Line 39: ema → ta.ema
- Line 40: ema → ta.ema
6 more edits
- Line 42: transp = 0 → color.new(color.green, 0)
- Line 43: transp = 0 → color.new(color.orange, 0)
- Line 44: transp = 0 → color.new(color.purple, 0)
- Line 57: long = true → direction = strategy.long
- Line 59: long = true → direction = strategy.long
- Line 66: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5strategy(title="TrianglePoint strategy", overlay=true,pyramiding=2, default_qty_value=3, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯//showAllTriangles = input(true, title="show All Triangles")-HH = highest(close,numPeriods)+HH = ta.highest(close,numPeriods)-LL = lowest(close,numPeriods)+LL = ta.lowest(close,numPeriods)tringlePoint = low > LL and high < HH⋯//LL = lowest(low,numPeriods) //close[1],numPeriods-fastEMAval= ema(close, fastEMA)+fastEMAval= ta.ema(close, fastEMA)-slowEMAval= ema(close, slowEMA)+slowEMAval= ta.ema(close, slowEMA)-two100EMAval= ema(close, 200)+two100EMAval= ta.ema(close, 200)//plot emas-plot(fastEMAval, color = color.green, linewidth = 1, transp=0)+plot(fastEMAval, color = color.new(color.green, 0), linewidth = 1)-plot(slowEMAval, color = color.orange, linewidth = 1, transp=0)+plot(slowEMAval, color = color.new(color.orange, 0), linewidth = 1)-plot(two100EMAval, color = color.purple, linewidth = 2, transp=0)+plot(two100EMAval, color = color.new(color.purple, 0), linewidth = 2)longCondition=fastEMAval>two100EMAval and tringlePoint //and close>two100EMAval⋯//Entry-strategy.entry(id="TBT LE", comment="TBT LE" , long=true, stop=close[0]+0.10 ,when= longCondition and strategy.position_size<1 ) +strategy.entry(id="TBT LE", comment="TBT LE" , direction = strategy.long, stop=close[0]+0.10 ,when= longCondition and strategy.position_size<1 ) //Add-strategy.entry(id="TBT LE", comment="Add" , long=true, when= longCondition and strategy.position_size>=1 and close<strategy.position_avg_price) +strategy.entry(id="TBT LE", comment="Add" , direction = strategy.long, when= longCondition and strategy.position_size>=1 and close<strategy.position_avg_price) //barcolor(strategy.position_size>=1 ? color.blue : na)⋯//Exit-strategy.close(id="TBT LE", comment="TBT Exit", when=crossunder(fastEMAval,slowEMAval))+strategy.close(id="TBT LE", comment="TBT Exit", when=ta.crossunder(fastEMAval,slowEMAval))//stoploss⋯Same 11 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 27: input() → input.int()
- Line 28: input() → input.int()
- Line 29: input() → input.int()
- Line 30: input() → input.int()
- Line 31: input() → input.bool()
- Line 57: when = longCondition and strategy.position_size<1 → if block
3 more edits
- Line 59: when = longCondition and strategy.position_size>=1 and close<strategy.position_avg_price → if block
- Line 66: when = ta.crossunder(fastEMAval,slowEMAval) → if block
- Line 70: when = close < stopLossVal → if block
⋯ -numPeriods=input(9,title="Number of Bars")+numPeriods=input.int(9,title="Number of Bars")-fastEMA = input(13, title="fast EMA", minval=1)+fastEMA = input.int(13, title="fast EMA", minval=1)-slowEMA = input(65, title="slow EMA", minval=1)+slowEMA = input.int(65, title="slow EMA", minval=1)-stopLoss = input(title="Stop Loss%", defval=5, minval=1)+stopLoss = input.int(title="Stop Loss%", defval=5, minval=1)-changeBarColor = input(true, title="chage bar color")+changeBarColor = input.bool(true, title="chage bar color")//showAllTriangles = input(true, title="show All Triangles")⋯//Entry-strategy.entry(id="TBT LE", comment="TBT LE" , direction = strategy.long, stop=close[0]+0.10 ,when= longCondition and strategy.position_size<1 ) +if longCondition and strategy.position_size<1+ strategy.entry(id="TBT LE", comment="TBT LE" , direction = strategy.long, stop=close[0]+0.10 ) //Add-strategy.entry(id="TBT LE", comment="Add" , direction = strategy.long, when= longCondition and strategy.position_size>=1 and close<strategy.position_avg_price) +if longCondition and strategy.position_size>=1 and close<strategy.position_avg_price+ strategy.entry(id="TBT LE", comment="Add" , direction = strategy.long) //barcolor(strategy.position_size>=1 ? color.blue : na)⋯//Exit-strategy.close(id="TBT LE", comment="TBT Exit", when=ta.crossunder(fastEMAval,slowEMAval))+if ta.crossunder(fastEMAval,slowEMAval)+ strategy.close(id="TBT LE", comment="TBT Exit")//stoploss⋯//stopLossVal= close> (strategy.position_avg_price * (1+(stopLoss*0.01) )) ? lowest(close,numPeriods) : (strategy.position_avg_price * (1-(stopLoss*0.01) ))-strategy.close(id="TBT LE", comment="SL Exit", when= close < stopLossVal)+if close < stopLossVal+ strategy.close(id="TBT LE", comment="SL Exit")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: 11 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.
⋯// © mohanee-//@version=5+//@version=6strategy(title="TrianglePoint strategy", overlay=true,pyramiding=2, default_qty_value=3, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯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 |
|---|---|---|---|
| Number of Bars | 9 | int | HH_index LL_index HH LL |
| fast EMA | 13 | int · min 1 | fastEMAval |
| slow EMA | 65 | int · min 1 | slowEMAval |
| Stop Loss% | 5 | int · min 1 | takeProfitVal stopLossVal |
| chage bar color | true | bool | barcolor |
What it calculates
- Highest (
highest,ta.highestin v5)close, Number of Bars (9)HH · line 33 - Lowest (
lowest,ta.lowestin v5)close, Number of Bars (9)LL · line 34 - EMA (
ema,ta.emain v5)close, fast EMA (13)fastEMAval · line 38 - EMA (
ema,ta.emain v5)close, slow EMA (65)slowEMAval · line 39 - EMA (
ema,ta.emain v5)close, 200two100EMAval · line 40
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 TBT LE long | longCondition and strategy.position_size<1 | On | 57 |
| Open TBT LE long | longCondition and strategy.position_size>=1 and close<strategy.position_avg_price | On | 59 |
| Close TBT LE | crossunder(fastEMAval,slowEMAval) | On | 66 |
| Close TBT LE | close < stopLossVal | On | 70 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
- 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 | +45.4% | +102.5% | 11 | 18% | 1.03 | 101.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1,077.0% | +5.5% | 9 | 44% | 10.85 | 131.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −19.5% | +9.8% | 11 | 18% | 0.69 | 40.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +42.5% | +8.4% | 7 | 100% | — | 3.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −1.1% | +16.7% | 16 | 25% | 0.71 | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.9% | +21.5% | 12 | 25% | 2.19 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +1.6% | +148.3% | 13 | 23% | 1.12 | 6.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +3.6% | +17.1% | 9 | 100% | — | 2.0% | 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 | 0 | — | $0.00 |
| Sideways market | 11 | 18% | $4,540.47 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
89.3%
The 95th percentile of the worst drawdown when the same 11 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 61.8% to 89.3%; the tick is what actually happened, 75.2%. Order luck alone moves it this much.
All 11 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 6 Oct 2024 62,058.10 | 23 Feb 2025 96,551.00 | 140 | $103,479.00 |
| long | 3 Mar 2025 94,270.10 | 4 Mar 2025 86,221.20 | 1 | −$24,146.80 |
| long | 4 Mar 2025 86,221.20 | 4 Mar 2025 86,221.20 | 0 | $0.00 |
| long | 6 Mar 2025 90,606.10 | 10 Mar 2025 80,734.50 | 4 | −$29,614.90 |
| long | 7 Mar 2025 89,931.90 | 10 Mar 2025 80,734.50 | 3 | −$27,592.20 |
| long | 5 May 2025 94,277.70 | 30 Aug 2025 108,377.00 | 117 | $42,299.00 |
| long | 3 Sep 2025 111,240.00 | 27 Sep 2025 109,643.00 | 24 | −$4,789.95 |
| long | 5 Sep 2025 110,731.00 | 27 Sep 2025 109,643.00 | 22 | −$3,262.23 |
| long | 28 Sep 2025 109,636.00 | 17 Oct 2025 108,194.00 | 19 | −$4,325.04 |
| long | 21 Oct 2025 110,532.00 | 5 Nov 2025 101,497.00 | 15 | −$27,104.90 |
| long | 22 Oct 2025 108,298.00 | 5 Nov 2025 101,497.00 | 14 | −$20,401.30 |
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 |
|---|---|---|---|---|---|
| TrianglePoint strategy this page | — | v4 strategy | +45.4% | 11 | 101.9% |
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema highest lowest | v5 strategy | No trades on this market | ||
| Lagged Donchian Channel + EMA by Mysteriown | ema highest lowest | v4 strategy | −12.3% | 4 | 12.3% |
| Backtest Custom HiLo Strategy by luyikaibr | ema highest lowest | v4 strategy | No trades on this market | ||
| CM_SlingShotSystem+_CassicEMA+Willams21EMA13 htc1977 edition by Arivadis | ema highest lowest | v5 strategy | No trades on this market | ||
| EMA Mean Reversion Strategy by jordanfray | ema highest lowest | v5 strategy | +4.7% | 230 | 8.9% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 17 ms | With a workaround 1,000 bars in 48 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 57, 59) so the engine trades the way the script says.
“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/// © mohanee//@version=4strategy(title="TrianglePoint strategy", overlay=true,pyramiding=2, default_qty_value=3, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)// variables BEGIN//find the index of highest high of n periods index_HH(pds) => tHH =0.00 HH_index=1 for i=1 to pds if high[i]>tHH tHH:=high[i] HH_index:=i HH_index//find the index of lowest low of n periods index_LL(pds) => tLL = low[0] LL_index=1 for i=1 to pds if low[i]<tLL tLL:=low[i] LL_index:=i LL_index numPeriods=input(9,title="Number of Bars")fastEMA = input(13, title="fast EMA", minval=1)slowEMA = input(65, title="slow EMA", minval=1)stopLoss = input(title="Stop Loss%", defval=5, minval=1)changeBarColor = input(true, title="chage bar color")//showAllTriangles = input(true, title="show All Triangles")HH = highest(close,numPeriods)LL = lowest(close,numPeriods)tringlePoint = low > LL and high < HH//HH = highest(high,numPeriods) ///close[1],numPeriod//LL = lowest(low,numPeriods) //close[1],numPeriodsfastEMAval= ema(close, fastEMA)slowEMAval= ema(close, slowEMA)two100EMAval= ema(close, 200)//plot emasplot(fastEMAval, color = color.green, linewidth = 1, transp=0)plot(slowEMAval, color = color.orange, linewidth = 1, transp=0)plot(two100EMAval, color = color.purple, linewidth = 2, transp=0)longCondition=fastEMAval>two100EMAval and tringlePoint //and close>two100EMAval// On the last price bar, make a new trend lineHH_index=index_HH(numPeriods)LL_index=index_LL(numPeriods)if (longCondition and strategy.position_size<1 ) //and barstate.islast line.new(x1=bar_index[LL_index ], y1=low[LL_index], x2=bar_index, y2=close, color=color.red, width=2) line.new(x1=bar_index[HH_index], y1=high[HH_index], x2=bar_index, y2=close, color=color.green, width=2) line.new(x1=bar_index[HH_index], y1=high[HH_index], x2=bar_index[LL_index], y2=low[LL_index], color=color.blue, width=2) //Entrystrategy.entry(id="TBT LE", comment="TBT LE" , long=true, stop=close[0]+0.10 ,when= longCondition and strategy.position_size<1 ) //Addstrategy.entry(id="TBT LE", comment="Add" , long=true, when= longCondition and strategy.position_size>=1 and close<strategy.position_avg_price) //barcolor(strategy.position_size>=1 ? color.blue : na)//Take profittakeProfitVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00//strategy.close(id="TBT LE", comment="Profit Exit", qty=strategy.position_size/2, when=close>=takeProfitVal and close<open and close<fastEMAval) //crossunder(close,fastEMAval)barcolor(strategy.position_size>=1 and changeBarColor==true ? (close>takeProfitVal? color.purple : color.blue): na)//Exitstrategy.close(id="TBT LE", comment="TBT Exit", when=crossunder(fastEMAval,slowEMAval))//stoplossstopLossVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00//stopLossVal= close> (strategy.position_avg_price * (1+(stopLoss*0.01) )) ? lowest(close,numPeriods) : (strategy.position_avg_price * (1-(stopLoss*0.01) ))strategy.close(id="TBT LE", comment="SL Exit", when= close < stopLossVal)