Pine Script v5 · Strategy
MACD Strategy
A Pine Script v5 strategy built on ATR (14), Highest (high, 7) and Lowest (low, 7). It has 48 order rules, 32 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 29 settings; defaults include Alert PineConnector, License ID (PineConnector) 1234567890123 and Risk per Trade % 2.
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 MACD Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did MACD Strategy do on BTCUSDT 1D with default settings?
- +5.75%
- From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does MACD Strategy have?
- 8
- " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0; " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0; " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0; " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0; and more.
- Does MACD Strategy run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L86:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download.
- Does MACD Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 270, 273, 287, 290, 302, 304, 315, 317, 328, 331, 341, 344.
BTCUSDT · 1D · default settings
- ParabolicSAR
- EMA
- Swing High
- Swing Low
- entry price
- stopLoss
- takeProfit2
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Symbole | Net Profit | Trades | Period |
| BTCUSDT | 5.75 % | 5 | 30 day |
- Net profit
- +5.75%
- $57.52
- Buy and hold
- +102.5%
- same period
- Closed trades
- 5
- 2 won · 3 lost
- Profitable
- 40.0%
- of closed trades
- Profit factor
- 1.98
- gross profit ÷ gross loss
- Max drawdown
- 6.89%
- −$68.87
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.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog start (line 38), increment (line 39) 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 111, 114, 130, 133, 151, 154, 168, 171, 188, 191, 207, 210, 227, 230, 244, 247. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| AlertGo to alertatron to have alerts automatically sent to Telegram | PineConnector | string · options ["PineConnector", "Telegram"] | entry long entry long entry long entry long entry short entry short entry short entry short entry long entry long entry long entry long entry short entry short entry short entry short entry long entry long entry long entry long entry short entry short entry short entry short entry long entry long entry long entry long entry short entry short entry short entry short exit Exit long exit Exit long exit Exit short exit Exit short line 110 line 113 line 117 line 120 line 129 line 132 line 136 line 139 line 150 line 153 line 156 line 159 line 167 line 170 line 173 line 176 line 187 line 190 line 194 line 197 line 206 line 209 line 213 line 216 line 226 line 229 line 232 line 235 line 243 line 246 line 249 line 252 line 256 line 292 line 325 line 330 line 338 line 343 |
| Setting | |||
| License ID (PineConnector) | 1234567890123 | string | mess_buyP mess_sellP mess_buyAP mess_sellAP mess_buyAMP1 mess_buyAMP2 mess_sellAMP1 mess_sellAMP2 mess_buyMP1 mess_buyMP2 mess_sellMP1 mess_sellMP2 |
| Risk per Trade % | 2 | float · step 0.5 | riskt mess_buyT mess_sellT mess_buyP mess_sellP mess_buyAT mess_sellAT mess_buyAP mess_sellAP mess_buyAMT mess_sellAMT mess_buyAMP1 mess_buyAMP2 mess_sellAMP1 mess_sellAMP2 mess_buyMT mess_sellMT mess_buyMP1 mess_buyMP2 mess_sellMP1 mess_sellMP2 mess_profit1 mess_profit2 mess_loss mess_profit |
| StopLoss | Swing | string · options ["Swing", "ATR"] | exswingH exswingL exatrS exatrB line 102 line 179 |
| TakeProfit | R:R | string · options ["R:R", "Multiple Target"] | line 103 line 143 line 180 line 220 line 255 line 319 |
| do not take too small positionsThis parameter is used to avoid positions that have a stoploss too close to the entry point and that the broker's spreads take all the gains | false | bool | line 109 line 128 line 149 line 166 line 186 line 205 line 225 line 242 |
| min of pips (00001.00) | 10 | float | entry long entry short |
| Backtest Time Period | |||
| Filter Date Range of Backtest | false | bool | inTradeWindow |
| Start DateThis start date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer. | timestamp("1 June 2022") | time | inTradeWindow periodzone |
| End DateThis end date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer. | timestamp("1 July 2022") | time | inTradeWindow periodzone |
| Stop Loss | |||
| Swing HighNumber of candles in which the parameter targets the highest | 7 | int | swingHigh |
| Swing LowNumber of candles in which the parameter targets the lowest | 7 | int | swingLow |
| ATR Period | 14 | int | atr |
| ATR Multiplier | 2 | int | atrSell atrBuy |
| TakeProfit | |||
| Risk/Reward (R:R) | 3 | float · min 0.5 · max 100 · step 0.1 | mess_buyT mess_sellT mess_buyP mess_sellP mess_buyAT mess_sellAT mess_buyAP mess_sellAP takeProfit1 mess_profit |
| Target 1 R:R (Multiple Target)SL moved to entry point if hit | 1 | float · step 0.1 | mess_buyAMT mess_sellAMT mess_buyAMP1 mess_buyAMP2 mess_sellAMP1 mess_sellAMP2 mess_buyMT mess_sellMT mess_buyMP1 mess_buyMP2 mess_sellMP1 mess_sellMP2 takeProfit1 mess_profit1 |
| Target 2 R:R (Multiple Target) | 2 | float · step 0.1 | mess_buyAMT mess_sellAMT mess_buyAMP2 mess_sellAMP2 mess_buyMT mess_sellMT mess_buyMP2 mess_sellMP2 takeProfit2 mess_profit2 |
| EMA | |||
| Source | close | source | ema |
| Length | 200 | int | ema |
| Parabolic SAR | |||
| Parabolic SAR Indicator | true | bool | exsar line 88 line 91 |
| Start (no label in the script) | 0.02 | float | SAR |
| Increment (no label in the script) | 0.02 | float | SAR |
| Max Value | 0.2 | float | SAR |
| MACD | |||
| Source | close | source | fast_ma slow_ma |
| Fast Length | 12 | int | fast_ma |
| Slow Length | 26 | int | slow_ma |
| Signal Smoothing | 9 | int · min 1 · max 50 | signal |
| Oscillator MA Type | EMA | string · options ["SMA", "EMA"] | fast_ma slow_ma |
| Signal Line MA Type | EMA | string · options ["SMA", "EMA"] | signal |
What it calculates
- ATRATR Period (14)
atr · line 23 - Highesthigh, Swing High (7)
swingHigh · line 24 - Lowestlow, Swing Low (7)
swingLow · line 25 - EMASource (close), Length (200)
ema · line 35 - SARStart (0.02), Increment (0.02), Max Value (0.2)
SAR · line 41 - SMA / EMASource (close), Fast Length (12) · chosen by Oscillator MA Type
fast_ma · line 50 - SMA / EMASource (close), Slow Length (26) · chosen by Oscillator MA Type
slow_ma · line 51 - SMA / EMAmacd, Signal Smoothing (9) · chosen by Signal Line MA Type
signal · line 53
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.
The script has 87 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | minp > security | On | 111 |
| Open long long | minp > security | On | 114 |
| Open long long | tlpc == "Telegram" | On | 118 |
| Open long long | tlpc == "PineConnector" | On | 121 |
| Open short short | minp > security | On | 130 |
| Open short short | minp > security | On | 133 |
| Open short short | tlpc == "Telegram" | On | 137 |
| Open short short | tlpc == "PineConnector" | On | 140 |
| Open long long | minp > security | On | 151 |
| Open long long | minp > security | On | 154 |
| Open long long | tlpc == "Telegram" | On | 157 |
| Open long long | tlpc == "PineConnector" | On | 160 |
| Open short short | minp > security | On | 168 |
| Open short short | minp > security | On | 171 |
| Open short short | tlpc == "Telegram" | On | 174 |
| Open short short | tlpc == "PineConnector" | On | 177 |
| Open long long | minp > security | On | 188 |
| Open long long | minp > security | On | 191 |
| Open long long | tlpc == "Telegram" | On | 195 |
| Open long long | tlpc == "PineConnector" | On | 198 |
| Open short short | minp > security | On | 207 |
| Open short short | minp > security | On | 210 |
| Open short short | tlpc == "Telegram" | On | 214 |
| Open short short | tlpc == "PineConnector" | On | 217 |
| Open long long | minp > security | On | 227 |
| Open long long | minp > security | On | 230 |
| Open long long | tlpc == "Telegram" | On | 233 |
| Open long long | tlpc == "PineConnector" | On | 236 |
| Open short short | minp > security | On | 244 |
| Open short short | minp > security | On | 247 |
| Open short short | tlpc == "Telegram" | On | 250 |
| Open short short | tlpc == "PineConnector" | On | 253 |
| Exit Exit 1 limit | strategy.position_size > 0 | On | 265 |
| Exit Exit 2 stop and limit | ta.crossover(high, takeProfit1) | On | 270 |
| Exit Exit 1 stop | ta.crossover(high, takeProfit1) | On | 273 |
| Exit Exit 1 limit | strategy.position_size < 0 | On | 282 |
| Exit Exit 2 stop and limit | ta.crossunder(low, takeProfit1) | On | 287 |
| Exit Exit 1 stop | ta.crossunder(low, takeProfit1) | On | 290 |
| Exit Exit 1 limit | strategy.position_size > 0 | On | 299 |
| Exit Exit 2 stop and limit | ta.crossover(high, takeProfit1) | On | 302 |
| Exit Exit 1 stop | ta.crossover(high, takeProfit1) | On | 304 |
| Exit Exit 1 limit | strategy.position_size < 0 | On | 312 |
| Exit Exit 2 stop and limit | ta.crossunder(low, takeProfit1) | On | 315 |
| Exit Exit 1 stop | ta.crossunder(low, takeProfit1) | On | 317 |
| Exit Exit long stop and limit | tlpc == "Telegram" | On | 328 |
| Exit Exit long stop and limit | tlpc == "PineConnector" | On | 331 |
| Exit Exit short stop and limit | tlpc == "Telegram" | On | 341 |
| Exit Exit short stop and limit | tlpc == "PineConnector" | On | 344 |
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 | " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0 | 115 |
| (no title) | alert | " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0 | 122 |
| (no title) | alert | " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0 | 134 |
| (no title) | alert | " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0 | 141 |
| (no title) | alert | " + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingLow) + ",tp=" + str.tostring(((close-swingLow)*target2)+close) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring(((((close-swingLow)*target1)+close)-close)/getpips()) + ",beoffset=0 | 192 |
| (no title) | alert | " + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingLow) + ",tp=" + str.tostring(((close-swingLow)*target2)+close) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring(((((close-swingLow)*target1)+close)-close)/getpips()) + ",beoffset=0 | 199 |
| (no title) | alert | " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingHigh) + ",tp=" + str.tostring(close-((swingHigh-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((swingHigh-close)*target1)))/getpips()) + ",beoffset=0 | 211 |
| (no title) | alert | " + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingHigh) + ",tp=" + str.tostring(close-((swingHigh-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((swingHigh-close)*target1)))/getpips()) + ",beoffset=0 | 218 |
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 | +5.8% | +102.5% | 5 | 40% | 1.98 | 6.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +7.6% | +5.5% | 7 | 43% | 1.73 | 5.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.6% | +9.8% | 7 | 29% | 1.16 | 8.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +14.4% | +8.4% | 5 | 60% | 4.05 | 4.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −4.2% | +16.7% | 6 | 17% | 0.57 | 6.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −7.7% | +21.5% | 7 | 14% | 0.41 | 11.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −4.2% | +148.3% | 6 | 17% | 0.58 | 5.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +18.8% | +17.1% | 7 | 57% | 3.69 | 2.5% | 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 | 4 | 25% | −$2.34 |
| Falling market | 1 | 100% | $59.86 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.9%
The 95th percentile of the worst drawdown when the same 5 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.0% to 5.9%; the tick is what actually happened, 5.9%. Order luck alone moves it this much.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 2 Oct 2024 60,804.90 | 14 Oct 2024 66,497.10 | 12 | −$20.00 |
| long | 21 Feb 2025 98,305.00 | 24 Feb 2025 93,388.10 | 3 | −$19.60 |
| long | 7 Mar 2025 89,931.90 | 10 Mar 2025 78,258.50 | 3 | −$19.21 |
| long | 7 Sep 2025 110,188.00 | 2 Oct 2025 118,987.00 | 25 | $56.47 |
| short | 21 Jan 2026 88,427.70 | 5 Jun 2026 59,937.20 | 135 | $59.86 |
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 |
|---|---|---|---|---|---|
| MACD Strategy this page | — | v5 strategy | +5.8% | 5 | 6.9% |
| CHOP Zone Entry Strategy + DMI-PSAR Exit by IronCasper | atr highest lowest sma sar ema | v4 strategy | +17.1% | 8 | 20.0% |
| ATR + STC + MA by Romedius | ema lowest highest atr sma | v5 strategy | −1.2% | 15 | 3.3% |
| -NoSKi Hammer-Star -w angle of ema Backtester - by noski1 | atr ema sma highest lowest | v5 strategy | does not run in Zeal Terminal | ||
| LONG SAZB $ by stevenz17 | ema sma atr lowest highest | v4 strategy | No trades on this market | ||
| DC Breakout Strategy - This is simplicity at its finest. by Robrecht99 | sma highest lowest atr | v5 strategy | +10.8% | 57 | 8.3% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 16 strategy calls use the when = argument (line 111, 114, 130, 133, 151, 154, 168, 171, 188, 191, 207, 210, 227, 230, 244, 247). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 8 settings use the untyped input() (line 7, 33, 38, 39, 40, 44, 45, 46). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.string()
- Line 33: input() → input.source()
- Line 38: input() → input.float()
- Line 39: input() → input.float()
- Line 40: input() → input.float()
- Line 44: input() → input.source()
18 more edits
- Line 45: input() → input.int()
- Line 46: input() → input.int()
- Line 111: when = minp > security → if block
- Line 114: when = minp > security → if block
- Line 130: when = minp > security → if block
- Line 133: when = minp > security → if block
- Line 151: when = minp > security → if block
- Line 154: when = minp > security → if block
- Line 168: when = minp > security → if block
- Line 171: when = minp > security → if block
- Line 188: when = minp > security → if block
- Line 191: when = minp > security → if block
- Line 207: when = minp > security → if block
- Line 210: when = minp > security → if block
- Line 227: when = minp > security → if block
- Line 230: when = minp > security → if block
- Line 244: when = minp > security → if block
- Line 247: when = minp > security → if block
⋯// Setting -ID = input("1234567890123", title="License ID (PineConnector)", group="Setting")+ID = input.string("1234567890123", title="License ID (PineConnector)", group="Setting")risk = input.float(2, title="Risk per Trade %", group="Setting", step=0.5)⋯//EMA-src1 = input(title="Source", defval=close, group="EMA")+src1 = input.source(title="Source", defval=close, group="EMA")emaV = input.int(200, title="Length", group="EMA")⋯sarT = input.bool(true, title="Parabolic SAR Indicator", group="Parabolic SAR")-start = input(0.02, group="Parabolic SAR")+start = input.float(0.02, group="Parabolic SAR")-increment = input(0.02, group="Parabolic SAR")+increment = input.float(0.02, group="Parabolic SAR")-maximum = input(0.2, "Max Value", group="Parabolic SAR")+maximum = input.float(0.2, "Max Value", group="Parabolic SAR")SAR = ta.sar(start, increment, maximum)⋯//MACD-src = input(title="Source", defval=close, group="MACD")+src = input.source(title="Source", defval=close, group="MACD")-fast_length = input(title="Fast Length", defval=12, group="MACD")+fast_length = input.int(title="Fast Length", defval=12, group="MACD")-slow_length = input(title="Slow Length", defval=26, group="MACD")+slow_length = input.int(title="Slow Length", defval=26, group="MACD")signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9, group="MACD")⋯ if tlpc == "Telegram" - strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMT, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMT) if tlpc == "PineConnector" - strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMP1, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMP1) alert(mess_sellAMP2, alert.freq_once_per_bar_close)⋯ if tlpc == "Telegram" - strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMT, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMT) if tlpc == "PineConnector" - strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMP1, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMP1) alert(mess_sellAMP2, alert.freq_once_per_bar_close)⋯ if tlpc == "Telegram" - strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAT, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAT) if tlpc == "PineConnector" - strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAP, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAP) else ⋯ if tlpc == "Telegram" - strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAT, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAT) if tlpc == "PineConnector" - strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAP, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAP) else ⋯ if tlpc == "Telegram" - strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMT, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMT) if tlpc == "PineConnector" - strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMP1, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMP1) alert(mess_buyMP2, alert.freq_once_per_bar_close)⋯ if tlpc == "Telegram" - strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMT, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMT) if tlpc == "PineConnector" - strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMP1, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMP1) alert(mess_sellMP2, alert.freq_once_per_bar_close)⋯ if tlpc == "Telegram" - strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyT, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyT) if tlpc == "PineConnector" - strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyP, when = minp > security)+ if minp > security+ strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyP) else ⋯ if tlpc == "Telegram" - strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellT, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellT) if tlpc == "PineConnector" - strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellP, when = minp > security)+ if minp > security+ strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellP) else ⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L86:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © maxencetajet-//@version=5+//@version=6strategy("MACD Strategy", overlay=true, initial_capital=1000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 1,777 ms | Yes 1,000 bars in 305 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © maxencetajet//@version=5strategy("MACD Strategy", overlay=true, initial_capital=1000)tlpc = input.string(title="Alert", defval="PineConnector", options=["PineConnector", "Telegram"], tooltip="Go to alertatron to have alerts automatically sent to Telegram")// Setting ID = input("1234567890123", title="License ID (PineConnector)", group="Setting")risk = input.float(2, title="Risk per Trade %", group="Setting", step=0.5)typeSL = input.string(title="StopLoss", defval="Swing", options=["Swing", "ATR"], group="Setting")typeTP = input.string(title="TakeProfit", defval="R:R", options=["R:R", "Multiple Target"], group="Setting")_x = input.bool(false, title="do not take too small positions", group="Setting", tooltip="This parameter is used to avoid positions that have a stoploss too close to the entry point and that the broker's spreads take all the gains")security = input.float(10, title="min of pips (00001.00)", group="Setting")riskt = risk / 100 + 1useDateFilter = input.bool(false, title="Filter Date Range of Backtest", group="Backtest Time Period")backtestStartDate = input.time(timestamp("1 June 2022"), title="Start Date", group="Backtest Time Period", tooltip="This start date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer.")backtestEndDate = input.time(timestamp("1 July 2022"), title="End Date", group="Backtest Time Period", tooltip="This end date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer.")inTradeWindow = not useDateFilter or (time >= backtestStartDate and time < backtestEndDate)//StopLossswingHighV = input.int(7, title="Swing High", group="Stop Loss", tooltip="Number of candles in which the parameter targets the highest")swingLowV = input.int(7, title="Swing Low", group="Stop Loss", tooltip="Number of candles in which the parameter targets the lowest")atr1 = input.int(14, title="ATR Period", group="Stop Loss")atrMultiplierSL = input.int(2, title = "ATR Multiplier", group="Stop Loss")atr = ta.atr(atr1)swingHigh = ta.highest(high, swingHighV)swingLow = ta.lowest(low, swingLowV)atrSell = close + atr * atrMultiplierSLatrBuy = close - atr * atrMultiplierSL//TakeProfittarget_stop_ratio = input.float(title='Risk/Reward (R:R)', defval=3, minval=0.5, maxval=100, step=0.1, group="TakeProfit")target1 = input.float(1, title='Target 1 R:R (Multiple Target)', group="TakeProfit", step=0.1, tooltip="SL moved to entry point if hit")target2 = input.float(2, title='Target 2 R:R (Multiple Target)', group="TakeProfit", step=0.1)//EMAsrc1 = input(title="Source", defval=close, group="EMA")emaV = input.int(200, title="Length", group="EMA")ema = ta.ema(src1, emaV)//Parabolic SARsarT = input.bool(true, title="Parabolic SAR Indicator", group="Parabolic SAR")start = input(0.02, group="Parabolic SAR")increment = input(0.02, group="Parabolic SAR")maximum = input(0.2, "Max Value", group="Parabolic SAR")SAR = ta.sar(start, increment, maximum)myColor = SAR < low ? color.green : color.red//MACDsrc = input(title="Source", defval=close, group="MACD")fast_length = input(title="Fast Length", defval=12, group="MACD")slow_length = input(title="Slow Length", defval=26, group="MACD")signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9, group="MACD")sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"], group="MACD")sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"], group="MACD")fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal//Alertgetpips() => syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)mess_buyT = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(swingLow) + " ⛔️ \n" + "TP " + str.tostring(((close-swingLow)*target_stop_ratio)+close) + " 🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade."mess_sellT = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(swingHigh) + " ⛔️ \n" + "TP " + str.tostring(close-((swingHigh-close)*target_stop_ratio)) + " 🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade."mess_buyP = "" + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingLow) + ",tp=" + str.tostring(((close-swingLow)*target_stop_ratio)+close) + ",risk=" + str.tostring(risk) + ""mess_sellP = "" + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingHigh) + ",tp=" + str.tostring(close-((swingHigh-close)*target_stop_ratio)) + ",risk=" + str.tostring(risk) + ""mess_buyAT = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(atrBuy) + " ⛔️ \n" + "TP " + str.tostring(((close-atrBuy)*target_stop_ratio)+close) + " 🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade."mess_sellAT = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(atrSell) + " ⛔️ \n" + "TP " + str.tostring(close-((atrSell-close)*target_stop_ratio)) + " 🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade."mess_buyAP = "" + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrBuy) + ",tp=" + str.tostring(((close-atrBuy)*target_stop_ratio)+close) + ",risk=" + str.tostring(risk) + ""mess_sellAP = "" + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target_stop_ratio)) + ",risk=" + str.tostring(risk) + ""mess_buyAMT = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(atrBuy) + " ⛔️ \n" + "TP1 " + str.tostring(((close-atrBuy)*target1)+close) + " 🎯 \n" + "TP2 " + str.tostring(((close-atrBuy)*target2)+close) + "🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade. BE si TP1 touché"mess_sellAMT = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(atrSell) + " ⛔️ \n" + "TP1 " + str.tostring(close-((atrSell-close)*target1)) + " 🎯 \n" + "TP2 " + str.tostring(close-((atrSell-close)*target2)) + "🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade. BE si TP1 touché"mess_buyAMP1 = "" + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrBuy) + ",tp=" + str.tostring(((close-atrBuy)*target1)+close) + ",risk=" + str.tostring(risk/2) + ""mess_buyAMP2 = "" + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrBuy) + ",tp=" + str.tostring(((close-atrBuy)*target2)+close) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring(((((close-atrBuy)*target1)+close)-close)/getpips()) + ",beoffset=0"mess_sellAMP1 = "" + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target1)) + ",risk=" + str.tostring(risk/2) + ""mess_sellAMP2 = "" + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(atrSell) + ",tp=" + str.tostring(close-((atrSell-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((atrSell-close)*target1)))/getpips()) + ",beoffset=0"mess_buyMT = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(swingLow) + " ⛔️ \n" + "TP1 " + str.tostring(((close-swingLow)*target1)+close) + " 🎯 \n" + "TP2 " + str.tostring(((close-swingLow)*target2)+close) + "🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade. BE si TP1 touché" mess_sellMT = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n \n" + "Prix d'entrée " + str.tostring(close) + "\n" + "SL " + str.tostring(swingHigh) + " ⛔️ \n" + "TP1 " + str.tostring(close-((swingHigh-close)*target1)) + " 🎯 \n" + "TP2 " + str.tostring(close-((swingHigh-close)*target2)) + "🎯 \n \n" + "⚠️ Avertissement : Respectez votre money management, risquez seulement " + str.tostring(risk) + "% de votre capital sur ce trade. BE si TP1 touché"mess_buyMP1 = "" + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingLow) + ",tp=" + str.tostring(((close-swingLow)*target1)+close) + ",risk=" + str.tostring(risk/2) + ""mess_buyMP2 = "" + str.tostring(ID) + ",buy," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingLow) + ",tp=" + str.tostring(((close-swingLow)*target2)+close) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring(((((close-swingLow)*target1)+close)-close)/getpips()) + ",beoffset=0"mess_sellMP1 = "" + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingHigh) + ",tp=" + str.tostring(close-((swingHigh-close)*target1)) + ",risk=" + str.tostring(risk/2) + ""mess_sellMP2 = "" + str.tostring(ID) + ",sell," + str.tostring(syminfo.ticker) + ",sl=" + str.tostring(swingHigh) + ",tp=" + str.tostring(close-((swingHigh-close)*target2)) + ",risk=" + str.tostring(risk/2) + ",betrigger=" + str.tostring((close-(close-((swingHigh-close)*target1)))/getpips()) + ",beoffset=0"// Strategy float risk_long = nafloat risk_short = nafloat stopLoss = nafloat takeProfit1 = nafloat takeProfit2 = nafloat entry_price = nabool longcondition = nabool shortcondition = naif sarT longcondition := close > ema and ta.crossover(macd, signal) and macd < 0 and high > SAR shortcondition := close < ema and ta.crossunder(macd, signal) and macd > 0 and low < SAR if not sarT longcondition := close > ema and ta.crossover(macd, signal) and macd < 0 shortcondition := close < ema and ta.crossunder(macd, signal) and macd > 0 risk_long := risk_long[1]risk_short := risk_short[1]lotB = (strategy.equity*riskt-strategy.equity)/(close - swingLow)lotS = (strategy.equity*riskt-strategy.equity)/(swingHigh - close) lotB1 = (strategy.equity*riskt-strategy.equity)/(close - atrBuy)lotS1 = (strategy.equity*riskt-strategy.equity)/(atrSell - close)if typeSL == "ATR" if typeTP == "Multiple Target" if strategy.position_size == 0 and longcondition and inTradeWindow risk_long := (close - atrBuy) / close minp = close - atrBuy if _x if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMT, when = minp > security) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMP1, when = minp > security) alert(mess_sellAMP2, alert.freq_once_per_bar_close) else if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMT) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAMP1) alert(mess_sellAMP2, alert.freq_once_per_bar_close) if strategy.position_size == 0 and shortcondition and inTradeWindow risk_short := (atrSell - close) / close minp = atrSell - close if _x if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMT, when = minp > security) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMP1, when = minp > security) alert(mess_sellAMP2, alert.freq_once_per_bar_close) else if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMT) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAMP1) alert(mess_sellAMP2, alert.freq_once_per_bar_close) if typeTP == "R:R" if strategy.position_size == 0 and longcondition and inTradeWindow risk_long := (close - atrBuy) / close minp = close - atrBuy if _x if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAT, when = minp > security) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAP, when = minp > security) else if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAT) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB1, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyAP) if strategy.position_size == 0 and shortcondition and inTradeWindow risk_short := (atrSell - close) / close minp = atrSell - close if _x if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAT, when = minp > security) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAP, when = minp > security) else if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAT) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS1, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellAP) if typeSL == "Swing" if typeTP == "Multiple Target" if strategy.position_size == 0 and longcondition and inTradeWindow risk_long := (close - swingLow) / close minp = close - swingLow if _x if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMT, when = minp > security) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMP1, when = minp > security) alert(mess_buyMP2, alert.freq_once_per_bar_close) else if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMT) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyMP1) alert(mess_buyMP2, alert.freq_once_per_bar_close) if strategy.position_size == 0 and shortcondition and inTradeWindow risk_short := (swingHigh - close) / close minp = swingHigh - close if _x if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMT, when = minp > security) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMP1, when = minp > security) alert(mess_sellMP2, alert.freq_once_per_bar_close) else if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMT) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellMP1) alert(mess_sellMP2, alert.freq_once_per_bar_close) if typeTP == "R:R" if strategy.position_size == 0 and longcondition and inTradeWindow risk_long := (close - swingLow) / close minp = close - swingLow if _x if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyT, when = minp > security) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyP, when = minp > security) else if tlpc == "Telegram" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyT) if tlpc == "PineConnector" strategy.entry("long", strategy.long, qty=lotB, comment="Buy " + str.tostring(close) + "", alert_message = mess_buyP) if strategy.position_size == 0 and shortcondition and inTradeWindow risk_short := (swingHigh - close) / close minp = swingHigh - close if _x if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellT, when = minp > security) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellP, when = minp > security) else if tlpc == "Telegram" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellT) if tlpc == "PineConnector" strategy.entry("short", strategy.short, qty=lotS, comment="Sell " + str.tostring(close) + "", alert_message = mess_sellP) if typeTP == "Multiple Target" if tlpc == "Telegram" if strategy.position_size > 0 stopLoss := strategy.position_avg_price * (1 - risk_long) takeProfit1 := strategy.position_avg_price * (1 + target1 * risk_long) takeProfit2 := strategy.position_avg_price * (1 + target2 * risk_long) entry_price := strategy.position_avg_price mess_profit1 = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n" + "TP1 Touché ✅ +" + str.tostring(risk*target1) + "% " strategy.exit("Exit 1", "long", limit = takeProfit1, qty_percent=50, comment_profit = "TP1 ✅", alert_profit = mess_profit1) if ta.crossover(high, takeProfit1) mess_profit2 = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n" + "TP2 Touché ✅ +" + str.tostring(risk*target2) + "% " mess_be = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n" + "BE ❎" strategy.exit("Exit 2", "long", stop = entry_price, limit = takeProfit2, qty_percent = 100, comment_profit = "TP2 ✅", comment_loss = "BE ❎", alert_profit = mess_profit2) else mess_loss = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n" + "SL Touché ❌ -" + str.tostring(risk) + "% " strategy.exit("Exit 1", "long", stop = stopLoss, qty_percent = 100, comment_loss = "SL ❌", alert_loss = mess_loss) if strategy.position_size < 0 stopLoss := strategy.position_avg_price * (1 + risk_short) takeProfit1 := strategy.position_avg_price * (1 - target1 * risk_short) takeProfit2 := strategy.position_avg_price * (1 - target2 * risk_short) entry_price := strategy.position_avg_price mess_profit1 = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n" + "TP1 Touché ✅ +" + str.tostring(risk*target1) + "% " strategy.exit("Exit 1", "short", limit = takeProfit1, qty_percent = 50, comment_profit = "TP1 ✅", alert_profit = mess_profit1) if ta.crossunder(low, takeProfit1) mess_profit2 = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n" + "TP2 Touché ✅ +" + str.tostring(risk*target2) + "% " mess_be = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n" + "BE ❎" strategy.exit("Exit 2", "short", stop = entry_price, limit = takeProfit2, qty_percent = 100, comment_profit = "TP2 ✅", comment_loss = "BE ❎", alert_profit = mess_profit2) else mess_loss = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n" + "SL Touché ❌ -" + str.tostring(risk) + "% " strategy.exit("Exit 1", "short", stop = stopLoss, qty_percent = 100, comment_loss = "SL ❌", alert_loss = mess_loss) if tlpc == "PineConnector" if strategy.position_size > 0 stopLoss := strategy.position_avg_price * (1 - risk_long) takeProfit1 := strategy.position_avg_price * (1 + target1 * risk_long) takeProfit2 := strategy.position_avg_price * (1 + target2 * risk_long) entry_price := strategy.position_avg_price strategy.exit("Exit 1", "long", limit = takeProfit1, qty_percent=50, comment_profit = "TP1 ✅") if ta.crossover(high, takeProfit1) strategy.exit("Exit 2", "long", stop = entry_price, limit = takeProfit2, qty_percent = 100, comment_profit = "TP2 ✅", comment_loss = "BE ❎") else strategy.exit("Exit 1", "long", stop = stopLoss, qty_percent = 100, comment_loss = "SL ❌") if strategy.position_size < 0 stopLoss := strategy.position_avg_price * (1 + risk_short) takeProfit1 := strategy.position_avg_price * (1 - target1 * risk_short) takeProfit2 := strategy.position_avg_price * (1 - target2 * risk_short) entry_price := strategy.position_avg_price strategy.exit("Exit 1", "short", limit = takeProfit1, qty_percent = 50, comment_profit = "TP1 ✅") if ta.crossunder(low, takeProfit1) strategy.exit("Exit 2", "short", stop = entry_price, limit = takeProfit2, qty_percent = 100, comment_profit = "TP2 ✅", comment_loss = "BE ❎") else strategy.exit("Exit 1", "short", stop = stopLoss, qty_percent = 100, comment_loss = "SL ❌") if typeTP == "R:R" if strategy.position_size > 0 stopLoss := strategy.position_avg_price * (1 - risk_long) takeProfit1 := strategy.position_avg_price * (1 + target_stop_ratio * risk_long) entry_price := strategy.position_avg_price if tlpc == "Telegram" mess_profit = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n" + "TP Touché ✅ +" + str.tostring(risk*target_stop_ratio) + "% " mess_loss = "📈 𝗔𝗖𝗛𝗔𝗧 🔵 " + str.tostring(syminfo.ticker) + "\n" + "SL Touché ❌ -" + str.tostring(risk) + "% " strategy.exit("Exit long", "long", stop = stopLoss, limit = takeProfit1, comment_profit="TP ✅", comment_loss="SL ❌", alert_profit = mess_profit, alert_loss = mess_loss) if tlpc == "PineConnector" strategy.exit("Exit long", "long", stop = stopLoss, limit = takeProfit1, comment_profit="TP ✅", comment_loss="SL ❌") if strategy.position_size < 0 stopLoss := strategy.position_avg_price * (1 + risk_short) takeProfit1 := strategy.position_avg_price * (1 - target_stop_ratio * risk_short) entry_price := strategy.position_avg_price if tlpc == "Telegram" mess_profit = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n" + "TP Touché ✅ +" + str.tostring(risk*target_stop_ratio) + "% " mess_loss = "📉 𝗩𝗘𝗡𝗧𝗘 🔴 " + str.tostring(syminfo.ticker) + "\n" + "SL Touché ❌ -" + str.tostring(risk) + "% " strategy.exit("Exit short", "short", stop = stopLoss, limit = takeProfit1, comment_profit="TP ✅" , comment_loss="SL ❌", alert_profit = mess_profit, alert_loss = mess_loss) if tlpc == "PineConnector" strategy.exit("Exit short", "short", stop = stopLoss, limit = takeProfit1, comment_profit="TP ✅" , comment_loss="SL ❌") //Plot exsar = sarT ? SAR : naplot(exsar, "ParabolicSAR", style=plot.style_circles, color=myColor, linewidth=1) plot(ema, color=color.white, linewidth=2, title="EMA")exswingH = typeSL == "Swing" ? swingHigh : naexswingL = typeSL == "Swing" ? swingLow : naplot(exswingH, color=color.new(color.white, 60), style=plot.style_cross, title='Swing High')plot(exswingL, color=color.new(color.white, 60), style=plot.style_cross, title='Swing Low')exatrS = typeSL == "ATR" ? atrSell : naexatrB = typeSL == "ATR" ? atrBuy : naplot(exatrS, color=color.new(color.white, 60), title='ATR')plot(exatrB, color=color.new(color.white, 60), title='ATR')p_ep = plot(entry_price, color=color.new(color.white, 0), linewidth=2, style=plot.style_linebr, title='entry price')p_sl = plot(stopLoss, color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr, title='stopLoss')p_tp2 = plot(takeProfit2, color=color.new(color.green, 0), linewidth=2, style=plot.style_linebr, title='takeProfit1')p_tp1 = plot(takeProfit1, color=color.new(#52F071, 0), linewidth=1, style=plot.style_linebr, title='takeProfit2')fill(p_sl, p_ep, color.new(color.red, transp=85))fill(p_tp2, p_ep, color.new(color.green, transp=85))fill(p_tp1, p_ep, color.new(#52F071, transp=85))colorresult = strategy.netprofit > 0 ? color.green : color.red profitprc = strategy.netprofit / strategy.initial_capital * 100periodzone = (backtestEndDate - backtestStartDate) / 3600 / 24 / 1000var tbl = table.new(position.top_right, 4, 2, border_width=3)table.cell(tbl, 0, 0, "Symbole", bgcolor = #9B9B9B, width = 6, height = 6)table.cell(tbl, 1, 0, "Net Profit", bgcolor = #9B9B9B, width = 6, height = 6)table.cell(tbl, 2, 0, "Trades", bgcolor = #9B9B9B, width = 6, height = 6)table.cell(tbl, 3, 0, "Period", bgcolor = #9B9B9B, width = 6, height = 6) table.cell(tbl, 0, 1, str.tostring(syminfo.ticker), bgcolor = #E8E8E8, width = 6, height = 6)table.cell(tbl, 1, 1, str.tostring(profitprc, format.mintick) + " %", bgcolor = colorresult, width = 6, height = 6)table.cell(tbl, 2, 1, str.tostring(strategy.closedtrades), bgcolor = colorresult, width = 6, height = 6)table.cell(tbl, 3, 1, str.tostring(periodzone) + " day", bgcolor = colorresult, width = 6, height = 6)