Pine Script v4 · Strategy
[Strategy] - EMA 10,20 59 with Profit Displayed
A Pine Script v4 strategy built on EMA (close, 10) and Barssince (Buytrend). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is 1000 contracts and pays no commission. 8 settings; defaults include infoBoxSize size.large, Ema1Value 10 and Ema2Value 20.
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 [Strategy] - EMA 10,20 59 with Profit Displayed repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 108 of 108 trades.
- Can [Strategy] - EMA 10,20 59 with Profit Displayed be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L50:C235: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version), so no v5 download is offered; the edits are shown below.
- Does [Strategy] - EMA 10,20 59 with Profit Displayed use a stop loss?
- Yes
- strategy.exit sets a stop on line 70, 77.
- Does [Strategy] - EMA 10,20 59 with Profit Displayed run in Zeal Terminal?
- Yes
- It compiles in 50 ms and runs 1,000 bars in 83 ms, in the browser.
BTCUSDT · 1D · default settings
- ema1
- ema2
- ema3
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −2,311,450.00%
- −$5,778,620.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 793
- 1 won · 792 lost
- Profitable
- 0.1%
- of closed trades
- Profit factor
- 0.76
- gross profit ÷ gross loss
- Max drawdown
- 8,424,000.00%
- −$21,060,000.00
One run with the author's default settings, $250 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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
4 settings have no label
In the settings dialog ema1Value (line 10), ema2Value (line 11), ema3Value (line 12), maxLoss (line 13) 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 transp =, which v5 removed line 27
transp = on line 27, 31, 32, 37, 38. 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 ema → ta.ema, tostring → str.tostring, barssince → ta.barssince, crossunder → ta.crossunder, crossover → ta.crossover.
v4 → v5
DiffersThe v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L50:C235: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.bool) → input.bool()
- Line 7: input(type = input.bool) → input.bool()
- Line 8: input(type = input.bool) → input.bool()
- Line 14: ema → ta.ema
- Line 15: ema → ta.ema
32 more edits
- Line 16: ema → ta.ema
- Line 18: tostring → str.tostring
- Line 24: barssince → ta.barssince
- Line 25: barssince → ta.barssince
- Line 27: transp = 70 → color.new(Buytrend ? color.green : color.red, 70)
- Line 29: crossunder → ta.crossunder
- Line 30: barssince → ta.barssince
- Line 31: transp = 30 → color.new(BuySignal ? color.green : na, 30)
- Line 32: transp = 30 → color.new(BuySignalOut ? color.black : na, 30)
- Line 35: crossover → ta.crossover
- Line 36: barssince → ta.barssince
- Line 37: transp = 30 → color.new(SellSignal ? color.red : na, 30)
- Line 38: transp = 30 → color.new(SellSignalOut ? color.black : na, 30)
- Line 50: tostring → str.tostring
- Line 50: tostring → str.tostring
- Line 50: tostring → str.tostring
- Line 52: tostring → str.tostring
- Line 52: tostring → str.tostring
- Line 52: tostring → str.tostring
- Line 55: tostring → str.tostring
- Line 55: tostring → str.tostring
- Line 55: tostring → str.tostring
- Line 58: tostring → str.tostring
- Line 58: tostring → str.tostring
- Line 58: tostring → str.tostring
- Line 59: tostring → str.tostring
- Line 59: tostring → str.tostring
- Line 59: tostring → str.tostring
- Line 59: tostring → str.tostring
- Line 59: tostring → str.tostring
- Line 69: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 76: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © mattehalen-//@version=4+//@version=5//study("EMA 10,20 59",overlay=true)strategy("EMA 10,20 59",overlay=true, process_orders_on_close = true, default_qty_type = strategy.fixed, default_qty_value = 1000, initial_capital=250, currency=currency.USD)-infoBox = input(true, title="infoBox", type=input.bool)+infoBox = input.bool(true, title="infoBox")-infoBox2 = input(false, title="infoBox2", type=input.bool)+infoBox2 = input.bool(false, title="infoBox2")-BuySellSignal_Bool = input(false, title="Buy & SellSignal", type=input.bool)+BuySellSignal_Bool = input.bool(false, title="Buy & SellSignal")infoBoxSize = input(title="infoBoxSize", defval=size.large, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge])⋯maxLoss = input(3000)-ema1 = ema(close,ema1Value)+ema1 = ta.ema(close,ema1Value)-ema2 = ema(close,ema2Value)+ema2 = ta.ema(close,ema2Value)-ema3 = ema(close,ema3Value)+ema3 = ta.ema(close,ema3Value)objcnt = 0-buyTitle = tostring(close[1])+buyTitle = str.tostring(close[1])myProfit = float(0)⋯Buytrend = (ema1 and ema2 > ema3) and (ema1[1] and ema2[1] > ema3[1])-BarssinceBuyTrend = barssince(Buytrend)+BarssinceBuyTrend = ta.barssince(Buytrend)-BarssinceSellTrend = barssince(not Buytrend)+BarssinceSellTrend = ta.barssince(not Buytrend)closeAtBuyTrend = close[1]-bgcolor(Buytrend ? color.green : color.red,transp=70)+bgcolor(color.new(Buytrend ? color.green : color.red, 70))BuySignal = Buytrend and not Buytrend[1] and BuySellSignal_Bool-BuySignalOut = Buytrend and (crossunder(ema1,ema2)) and BuySellSignal_Bool+BuySignalOut = Buytrend and (ta.crossunder(ema1,ema2)) and BuySellSignal_Bool-BarssinceBuy = barssince(BuySignal)+BarssinceBuy = ta.barssince(BuySignal)-bgcolor(BuySignal ? color.green : na , transp=30)+bgcolor(color.new(BuySignal ? color.green : na, 30) )-bgcolor(BuySignalOut ? color.black : na , transp=30)+bgcolor(color.new(BuySignalOut ? color.black : na, 30) )plot(BarssinceBuy,title="BarssinceBuy",display=display.none)SellSignal = not Buytrend and Buytrend[1] and BuySellSignal_Bool-SellSignalOut = not Buytrend and (crossover(ema1,ema2)) and BuySellSignal_Bool+SellSignalOut = not Buytrend and (ta.crossover(ema1,ema2)) and BuySellSignal_Bool-BarssinceSell = barssince(SellSignal)+BarssinceSell = ta.barssince(SellSignal)-bgcolor(SellSignal ? color.red : na , transp=30)+bgcolor(color.new(SellSignal ? color.red : na, 30) )-bgcolor(SellSignalOut ? color.black : na , transp=30)+bgcolor(color.new(SellSignalOut ? color.black : na, 30) )plot(BarssinceSell,title="BarssinceSell",display=display.none)⋯if (Buytrend and not Buytrend[1] and infoBox==true)- l = label.new(bar_index - (BarssinceBuyTrend[1]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuyTrend[1]]) + "\n" + "Profit = "+tostring(close[BarssinceBuyTrend[1]]-close) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.red,size=infoBoxSize)+ l = label.new(bar_index - (BarssinceBuyTrend[1]/2), na,text="Close = " + str.tostring(close) + "\n" + "Start = "+str.tostring(close[BarssinceBuyTrend[1]]) + "\n" + "Profit = "+str.tostring(close[BarssinceBuyTrend[1]]-close) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.red,size=infoBoxSize)if (not Buytrend and Buytrend[1] and infoBox==true)- l = label.new(bar_index - (BarssinceSellTrend[1]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSellTrend[1]]) + "\n" + "Profit = "+tostring(close-close[BarssinceSellTrend[1]]) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.green,size=infoBoxSize)+ l = label.new(bar_index - (BarssinceSellTrend[1]/2), na,text="Close = " + str.tostring(close) + "\n" + "Start = "+str.tostring(close[BarssinceSellTrend[1]]) + "\n" + "Profit = "+str.tostring(close-close[BarssinceSellTrend[1]]) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.green,size=infoBoxSize)if (BuySignalOut and not BuySignalOut[1] and infoBox2==true)// l = label.new(bar_index - (BarssinceBuy[0]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.purple,size=infoBoxSize- l = label.new(bar_index, na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.lime,size=infoBoxSize)+ l = label.new(bar_index, na,text="Close = " + str.tostring(close) + "\n" + "Start = "+str.tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+str.tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.lime,size=infoBoxSize)if (SellSignalOut and not SellSignalOut[1] and infoBox2==true)// l = label.new(bar_index - (BarssinceSell[0]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.purple,size=infoBoxSize)- l = label.new(bar_index, na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.fuchsia,size=infoBoxSize)+ l = label.new(bar_index, na,text="Close = " + str.tostring(close) + "\n" + "Start = "+str.tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+str.tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.fuchsia,size=infoBoxSize)-l2 = label.new(bar_index, na, 'buyProfit in pip = '+tostring(buyProfit)+"\n"+ 'cntBuy = '+tostring(cntBuy) +"\n"+ 'sellProfit in pip = '+tostring(sellProfit)+"\n"+ 'cntSell = '+tostring(cntSell) +"\n"+ 'totalProfit in pip = '+tostring(totalProfit) , +l2 = label.new(bar_index, na, 'buyProfit in pip = '+str.tostring(buyProfit)+"\n"+ 'cntBuy = '+str.tostring(cntBuy) +"\n"+ 'sellProfit in pip = '+str.tostring(sellProfit)+"\n"+ 'cntSell = '+str.tostring(cntSell) +"\n"+ 'totalProfit in pip = '+str.tostring(totalProfit) , color=totalProfit>0 ? color.green : color.red, ⋯ strategy.close("short", comment = "Exit short")- strategy.entry("long", true)+ strategy.entry("long", strategy.long) strategy.exit("Max Loss", "long", loss = maxLoss)⋯ strategy.close("long", comment = "Exit Long")- strategy.entry("short", false)+ strategy.entry("short", strategy.short) strategy.exit("Max Loss", "short", loss = maxLoss)⋯Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L50:C235: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version.), so this step could not be checked.
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.int()
⋯infoBoxSize = input(title="infoBoxSize", defval=size.large, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge])-ema1Value = input(10)+ema1Value = input.int(10)-ema2Value = input(20)+ema2Value = input.int(20)-ema3Value = input(59)+ema3Value = input.int(59)-maxLoss = input(3000)+maxLoss = input.int(3000)ema1 = ta.ema(close,ema1Value)⋯Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L50:C235: 'label.style_labelup' is not available in Pine Script v5. It was added in a later version.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © mattehalen-//@version=5+//@version=6//study("EMA 10,20 59",overlay=true)⋯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 |
|---|---|---|---|
| infoBox | true | bool | line 49 line 51 |
| infoBox2 | false | bool | line 53 line 56 |
| Buy & SellSignal | false | bool | BuySignal BuySignalOut SellSignal SellSignalOut |
| infoBoxSize | size.large | value · options [size.auto, size.tiny, size.small, size.normal, size.large, size.huge] | l |
| Ema1Value (no label in the script) | 10 | int | ema1 |
| Ema2Value (no label in the script) | 20 | int | ema2 |
| Ema3Value (no label in the script) | 59 | int | ema3 |
| Max Loss (no label in the script) | 3000 | int | exit Max Loss |
What it calculates
- EMA (
ema,ta.emain v5)close, Ema1Value (10)ema1 · line 14 - EMA (
ema,ta.emain v5)close, Ema2Value (20)ema2 · line 15 - EMA (
ema,ta.emain v5)close, Ema3Value (59)ema3 · line 16 - Barssince (
barssince,ta.barssincein v5)BuytrendBarssinceBuyTrend · line 24 - Barssince (
barssince,ta.barssincein v5)BuySignalBarssinceBuy · line 30 - Barssince (
barssince,ta.barssincein v5)SellSignalBarssinceSell · line 36
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 |
|---|---|---|---|
| Close short | (Buytrend) | On | 68 |
| Open long long | (Buytrend) | On | 69 |
| Exit Max Loss stop | (Buytrend) | On | 70 |
| Close long | (not Buytrend) | On | 75 |
| Open short short | (not Buytrend) | On | 76 |
| Exit Max Loss stop | (not Buytrend) | On | 77 |
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, 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | −2,311,450.0% | +102.5% | 793 | 0% | 0.76 | 8,424,000.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +7,178,780.0% | +5.5% | 348 | 2% | 2.75 | 459,228.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −258,028.0% | +9.8% | 177 | 5% | 0.87 | 1,048,420.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +242,656.0% | +8.4% | 35 | 23% | 1.84 | 30,796.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −127,644.0% | +16.7% | 35 | 20% | 0.42 | 199,196.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +10,272.0% | +21.5% | 10 | 40% | 2.13 | 3,908.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −22,624.0% | +148.3% | 34 | 26% | 0.93 | 181,256.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −69,292.0% | +17.1% | 24 | 25% | 0.52 | 112,272.0% | 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 (Ema1Value 5, Ema2Value 34) made −7,640,630.0% before 26 Dec 2025 and +4,346,400.0% after it, worse than the defaults' +5,908,550.0% after. Tuning on the past did not carry forward. 0% of the 64 combinations made money in-sample and 100% out-of-sample.
| Ema2Value ↓ · Ema1Value → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 10 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 12 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 14 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 17 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 20 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 24 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 28 | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% | −8,220,000% |
| 34 | −7,640,630% | −7,640,630% | −7,640,630% | −7,640,630% | −7,640,630% | −7,640,630% | −7,640,630% | −7,640,630% |
| Ema2Value ↓ · Ema1Value → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 10 | +3,060,200% | +3,060,200% | +3,060,200% | +3,060,200% | +3,060,200% | +3,060,200% | +3,060,200% | +3,060,200% |
| 12 | +2,316,200% | +2,316,200% | +2,316,200% | +2,316,200% | +2,316,200% | +2,316,200% | +2,316,200% | +2,316,200% |
| 14 | +2,190,480% | +2,190,480% | +2,190,480% | +2,190,480% | +2,190,480% | +2,190,480% | +2,190,480% | +2,190,480% |
| 17 | +5,344,460% | +5,344,460% | +5,344,460% | +5,344,460% | +5,344,460% | +5,344,460% | +5,344,460% | +5,344,460% |
| 20 | +5,908,550% | +5,908,550% | +5,908,550% | +5,908,550% | +5,908,550% | +5,908,550% | +5,908,550% | +5,908,550% |
| 24 | +4,936,870% | +4,936,870% | +4,936,870% | +4,936,870% | +4,936,870% | +4,936,870% | +4,936,870% | +4,936,870% |
| 28 | +4,025,960% | +4,025,960% | +4,025,960% | +4,025,960% | +4,025,960% | +4,025,960% | +4,025,960% | +4,025,960% |
| 34 | +4,346,400% | +4,346,400% | +4,346,400% | +4,346,400% | +4,346,400% | +4,346,400% | +4,346,400% | +4,346,400% |
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 | 330 | 0% | −$9,900,000.00 |
| Sideways market | 364 | 0% | −$10,920,000.00 |
| Falling market | 99 | 1% | $15,041,400.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1,040,570.0%
The 95th percentile of the worst drawdown when the same 793 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 8,942.0% to 1,040,570.0%; the tick is what actually happened, 12,000.0%. Order luck alone moves it this much.
The first 150 of 793 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 26 Jan 2024 41,823.50 | 27 Jan 2024 41,853.50 | 1 | −$30,000.00 |
| short | 27 Jan 2024 42,120.60 | 28 Jan 2024 42,150.60 | 1 | −$30,000.00 |
| short | 28 Jan 2024 42,031.10 | 29 Jan 2024 42,061.10 | 1 | −$30,000.00 |
| short | 29 Jan 2024 43,302.70 | 30 Jan 2024 43,332.70 | 1 | −$30,000.00 |
| short | 30 Jan 2024 42,941.10 | 31 Jan 2024 42,971.10 | 1 | −$30,000.00 |
| short | 31 Jan 2024 42,580.00 | 1 Feb 2024 42,610.00 | 1 | −$30,000.00 |
| short | 1 Feb 2024 43,082.90 | 2 Feb 2024 43,112.90 | 1 | −$30,000.00 |
| short | 2 Feb 2024 43,200.00 | 3 Feb 2024 43,230.00 | 1 | −$30,000.00 |
| short | 3 Feb 2024 43,011.10 | 4 Feb 2024 43,041.10 | 1 | −$30,000.00 |
| short | 4 Feb 2024 42,582.90 | 5 Feb 2024 42,612.90 | 1 | −$30,000.00 |
| short | 5 Feb 2024 42,708.70 | 6 Feb 2024 42,738.70 | 1 | −$30,000.00 |
| short | 6 Feb 2024 43,098.90 | 7 Feb 2024 43,128.90 | 1 | −$30,000.00 |
| short | 7 Feb 2024 44,349.60 | 8 Feb 2024 44,379.60 | 1 | −$30,000.00 |
| short | 8 Feb 2024 45,288.70 | 9 Feb 2024 45,318.70 | 1 | −$30,000.00 |
| short | 9 Feb 2024 47,132.80 | 10 Feb 2024 47,162.80 | 1 | −$30,000.00 |
| short | 10 Feb 2024 47,751.10 | 11 Feb 2024 47,781.10 | 1 | −$30,000.00 |
| short | 11 Feb 2024 48,300.00 | 12 Feb 2024 48,330.00 | 1 | −$30,000.00 |
| short | 12 Feb 2024 49,917.30 | 13 Feb 2024 49,947.30 | 1 | −$30,000.00 |
| short | 13 Feb 2024 49,699.60 | 14 Feb 2024 49,729.60 | 1 | −$30,000.00 |
| short | 14 Feb 2024 51,795.20 | 15 Feb 2024 51,825.20 | 1 | −$30,000.00 |
| short | 15 Feb 2024 51,880.00 | 16 Feb 2024 51,910.00 | 1 | −$30,000.00 |
| short | 16 Feb 2024 52,124.10 | 17 Feb 2024 52,154.10 | 1 | −$30,000.00 |
| short | 17 Feb 2024 51,642.60 | 18 Feb 2024 51,672.60 | 1 | −$30,000.00 |
| short | 18 Feb 2024 52,137.70 | 19 Feb 2024 52,167.70 | 1 | −$30,000.00 |
| short | 19 Feb 2024 51,774.70 | 20 Feb 2024 51,804.70 | 1 | −$30,000.00 |
| short | 20 Feb 2024 52,258.80 | 21 Feb 2024 52,288.80 | 1 | −$30,000.00 |
| short | 21 Feb 2024 51,849.40 | 22 Feb 2024 51,879.40 | 1 | −$30,000.00 |
| short | 22 Feb 2024 51,288.40 | 23 Feb 2024 51,318.40 | 1 | −$30,000.00 |
| short | 23 Feb 2024 50,744.20 | 24 Feb 2024 50,774.20 | 1 | −$30,000.00 |
| short | 24 Feb 2024 51,568.20 | 25 Feb 2024 51,598.20 | 1 | −$30,000.00 |
| short | 25 Feb 2024 51,728.80 | 26 Feb 2024 51,758.80 | 1 | −$30,000.00 |
| short | 26 Feb 2024 54,476.50 | 27 Feb 2024 54,506.50 | 1 | −$30,000.00 |
| short | 27 Feb 2024 57,037.30 | 28 Feb 2024 57,067.30 | 1 | −$30,000.00 |
| short | 28 Feb 2024 62,432.10 | 29 Feb 2024 62,462.10 | 1 | −$30,000.00 |
| short | 29 Feb 2024 61,131.00 | 1 Mar 2024 61,161.00 | 1 | −$30,000.00 |
| short | 1 Mar 2024 62,387.90 | 2 Mar 2024 62,417.90 | 1 | −$30,000.00 |
| short | 2 Mar 2024 61,987.30 | 3 Mar 2024 62,017.30 | 1 | −$30,000.00 |
| short | 3 Mar 2024 63,114.00 | 4 Mar 2024 63,144.00 | 1 | −$30,000.00 |
| short | 4 Mar 2024 68,245.70 | 5 Mar 2024 68,275.70 | 1 | −$30,000.00 |
| short | 5 Mar 2024 63,724.00 | 6 Mar 2024 63,754.00 | 1 | −$30,000.00 |
| short | 6 Mar 2024 66,074.00 | 7 Mar 2024 66,104.00 | 1 | −$30,000.00 |
| short | 7 Mar 2024 66,823.20 | 8 Mar 2024 66,853.20 | 1 | −$30,000.00 |
| short | 8 Mar 2024 68,124.20 | 9 Mar 2024 68,154.20 | 1 | −$30,000.00 |
| short | 9 Mar 2024 68,313.30 | 10 Mar 2024 68,343.30 | 1 | −$30,000.00 |
| short | 10 Mar 2024 68,955.90 | 11 Mar 2024 68,985.90 | 1 | −$30,000.00 |
| short | 11 Mar 2024 72,078.10 | 12 Mar 2024 72,108.10 | 1 | −$30,000.00 |
| short | 12 Mar 2024 71,452.00 | 13 Mar 2024 71,482.00 | 1 | −$30,000.00 |
| short | 13 Mar 2024 73,072.40 | 14 Mar 2024 73,102.40 | 1 | −$30,000.00 |
| short | 14 Mar 2024 71,388.90 | 15 Mar 2024 71,418.90 | 1 | −$30,000.00 |
| short | 15 Mar 2024 69,499.90 | 16 Mar 2024 69,529.90 | 1 | −$30,000.00 |
| short | 16 Mar 2024 65,300.60 | 17 Mar 2024 65,330.60 | 1 | −$30,000.00 |
| short | 17 Mar 2024 68,393.50 | 18 Mar 2024 68,423.50 | 1 | −$30,000.00 |
| short | 18 Mar 2024 67,610.00 | 19 Mar 2024 67,640.00 | 1 | −$30,000.00 |
| short | 19 Mar 2024 61,937.40 | 20 Mar 2024 61,967.40 | 1 | −$30,000.00 |
| short | 20 Mar 2024 67,840.50 | 21 Mar 2024 67,870.50 | 1 | −$30,000.00 |
| short | 21 Mar 2024 65,501.30 | 22 Mar 2024 65,531.30 | 1 | −$30,000.00 |
| short | 22 Mar 2024 63,796.60 | 23 Mar 2024 63,826.60 | 1 | −$30,000.00 |
| short | 23 Mar 2024 63,990.00 | 24 Mar 2024 64,020.00 | 1 | −$30,000.00 |
| short | 24 Mar 2024 67,210.00 | 25 Mar 2024 67,240.00 | 1 | −$30,000.00 |
| long | 25 Mar 2024 69,880.00 | 26 Mar 2024 69,850.00 | 1 | −$30,000.00 |
| long | 26 Mar 2024 69,988.00 | 27 Mar 2024 69,958.00 | 1 | −$30,000.00 |
| long | 27 Mar 2024 69,470.00 | 28 Mar 2024 69,440.00 | 1 | −$30,000.00 |
| long | 28 Mar 2024 70,780.60 | 29 Mar 2024 70,750.60 | 1 | −$30,000.00 |
| long | 29 Mar 2024 69,850.50 | 30 Mar 2024 69,820.50 | 1 | −$30,000.00 |
| long | 30 Mar 2024 69,582.20 | 1 Apr 2024 69,552.20 | 2 | −$30,000.00 |
| long | 1 Apr 2024 69,649.80 | 2 Apr 2024 69,619.80 | 1 | −$30,000.00 |
| long | 2 Apr 2024 65,464.00 | 3 Apr 2024 65,434.00 | 1 | −$30,000.00 |
| long | 3 Apr 2024 65,963.30 | 4 Apr 2024 65,933.30 | 1 | −$30,000.00 |
| long | 4 Apr 2024 68,487.80 | 5 Apr 2024 68,457.80 | 1 | −$30,000.00 |
| long | 5 Apr 2024 67,820.60 | 6 Apr 2024 67,790.60 | 1 | −$30,000.00 |
| long | 6 Apr 2024 68,896.00 | 7 Apr 2024 68,866.00 | 1 | −$30,000.00 |
| long | 7 Apr 2024 69,360.40 | 8 Apr 2024 69,330.40 | 1 | −$30,000.00 |
| long | 8 Apr 2024 71,620.00 | 9 Apr 2024 71,590.00 | 1 | −$30,000.00 |
| long | 9 Apr 2024 69,146.00 | 10 Apr 2024 69,116.00 | 1 | −$30,000.00 |
| long | 10 Apr 2024 70,631.10 | 11 Apr 2024 70,601.10 | 1 | −$30,000.00 |
| long | 11 Apr 2024 70,006.20 | 12 Apr 2024 69,976.20 | 1 | −$30,000.00 |
| long | 12 Apr 2024 67,116.50 | 13 Apr 2024 67,086.50 | 1 | −$30,000.00 |
| long | 13 Apr 2024 63,924.50 | 14 Apr 2024 63,894.50 | 1 | −$30,000.00 |
| long | 14 Apr 2024 65,661.80 | 15 Apr 2024 65,631.80 | 1 | −$30,000.00 |
| long | 15 Apr 2024 63,420.00 | 16 Apr 2024 63,390.00 | 1 | −$30,000.00 |
| long | 16 Apr 2024 63,793.40 | 17 Apr 2024 63,763.40 | 1 | −$30,000.00 |
| long | 17 Apr 2024 61,277.40 | 18 Apr 2024 61,247.40 | 1 | −$30,000.00 |
| long | 18 Apr 2024 63,470.10 | 19 Apr 2024 63,440.10 | 1 | −$30,000.00 |
| long | 19 Apr 2024 63,818.00 | 20 Apr 2024 63,788.00 | 1 | −$30,000.00 |
| long | 20 Apr 2024 64,940.60 | 21 Apr 2024 64,910.60 | 1 | −$30,000.00 |
| long | 21 Apr 2024 64,941.20 | 22 Apr 2024 64,911.20 | 1 | −$30,000.00 |
| long | 22 Apr 2024 66,819.30 | 23 Apr 2024 66,789.30 | 1 | −$30,000.00 |
| long | 23 Apr 2024 66,414.00 | 24 Apr 2024 66,384.00 | 1 | −$30,000.00 |
| long | 24 Apr 2024 64,289.60 | 25 Apr 2024 64,259.60 | 1 | −$30,000.00 |
| long | 25 Apr 2024 64,498.30 | 26 Apr 2024 64,468.30 | 1 | −$30,000.00 |
| long | 26 Apr 2024 63,770.00 | 27 Apr 2024 63,740.00 | 1 | −$30,000.00 |
| long | 27 Apr 2024 63,462.00 | 28 Apr 2024 63,432.00 | 1 | −$30,000.00 |
| long | 28 Apr 2024 63,118.60 | 29 Apr 2024 63,088.60 | 1 | −$30,000.00 |
| long | 29 Apr 2024 63,866.00 | 30 Apr 2024 63,836.00 | 1 | −$30,000.00 |
| long | 30 Apr 2024 60,672.00 | 1 May 2024 60,642.00 | 1 | −$30,000.00 |
| long | 1 May 2024 58,365.00 | 2 May 2024 58,335.00 | 1 | −$30,000.00 |
| long | 2 May 2024 59,060.60 | 3 May 2024 59,030.60 | 1 | −$30,000.00 |
| long | 3 May 2024 62,882.00 | 4 May 2024 62,852.00 | 1 | −$30,000.00 |
| long | 4 May 2024 63,892.00 | 5 May 2024 63,862.00 | 1 | −$30,000.00 |
| long | 5 May 2024 64,012.00 | 6 May 2024 63,982.00 | 1 | −$30,000.00 |
| long | 6 May 2024 63,165.20 | 7 May 2024 63,135.20 | 1 | −$30,000.00 |
| long | 7 May 2024 62,312.10 | 8 May 2024 62,282.10 | 1 | −$30,000.00 |
| long | 8 May 2024 61,193.00 | 9 May 2024 61,163.00 | 1 | −$30,000.00 |
| long | 9 May 2024 63,074.00 | 10 May 2024 63,044.00 | 1 | −$30,000.00 |
| long | 10 May 2024 60,800.00 | 11 May 2024 60,770.00 | 1 | −$30,000.00 |
| long | 11 May 2024 60,826.00 | 12 May 2024 60,796.00 | 1 | −$30,000.00 |
| long | 12 May 2024 61,484.00 | 13 May 2024 61,454.00 | 1 | −$30,000.00 |
| long | 13 May 2024 62,940.10 | 14 May 2024 62,910.10 | 1 | −$30,000.00 |
| short | 14 May 2024 61,577.50 | 15 May 2024 61,607.50 | 1 | −$30,000.00 |
| short | 15 May 2024 66,206.50 | 16 May 2024 66,236.50 | 1 | −$30,000.00 |
| long | 16 May 2024 65,235.20 | 17 May 2024 65,205.20 | 1 | −$30,000.00 |
| long | 17 May 2024 67,024.00 | 18 May 2024 66,994.00 | 1 | −$30,000.00 |
| long | 18 May 2024 66,915.20 | 19 May 2024 66,885.20 | 1 | −$30,000.00 |
| long | 19 May 2024 66,274.00 | 20 May 2024 66,244.00 | 1 | −$30,000.00 |
| long | 20 May 2024 71,446.60 | 21 May 2024 71,416.60 | 1 | −$30,000.00 |
| long | 21 May 2024 70,148.30 | 22 May 2024 70,118.30 | 1 | −$30,000.00 |
| long | 22 May 2024 69,166.60 | 23 May 2024 69,136.60 | 1 | −$30,000.00 |
| long | 23 May 2024 67,969.60 | 24 May 2024 67,939.60 | 1 | −$30,000.00 |
| long | 24 May 2024 68,550.00 | 25 May 2024 68,520.00 | 1 | −$30,000.00 |
| long | 25 May 2024 69,290.60 | 26 May 2024 69,260.60 | 1 | −$30,000.00 |
| long | 26 May 2024 68,507.70 | 27 May 2024 68,477.70 | 1 | −$30,000.00 |
| long | 27 May 2024 69,436.40 | 28 May 2024 69,406.40 | 1 | −$30,000.00 |
| long | 28 May 2024 68,398.40 | 29 May 2024 68,368.40 | 1 | −$30,000.00 |
| long | 29 May 2024 67,652.40 | 30 May 2024 67,622.40 | 1 | −$30,000.00 |
| long | 30 May 2024 68,352.20 | 31 May 2024 68,322.20 | 1 | −$30,000.00 |
| long | 31 May 2024 67,540.00 | 1 Jun 2024 67,510.00 | 1 | −$30,000.00 |
| long | 1 Jun 2024 67,766.90 | 2 Jun 2024 67,736.90 | 1 | −$30,000.00 |
| long | 2 Jun 2024 67,765.60 | 3 Jun 2024 67,735.60 | 1 | −$30,000.00 |
| long | 3 Jun 2024 68,809.90 | 4 Jun 2024 68,779.90 | 1 | −$30,000.00 |
| long | 4 Jun 2024 70,537.80 | 5 Jun 2024 70,507.80 | 1 | −$30,000.00 |
| long | 5 Jun 2024 71,108.00 | 6 Jun 2024 71,078.00 | 1 | −$30,000.00 |
| long | 6 Jun 2024 70,799.10 | 7 Jun 2024 70,769.10 | 1 | −$30,000.00 |
| long | 7 Jun 2024 69,355.60 | 8 Jun 2024 69,325.60 | 1 | −$30,000.00 |
| long | 8 Jun 2024 69,310.50 | 9 Jun 2024 69,280.50 | 1 | −$30,000.00 |
| long | 9 Jun 2024 69,648.10 | 10 Jun 2024 69,618.10 | 1 | −$30,000.00 |
| long | 10 Jun 2024 69,540.00 | 11 Jun 2024 69,510.00 | 1 | −$30,000.00 |
| long | 11 Jun 2024 67,314.20 | 12 Jun 2024 67,284.20 | 1 | −$30,000.00 |
| long | 12 Jun 2024 68,264.00 | 13 Jun 2024 68,234.00 | 1 | −$30,000.00 |
| long | 13 Jun 2024 66,773.00 | 14 Jun 2024 66,743.00 | 1 | −$30,000.00 |
| long | 14 Jun 2024 66,044.00 | 15 Jun 2024 66,014.00 | 1 | −$30,000.00 |
| long | 15 Jun 2024 66,228.30 | 16 Jun 2024 66,198.30 | 1 | −$30,000.00 |
| long | 16 Jun 2024 66,676.90 | 17 Jun 2024 66,646.90 | 1 | −$30,000.00 |
| long | 17 Jun 2024 66,504.30 | 18 Jun 2024 66,474.30 | 1 | −$30,000.00 |
| long | 18 Jun 2024 65,175.30 | 19 Jun 2024 65,145.30 | 1 | −$30,000.00 |
| long | 19 Jun 2024 64,974.40 | 20 Jun 2024 64,944.40 | 1 | −$30,000.00 |
| long | 20 Jun 2024 64,870.00 | 21 Jun 2024 64,840.00 | 1 | −$30,000.00 |
| long | 21 Jun 2024 64,143.60 | 22 Jun 2024 64,113.60 | 1 | −$30,000.00 |
| long | 22 Jun 2024 64,262.00 | 23 Jun 2024 64,232.00 | 1 | −$30,000.00 |
| long | 23 Jun 2024 63,210.00 | 24 Jun 2024 63,180.00 | 1 | −$30,000.00 |
| short | 24 Jun 2024 60,293.30 | 25 Jun 2024 60,323.30 | 1 | −$30,000.00 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| [Strategy] - EMA 10,20 59 with Profit Displayed this page | — | v4 strategy | −2,311,450.0% | 793 | 8,424,000.0% |
| Mathias & Christer EMA by mattehalen | ema barssince | v4 strategy | No trades on this market | ||
| Dazzling Bolts by OrcChieftain | ema barssince | v4 strategy | +8.5% | 14 | 13.0% |
| Triple Supertrend with EMA and ADX strategy by kunjandetroja | ema barssince | v5 strategy | −1.0% | 58 | 5.3% |
| Momentum Strategy (BTC-USDT; 30m) - STOCH RSI (with source code) by Drun30 | ema barssince | v4 strategy | +13.3% | 12 | 13.6% |
| Twin Range Filter Algo by OrcChieftain | ema barssince | v4 strategy | +48.4% | 18 | 6.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 50 ms | With a workaround 1,000 bars in 83 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 69, 76) 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/// © mattehalen//@version=4//study("EMA 10,20 59",overlay=true)strategy("EMA 10,20 59",overlay=true, process_orders_on_close = true, default_qty_type = strategy.fixed, default_qty_value = 1000, initial_capital=250, currency=currency.USD)infoBox = input(true, title="infoBox", type=input.bool)infoBox2 = input(false, title="infoBox2", type=input.bool)BuySellSignal_Bool = input(false, title="Buy & SellSignal", type=input.bool)infoBoxSize = input(title="infoBoxSize", defval=size.large, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge])ema1Value = input(10)ema2Value = input(20)ema3Value = input(59)maxLoss = input(3000)ema1 = ema(close,ema1Value)ema2 = ema(close,ema2Value)ema3 = ema(close,ema3Value)objcnt = 0buyTitle = tostring(close[1])myProfit = float(0)plot(ema1,title="ema1",color=color.red,linewidth=2)plot(ema2,title="ema2",color=color.green,linewidth=2)plot(ema3,title="ema3",color=color.black,linewidth=2)Buytrend = (ema1 and ema2 > ema3) and (ema1[1] and ema2[1] > ema3[1])BarssinceBuyTrend = barssince(Buytrend)BarssinceSellTrend = barssince(not Buytrend)closeAtBuyTrend = close[1]bgcolor(Buytrend ? color.green : color.red,transp=70)BuySignal = Buytrend and not Buytrend[1] and BuySellSignal_BoolBuySignalOut = Buytrend and (crossunder(ema1,ema2)) and BuySellSignal_BoolBarssinceBuy = barssince(BuySignal)bgcolor(BuySignal ? color.green : na , transp=30)bgcolor(BuySignalOut ? color.black : na , transp=30)plot(BarssinceBuy,title="BarssinceBuy",display=display.none)SellSignal = not Buytrend and Buytrend[1] and BuySellSignal_BoolSellSignalOut = not Buytrend and (crossover(ema1,ema2)) and BuySellSignal_BoolBarssinceSell = barssince(SellSignal)bgcolor(SellSignal ? color.red : na , transp=30)bgcolor(SellSignalOut ? color.black : na , transp=30)plot(BarssinceSell,title="BarssinceSell",display=display.none)buyProfit = float(0)cntBuy =0sellProfit = float(0)cntSell =0buyProfit := Buytrend and not Buytrend[1]? nz(buyProfit[1]) + (close[BarssinceBuyTrend[1]]-close) : nz(buyProfit[1])cntBuy := Buytrend and not Buytrend[1]? nz(cntBuy[1]) + 1: nz(cntBuy[1])sellProfit := not Buytrend and Buytrend[1]? nz(sellProfit[1]) + (close-close[BarssinceSellTrend[1]]) : nz(sellProfit[1])cntSell := not Buytrend and Buytrend[1]? nz(cntSell[1]) + 1 : nz(cntSell[1])totalProfit = buyProfit + sellProfitif (Buytrend and not Buytrend[1] and infoBox==true) l = label.new(bar_index - (BarssinceBuyTrend[1]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuyTrend[1]]) + "\n" + "Profit = "+tostring(close[BarssinceBuyTrend[1]]-close) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.red,size=infoBoxSize)if (not Buytrend and Buytrend[1] and infoBox==true) l = label.new(bar_index - (BarssinceSellTrend[1]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSellTrend[1]]) + "\n" + "Profit = "+tostring(close-close[BarssinceSellTrend[1]]) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.green,size=infoBoxSize)if (BuySignalOut and not BuySignalOut[1] and infoBox2==true)// l = label.new(bar_index - (BarssinceBuy[0]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.purple,size=infoBoxSize l = label.new(bar_index, na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.lime,size=infoBoxSize)if (SellSignalOut and not SellSignalOut[1] and infoBox2==true)// l = label.new(bar_index - (BarssinceSell[0]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.purple,size=infoBoxSize) l = label.new(bar_index, na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.fuchsia,size=infoBoxSize)l2 = label.new(bar_index, na, 'buyProfit in pip = '+tostring(buyProfit)+"\n"+ 'cntBuy = '+tostring(cntBuy) +"\n"+ 'sellProfit in pip = '+tostring(sellProfit)+"\n"+ 'cntSell = '+tostring(cntSell) +"\n"+ 'totalProfit in pip = '+tostring(totalProfit) , color=totalProfit>0 ? color.green : color.red, textcolor=color.white, style=label.style_labeldown, yloc=yloc.abovebar, size=size.large)label.delete(l2[1])//--------------------------------------------------//--------------------------------------------------if (Buytrend) strategy.close("short", comment = "Exit short") strategy.entry("long", true) strategy.exit("Max Loss", "long", loss = maxLoss)//if BuySignalOut // strategy.close("long", comment = "Exit Long")if (not Buytrend) // Enter trade and issue exit order on max loss. strategy.close("long", comment = "Exit Long") strategy.entry("short", false) strategy.exit("Max Loss", "short", loss = maxLoss)//if SellSignalOut // Force trade exit. //strategy.close("short", comment = "Exit short") //--------------------------------------------------//--------------------------------------------------//--------------------------------------------------