Pine Script v4 · Strategy
Golden Triangle Strategy
A Pine Script v4 strategy built on SMA (close, smaLength1), Pivothigh (5, 5) and Pivotlow (5, 5). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 10% of equity and pays no commission. 9 settings; defaults include SMA Length 50, Look Back periods 200 and Risk % of capital 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 Golden Triangle 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 Golden Triangle Strategy do on BTCUSDT 1D with default settings?
- +156.10%
- From 26 Jan 2024 to 21 Oct 2026, over 10 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Golden Triangle 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 Golden Triangle Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Golden Triangle Strategy run in Zeal Terminal?
- Yes
- It compiles in 31 ms and runs 1,000 bars in 148 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Pivot Trailing Stop
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +156.10%
- $15,609.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 10
- 9 won · 1 lost
- Profitable
- 90.0%
- of closed trades
- Profit factor
- 332.00
- gross profit ÷ gross loss
- Max drawdown
- 101.17%
- −$25,909.10
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.
-
Check
1 setting does nothing
“chage bar color” is declared but never read.
-
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 122, 145, 149. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 57
transp = on line 57, 139. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 122
long = on line 122. 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 sma → ta.sma, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, atr → ta.atr, max → math.max, min → math.min, tostring → str.tostring, crossover → ta.crossover, crossunder → ta.crossunder.
- 3 strategy calls use the when = argument (line 122, 145, 149). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 10 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 55: sma → ta.sma
- Line 57: transp = 0 → color.new(color.green, 0)
- Line 87: vwap → ta.vwap
- Line 91: pivothigh → ta.pivothigh
13 more edits
- Line 92: pivotlow → ta.pivotlow
- Line 101: atr → ta.atr
- Line 102: atr → ta.atr
- Line 106: max → math.max
- Line 107: min → math.min
- Line 122: tostring → str.tostring
- Line 122: long = true → direction = strategy.long
- Line 122: crossover → ta.crossover
- Line 139: transp = 80 → color.new(strategy.position_size>=1?color.blue:na, 80)
- Line 145: tostring → str.tostring
- Line 145: crossunder → ta.crossunder
- Line 149: tostring → str.tostring
- Line 149: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5//Golden Triangle strategy setup is a variation of the buy-the-dip strategy, by Charlotte Hudgin.⋯ prev_index=0- smaVal1=sma(close, smaLength1)+ smaVal1=ta.sma(close, smaLength1) for i=1 to lookbackPds1⋯atrPeriod=input(defval = 50, title = "ATR Period", minval=1)-smaVal = sma(close, smaLength)+smaVal = ta.sma(close, smaLength)//plot sma-plot(smaVal, color = color.green, linewidth = 1, transp=0)+plot(smaVal, color = color.new(color.green, 0), linewidth = 1)isPriceAbove50=true⋯//voulmeConfirmed= triangleFound and volume[0]>volume[1] and volume[0]>volume[2] and volume[0]>volume[3] and volume[0]>volume[4]-vwapVal=vwap+vwapVal=ta.vwap//pivot points calculation BEGIN⋯float pvtLow = na-pvtHigh := pivothigh(pivotPeriod, pivotPeriod)+pvtHigh := ta.pivothigh(pivotPeriod, pivotPeriod)-pvtLow := pivotlow(pivotPeriod, pivotPeriod)+pvtLow := ta.pivotlow(pivotPeriod, pivotPeriod)float center = na⋯ center := (center * 2 + lastpp) / 3-Up = center - (atrFactor * atr(atrPeriod))+Up = center - (atrFactor * ta.atr(atrPeriod))-Dn = center + (atrFactor * atr(atrPeriod))+Dn = center + (atrFactor * ta.atr(atrPeriod))float TUp = na⋯Trend = 0-TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : Up+TUp := close[1] > TUp[1] ? math.max(Up, TUp[1]) : Up-TDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : Dn+TDown := close[1] < TDown[1] ? math.min(Dn, TDown[1]) : DnTrend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)⋯//strategy.entry(id="GT LE", comment="GT LE SL="+tostring(close*(1-(stopLoss*0.01)), "####.##"), long=true, qty=qty1 , when= triangleFound and crossover(close,vwapVal) ) //and strategy.position_size<1-strategy.entry(id="GT LE", comment="GT LE SL="+tostring(close*(1-(stopLoss*0.01)), "####.##"), long=true, qty=qty1 , when= triangleFound and Trend == 1 and crossover(close,vwapVal) ) //and strategy.position_size<1 +strategy.entry(id="GT LE", comment="GT LE SL="+str.tostring(close*(1-(stopLoss*0.01)), "####.##"), direction = strategy.long, qty=qty1 , when= triangleFound and Trend == 1 and ta.crossover(close,vwapVal) ) //and strategy.position_size<1 triangleFound:= strategy.position_size>=1 ? false :triangleFound⋯plot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")-bgcolor(strategy.position_size>=1?color.blue:na, transp=80)+bgcolor(color.new(strategy.position_size>=1?color.blue:na, 80))//plot(close>strategy.position_avg_price ? TUp: stopLossVal>0 ? stopLossVal : na, color = color.green , linewidth = 2, title = "Pivot Trailing Stop")⋯//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and crossunder(vwapVal,smaVal) ) //close<vwapVal and close<smaVal)-strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and crossunder(vwapVal,smaVal)) // and crossunder(vwapVal,smaVal)+strategy.close(id="GT LE", comment="GTVW Exit points="+str.tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and ta.crossunder(vwapVal,smaVal)) // and crossunder(vwapVal,smaVal)//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when= vwapVal < TUp ) // and crossunder(vwapVal,smaVal)⋯//strategy.close(id="GT LE", comment="SL Exit points="+tostring(close-strategy.position_avg_price,"###.##") , when= close< stopLossVal ) //windupPrice-strategy.close(id="GT LE", comment="SL Exit points="+tostring(close-strategy.position_avg_price,"###.##") , when=crossunder(close,stopLossVal) ) //windupPrice (strategy.position_avg_price - close ) > 10+strategy.close(id="GT LE", comment="SL Exit points="+str.tostring(close-strategy.position_avg_price,"###.##") , when=ta.crossunder(close,stopLossVal) ) //windupPrice (strategy.position_avg_price - close ) > 10Same 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 45: input() → input.int()
- Line 46: input() → input.int()
- Line 47: input() → input.int()
- Line 48: input() → input.int()
- Line 49: input() → input.bool()
- Line 50: input() → input.bool()
6 more edits
- Line 52: input() → input.int()
- Line 53: input() → input.int()
- Line 54: input() → input.int()
- Line 122: when = triangleFound and Trend == 1 and ta.crossover(close,vwapVal) → if block
- Line 145: when = close>strategy.position_avg_price and ta.crossunder(vwapVal,smaVal) → if block
- Line 149: when = ta.crossunder(close,stopLossVal) → if block
⋯ -smaLength=input(50,title="SMA Length")+smaLength=input.int(50,title="SMA Length")-lookBackPds=input(200,title="Look Back periods")+lookBackPds=input.int(200,title="Look Back periods")-riskCapital = input(title="Risk % of capital", defval=10, minval=1)+riskCapital = input.int(title="Risk % of capital", defval=10, minval=1)-stopLoss = input(title="Stop Loss%", defval=6, minval=1)+stopLoss = input.int(title="Stop Loss%", defval=6, minval=1)-changeBarColor = input(true, title="chage bar color")+changeBarColor = input.bool(true, title="chage bar color")-showAllTriangles = input(false, title="show Triangles even after Long position is taken")+showAllTriangles = input.bool(false, title="show Triangles even after Long position is taken")//pivot points -pivotPeriod = input(defval = 5, title="Pivot Point Period", minval = 1, maxval = 50)+pivotPeriod = input.int(defval = 5, title="Pivot Point Period", minval = 1, maxval = 50)-atrFactor=input(defval = 3, title = "ATR Factor", minval = 1, step = 0.1)+atrFactor=input.int(defval = 3, title = "ATR Factor", minval = 1, step = 0.1)-atrPeriod=input(defval = 50, title = "ATR Period", minval=1)+atrPeriod=input.int(defval = 50, title = "ATR Period", minval=1)smaVal = ta.sma(close, smaLength)⋯//strategy.entry(id="GT LE", comment="GT LE SL="+tostring(close*(1-(stopLoss*0.01)), "####.##"), long=true, qty=qty1 , when= triangleFound and crossover(close,vwapVal) ) //and strategy.position_size<1-strategy.entry(id="GT LE", comment="GT LE SL="+str.tostring(close*(1-(stopLoss*0.01)), "####.##"), direction = strategy.long, qty=qty1 , when= triangleFound and Trend == 1 and ta.crossover(close,vwapVal) ) //and strategy.position_size<1 +if triangleFound and Trend == 1 and ta.crossover(close,vwapVal)+ strategy.entry(id="GT LE", comment="GT LE SL="+str.tostring(close*(1-(stopLoss*0.01)), "####.##"), direction = strategy.long, qty=qty1 ) //and strategy.position_size<1 triangleFound:= strategy.position_size>=1 ? false :triangleFound⋯//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and crossunder(vwapVal,smaVal) ) //close<vwapVal and close<smaVal)-strategy.close(id="GT LE", comment="GTVW Exit points="+str.tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and ta.crossunder(vwapVal,smaVal)) // and crossunder(vwapVal,smaVal)+if close>strategy.position_avg_price and ta.crossunder(vwapVal,smaVal)+ strategy.close(id="GT LE", comment="GTVW Exit points="+str.tostring(close-strategy.position_avg_price,"###.##")) // and crossunder(vwapVal,smaVal)//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when= vwapVal < TUp ) // and crossunder(vwapVal,smaVal)⋯//strategy.close(id="GT LE", comment="SL Exit points="+tostring(close-strategy.position_avg_price,"###.##") , when= close< stopLossVal ) //windupPrice-strategy.close(id="GT LE", comment="SL Exit points="+str.tostring(close-strategy.position_avg_price,"###.##") , when=ta.crossunder(close,stopLossVal) ) //windupPrice (strategy.position_avg_price - close ) > 10+if ta.crossunder(close,stopLossVal)+ strategy.close(id="GT LE", comment="SL Exit points="+str.tostring(close-strategy.position_avg_price,"###.##") ) //windupPrice (strategy.position_avg_price - close ) > 10Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L95:C15: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © mohanee-//@version=5+//@version=6//Golden Triangle strategy setup is a variation of the buy-the-dip strategy, by Charlotte Hudgin.⋯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 |
|---|---|---|---|
| SMA Length | 50 | int | smaVal lastIndex |
| Look Back periods | 200 | int | lastIndex |
| Risk % of capital | 10 | int · min 1 | qty1 |
| Stop Loss% | 6 | int · min 1 | stopLossVal qty1 entry GT LE |
| chage bar color | true | bool | unused |
| show Triangles even after Long position is taken | false | bool | drawCondition |
| Pivot Point Period | 5 | int · min 1 · max 50 | pvtHigh pvtLow |
| ATR Factor | 3 | int · min 1 · step 0.1 | Up Dn |
| ATR Period | 50 | int · min 1 | Up Dn |
What it calculates
- SMA (
sma,ta.smain v5)close, smaLength1smaVal1 · line 14 - SMA (
sma,ta.smain v5)close, SMA Length (50)smaVal · line 55 - Pivothigh (
pivothigh,ta.pivothighin v5)Pivot Point Period (5), Pivot Point Period (5)pvtHigh · line 91 - Pivotlow (
pivotlow,ta.pivotlowin v5)Pivot Point Period (5), Pivot Point Period (5)pvtLow · line 92 - ATR (
atr,ta.atrin v5)ATR Period (50)Up · line 101 - ATR (
atr,ta.atrin v5)ATR Period (50)Dn · line 102
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open GT LE long | triangleFound and Trend == 1 and crossover(close,vwapVal) | On | 122 |
| Close GT LE | close>strategy.position_avg_price and crossunder(vwapVal,smaVal) | On | 145 |
| Close GT LE | crossunder(close,stopLossVal) | On | 149 |
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 | +156.1% | +102.5% | 10 | 90% | 332.00 | 101.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +70.8% | +5.5% | 16 | 88% | 55.18 | 10.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −7.4% | +9.8% | 4 | 50% | 0.60 | 13.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +18.8% | +8.4% | 4 | 100% | — | 5.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +25.1% | +16.7% | 6 | 50% | 1.95 | 18.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +26.7% | +21.5% | 3 | 67% | 4.22 | 8.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.8% | +148.3% | 4 | 75% | 0.93 | 13.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +6.4% | +17.1% | 6 | 67% | 1.43 | 8.6% | 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 | 7 | 86% | $5,480.60 |
| Sideways market | 3 | 100% | $10,129.20 |
| 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?
0.3%
The 95th percentile of the worst drawdown when the same 10 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.3% to 0.3%; the tick is what actually happened, 0.3%. Order luck alone moves it this much.
All 10 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Jun 2024 66,228.30 | 28 Dec 2024 94,299.00 | 195 | $4,238.49 |
| long | 23 Jun 2024 64,262.00 | 28 Dec 2024 94,299.00 | 188 | $4,535.38 |
| long | 29 Dec 2024 95,300.00 | 9 Jan 2025 95,060.60 | 11 | −$47.16 |
| long | 2 Jan 2025 94,591.80 | 9 Jan 2025 95,060.60 | 7 | $92.36 |
| long | 11 Jan 2025 94,726.10 | 3 Feb 2025 97,700.60 | 23 | $590.94 |
| long | 14 Jan 2025 94,536.10 | 3 Feb 2025 97,700.60 | 20 | $628.68 |
| long | 4 Feb 2025 101,329.00 | 21 Jun 2025 103,298.00 | 137 | $389.48 |
| long | 9 Feb 2025 96,444.80 | 21 Jun 2025 103,298.00 | 132 | $1,355.29 |
| long | 23 Jun 2025 100,964.00 | 20 Aug 2025 112,873.00 | 58 | $2,569.44 |
| long | 28 Jun 2025 107,048.00 | 20 Aug 2025 112,873.00 | 53 | $1,256.85 |
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 |
|---|---|---|---|---|---|
| Golden Triangle Strategy this page | — | v4 strategy | +156.1% | 10 | 101.2% |
| Villa Dinamic Pivot Supertrend Strategy by VILIO_Trading | pivothigh pivotlow atr sma | v5 strategy | No trades on this market | ||
| The Only EURUSD Trading Strategy You Need - Kaspricci by Kaspricci | atr pivothigh pivotlow | v5 strategy | No trades on this market | ||
| Alert(), alertcondition() or strategy alerts- by Peter_O | sma pivothigh pivotlow | v4 strategy | +7,640,000.0% | 191 | 919.9% |
| Quantitative Trend Strategy- Uptrend long by CheatCode1 | sma pivothigh pivotlow | v5 strategy | +5.9% | 28 | 32.8% |
| Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_O | sma pivothigh pivotlow | v5 strategy | −9,857,600.0% | 191 | 4,436.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 31 ms | With a workaround 1,000 bars in 148 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 (line 122) 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=4//Golden Triangle strategy setup is a variation of the buy-the-dip strategy, by Charlotte Hudgin.//You can find the detailed explanataion here by Thomas N. Bulkowski http://thepatternsite.com/GoldenTriangle.htmlstrategy(title="Golden Triangle Strategy", overlay=true,pyramiding=2, default_qty_type=strategy.percent_of_equity, default_qty_value=10, initial_capital=10000, currency=currency.USD, max_bars_back=200)// variables BEGINvar triangleFound=falsevar windupPrice=0.00var stopLossVal=0.00//find the index of highest high of n periods findIndexForWhiteSpace(smaLength1, lookbackPds1) => prev_index=0 smaVal1=sma(close, smaLength1) for i=1 to lookbackPds1 if low[i]<smaVal1[i] and close[i]>smaVal1[i] prev_index:=i break if open[i] < smaVal1[1] and high[i]<smaVal1[i] prev_index:=0 break prev_index//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 smaLength=input(50,title="SMA Length")lookBackPds=input(200,title="Look Back periods")riskCapital = input(title="Risk % of capital", defval=10, minval=1)stopLoss = input(title="Stop Loss%", defval=6, minval=1)changeBarColor = input(true, title="chage bar color")showAllTriangles = input(false, title="show Triangles even after Long position is taken")//pivot points pivotPeriod = input(defval = 5, title="Pivot Point Period", minval = 1, maxval = 50)atrFactor=input(defval = 3, title = "ATR Factor", minval = 1, step = 0.1)atrPeriod=input(defval = 50, title = "ATR Period", minval=1)smaVal = sma(close, smaLength)//plot smaplot(smaVal, color = color.green, linewidth = 1, transp=0)isPriceAbove50=truefor i=1 to 10 if not(high[i]>smaVal and low[i]>smaVal) isPriceAbove50:=false break longCondition= isPriceAbove50 and high>smaVal and low<smaVal //check for current candle lastIndex=findIndexForWhiteSpace(smaLength, lookBackPds)// On the last price bar, make a new trend lineHH_index=index_HH(lastIndex)//LL_index=index_LL(numPeriods)drawCondition=showAllTriangles==true ? longCondition and lastIndex>1 : longCondition and lastIndex>1 and strategy.position_size<1if (drawCondition ) //longCondition and lastIndex>1 ) //and strategy.position_size<1 //draw line from last touch point to pivot (Gighest High) line.new(x1=bar_index[lastIndex], y1=low[lastIndex], x2=bar_index[HH_index], y2=high[HH_index], color=color.red, width=2) //draw line from Highest to current price touch point line.new(x1=bar_index[HH_index], y1=high[HH_index], x2=bar_index, y2=close, color=color.green, width=2) //draw line from previous touch to current touch -- This is trianle base line.new(x1=bar_index[lastIndex], y1=low[lastIndex], x2=bar_index, y2=close, color=color.blue, width=2) triangleFound:=true windupPrice:=low[lastIndex] //+ ( abs(high[HH_index]-low[lastIndex])*0.61) //mycomment:="High="+tostring(HH_index,"######") //voulmeConfirmed= triangleFound and volume[0]>volume[1] and volume[0]>volume[2] and volume[0]>volume[3] and volume[0]>volume[4]vwapVal=vwap//pivot points calculation BEGINfloat pvtHigh = nafloat pvtLow = napvtHigh := pivothigh(pivotPeriod, pivotPeriod)pvtLow := pivotlow(pivotPeriod, pivotPeriod)float center = nacenter := center[1]float lastpp = pvtHigh ? pvtHigh : pvtLow ? pvtLow : naif lastpp if na(center) center := lastpp else center := (center * 2 + lastpp) / 3Up = center - (atrFactor * atr(atrPeriod))Dn = center + (atrFactor * atr(atrPeriod))float TUp = nafloat TDown = naTrend = 0TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : UpTDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : DnTrend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)//Trailingsl = Trend ==s 1 ? TUp : TDown//draw pivot pointsTrailingstop = Trend == 1 ? TUp : TDowntslColor = Trend == 1 and nz(Trend[1]) == 1 ? color.lime : Trend == -1 and nz(Trend[1]) == -1 ? color.red : naplot(Trend==1 ? TUp:na, color = tslColor , linewidth = 2, title = "Pivot Trailing Stop")//pivot points calculation END//Entry--//Echeck how many units can be purchased based on risk manage ment and stop lossqty1 = (strategy.equity * riskCapital / 100 ) / (close*stopLoss/100) //check if cash is sufficient to buy qty1 , if capital not available use the available capital onlyqty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1//Entry//strategy.entry(id="GT LE", comment="GT LE SL="+tostring(close*(1-(stopLoss*0.01)), "####.##"), long=true, qty=qty1 , when= triangleFound and crossover(close,vwapVal) ) //and strategy.position_size<1strategy.entry(id="GT LE", comment="GT LE SL="+tostring(close*(1-(stopLoss*0.01)), "####.##"), long=true, qty=qty1 , when= triangleFound and Trend == 1 and crossover(close,vwapVal) ) //and strategy.position_size<1 triangleFound:= strategy.position_size>=1 ? false :triangleFound//stoplossstopLossVal:= strategy.position_size>=1 ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00//Add//if (strategy.position_size>=1 and close>stopLossVal and close<TUp ) //longCondition and crossover(close, vwapVal) // strategy.entry(id="GT LE", comment="Add", long=true, when= strategy.position_size>=1 and longCondition and close>vwapVal) //close<strategy.position_avg_price and crossover(close,smaVal)) // strategy.entry(id="GT LE", comment="Add new SL="+tostring(close*(1-(stopLoss*0.01)), "####.##"), long=true) //stoploss//stopLossVal:= strategy.position_size>=1 ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00//barcolor(strategy.position_size>=1 ? color.blue : na)//Take profittakeProfitVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1+(2*0.01) )) : 0.00//takeProfitVal= strategy.position_size>=1 ? windupPrice : 0.00//barcolor(strategy.position_size>=1 and changeBarColor==true ? (close>takeProfitVal? color.purple : color.blue): na)//draw initil stop lossplot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")bgcolor(strategy.position_size>=1?color.blue:na, transp=80)//plot(close>strategy.position_avg_price ? TUp: stopLossVal>0 ? stopLossVal : na, color = color.green , linewidth = 2, title = "Pivot Trailing Stop")//Exit//strategy.close(id="GT LE", comment="GT Exit", when=close>=takeProfitVal)//strategy.close(id="GT LE", comment="GT Exit", when=close>takeProfitVal and crossunder(close,smaVal)) --- original//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and crossunder(vwapVal,smaVal) ) //close<vwapVal and close<smaVal)strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and crossunder(vwapVal,smaVal)) // and crossunder(vwapVal,smaVal)//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when= vwapVal < TUp ) // and crossunder(vwapVal,smaVal)//strategy.close(id="GT LE", comment="GTVW Exit points="+tostring(close-strategy.position_avg_price,"###.##"), when=close>strategy.position_avg_price and crossunder(vwapVal,smaVal))//strategy.close(id="GT LE", comment="SL Exit points="+tostring(close-strategy.position_avg_price,"###.##") , when= close< stopLossVal ) //windupPricestrategy.close(id="GT LE", comment="SL Exit points="+tostring(close-strategy.position_avg_price,"###.##") , when=crossunder(close,stopLossVal) ) //windupPrice (strategy.position_avg_price - close ) > 10