Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (29)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,058$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Table drawn by the script, as it stood on the last bar
SymboleNet ProfitTradesPeriod
BTCUSDT5.75 %530 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.

SettingDefaultType and rangeFeeds
AlertGo to alertatron to have alerts automatically sent to TelegramPineConnectorstring · 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)1234567890123stringmess_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 %2float · step 0.5riskt 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
StopLossSwingstring · options ["Swing", "ATR"]exswingH exswingL exatrS exatrB line 102 line 179
TakeProfitR:Rstring · 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 gainsfalseboolline 109 line 128 line 149 line 166 line 186 line 205 line 225 line 242
min of pips (00001.00)10floatentry long entry short
Backtest Time Period
Filter Date Range of BacktestfalseboolinTradeWindow
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")timeinTradeWindow 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")timeinTradeWindow periodzone
Stop Loss
Swing HighNumber of candles in which the parameter targets the highest7intswingHigh
Swing LowNumber of candles in which the parameter targets the lowest7intswingLow
ATR Period14intatr
ATR Multiplier2intatrSell atrBuy
TakeProfit
Risk/Reward (R:R)3float · min 0.5 · max 100 · step 0.1mess_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 hit1float · step 0.1mess_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)2float · step 0.1mess_buyAMT mess_sellAMT mess_buyAMP2 mess_sellAMP2 mess_buyMT mess_sellMT mess_buyMP2 mess_sellMP2 takeProfit2 mess_profit2
EMA
Sourceclosesourceema
Length200intema
Parabolic SAR
Parabolic SAR Indicatortrueboolexsar line 88 line 91
Start (no label in the script)0.02floatSAR
Increment (no label in the script)0.02floatSAR
Max Value0.2floatSAR
MACD
Sourceclosesourcefast_ma slow_ma
Fast Length12intfast_ma
Slow Length26intslow_ma
Signal Smoothing9int · min 1 · max 50signal
Oscillator MA TypeEMAstring · options ["SMA", "EMA"]fast_ma slow_ma
Signal Line MA TypeEMAstring · 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 Typefast_ma · line 50
  • SMA / EMASource (close), Slow Length (26) · chosen by Oscillator MA Typeslow_ma · line 51
  • SMA / EMAmacd, Signal Smoothing (9) · chosen by Signal Line MA Typesignal · 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

OrderFires whenBy defaultLine
Open long longminp > securityOn111
Open long longminp > securityOn114
Open long longtlpc == "Telegram"On118
Open long longtlpc == "PineConnector"On121
Open short shortminp > securityOn130
Open short shortminp > securityOn133
Open short shorttlpc == "Telegram"On137
Open short shorttlpc == "PineConnector"On140
Open long longminp > securityOn151
Open long longminp > securityOn154
Open long longtlpc == "Telegram"On157
Open long longtlpc == "PineConnector"On160
Open short shortminp > securityOn168
Open short shortminp > securityOn171
Open short shorttlpc == "Telegram"On174
Open short shorttlpc == "PineConnector"On177
Open long longminp > securityOn188
Open long longminp > securityOn191
Open long longtlpc == "Telegram"On195
Open long longtlpc == "PineConnector"On198
Open short shortminp > securityOn207
Open short shortminp > securityOn210
Open short shorttlpc == "Telegram"On214
Open short shorttlpc == "PineConnector"On217
Open long longminp > securityOn227
Open long longminp > securityOn230
Open long longtlpc == "Telegram"On233
Open long longtlpc == "PineConnector"On236
Open short shortminp > securityOn244
Open short shortminp > securityOn247
Open short shorttlpc == "Telegram"On250
Open short shorttlpc == "PineConnector"On253
Exit Exit 1 limitstrategy.position_size > 0On265
Exit Exit 2 stop and limitta.crossover(high, takeProfit1)On270
Exit Exit 1 stopta.crossover(high, takeProfit1)On273
Exit Exit 1 limitstrategy.position_size < 0On282
Exit Exit 2 stop and limitta.crossunder(low, takeProfit1)On287
Exit Exit 1 stopta.crossunder(low, takeProfit1)On290
Exit Exit 1 limitstrategy.position_size > 0On299
Exit Exit 2 stop and limitta.crossover(high, takeProfit1)On302
Exit Exit 1 stopta.crossover(high, takeProfit1)On304
Exit Exit 1 limitstrategy.position_size < 0On312
Exit Exit 2 stop and limitta.crossunder(low, takeProfit1)On315
Exit Exit 1 stopta.crossunder(low, takeProfit1)On317
Exit Exit long stop and limittlpc == "Telegram"On328
Exit Exit long stop and limittlpc == "PineConnector"On331
Exit Exit short stop and limittlpc == "Telegram"On341
Exit Exit short stop and limittlpc == "PineConnector"On344

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
(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=0115
(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=0122
(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=0134
(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=0141
(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=0192
(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=0199
(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=0211
(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=0218

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

1/1trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+5.8%+102.5%540%1.986.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7.6%+5.5%743%1.735.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.6%+9.8%729%1.168.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+14.4%+8.4%560%4.054.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−4.2%+16.7%617%0.576.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−7.7%+21.5%714%0.4111.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−4.2%+148.3%617%0.585.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+18.8%+17.1%757%3.692.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 barsTradesWonP&L
Rising market0—$0.00
Sideways market425%−$2.34
Falling market1100%$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.

0%7%
All 5 trades
SideEntryExitBarsP&L
short2 Oct 2024 60,804.9014 Oct 2024 66,497.1012−$20.00
long21 Feb 2025 98,305.0024 Feb 2025 93,388.103−$19.60
long7 Mar 2025 89,931.9010 Mar 2025 78,258.503−$19.21
long7 Sep 2025 110,188.002 Oct 2025 118,987.0025$56.47
short21 Jan 2026 88,427.705 Jun 2026 59,937.20135$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.

ScriptSharesTypeNetTradesMax drawdown
MACD Strategy this page—v5 strategy+5.8%56.9%
CHOP Zone Entry Strategy + DMI-PSAR Exit by IronCasperatr highest lowest sma sar emav4 strategy+17.1%820.0%
ATR + STC + MA by Romediusema lowest highest atr smav5 strategy−1.2%153.3%
-NoSKi Hammer-Star -w angle of ema Backtester - by noski1atr ema sma highest lowestv5 strategydoes not run in Zeal Terminal
LONG SAZB $ by stevenz17ema sma atr lowest highestv4 strategyNo trades on this market
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 1,777 msYes 1,000 bars in 305 msNot measured
PineTSNot testedNot testedNot 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)