Pine Script v4 · Strategy
Dual MACD Strategy
A Pine Script v4 strategy built on MACD (close, 12), Crossover (w_macdLine, w_singleLine) and Crossunder (d_macdLine, d_singleLine). It has 14 order rules, 2 entries among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 20% of equity and pays 0.1 commission. 18 settings; defaults include Take Profit % 30.0, Stop Loss % 1.0 and Trailing Stop % 5.0.
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 Dual MACD Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Dual MACD Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Dual MACD Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- Does Dual MACD Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 87, 88, 91, 92, 99, 100, 103, 104.
- Does Dual MACD Strategy run in Zeal Terminal?
- Yes
- It compiles in 38 ms and runs 1,000 bars in 80 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
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
2 settings do nothing
“------ Profit & Loss ------”, “------ Macd Properties ------” are declared but never read.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses long =, which v5 renamed line 77
long = on line 77, 82. v5 writes it as direction = strategy.long or strategy.short.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames security → request.security, macd → ta.macd, crossover → ta.crossover, crossunder → ta.crossunder, max → math.max.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 7: //@version=4 → //@version=5
- Line 17: input(type = input.time) → input.time()
- Line 18: input(type = input.time) → input.time()
- Line 23: input(type = input.float) → input.float()
- Line 24: input(type = input.float) → input.float()
- Line 25: input(type = input.float) → input.float()
16 more edits
- Line 31: input(type = input.resolution) → input.timeframe()
- Line 32: input(type = input.resolution) → input.timeframe()
- Line 34: input(type = input.integer) → input.int()
- Line 35: input(type = input.integer) → input.int()
- Line 36: input(type = input.integer) → input.int()
- Line 37: input(type = input.bool) → input.bool()
- Line 46: security → request.security
- Line 46: macd → ta.macd
- Line 54: security → request.security
- Line 54: macd → ta.macd
- Line 66: crossover → ta.crossover
- Line 67: crossunder → ta.crossunder
- Line 68: crossover → ta.crossover
- Line 73: max → math.max
- Line 77: long = strategy.long → direction = strategy.long
- Line 82: long = strategy.long → direction = strategy.long
⋯// Re Entry Condition: Macd line crosses above Signal line only if [Trading Window MacdLine > Sgnal Line] (Weekly)-//@version=4+//@version=5strategy("Dual MACD Strategy",⋯// Define user inputs-i_time = input(defval = timestamp("01 May 2018 13:30 +0000"), title = "Start Time", type = input.time) // Starting time for Backtesting+i_time = input.time(defval = timestamp("01 May 2018 13:30 +0000"), title = "Start Time") // Starting time for Backtesting-f_time = input(defval = timestamp("9 Sep 2021 13:30 +0000"), title = "Finish Time", type = input.time) // Finishing time for Backtesting+f_time = input.time(defval = timestamp("9 Sep 2021 13:30 +0000"), title = "Finish Time") // Finishing time for Backtestingsep1 = input(false, title="------ Profit & Loss ------")⋯enable_TS = input(true, title=" Enable Only Trailing Stop")-long_TP_Input = input(30.0, title='Take Profit %', type=input.float, minval=0)/100+long_TP_Input = input.float(30.0, title='Take Profit %', minval=0)/100-long_SL_Input = input(1.0, title='Stop Loss %', type=input.float, minval=0)/100+long_SL_Input = input.float(1.0, title='Stop Loss %', minval=0)/100-long_TS_Input = input(5.0, title='Trailing Stop %', type=input.float, minval=0)/100+long_TS_Input = input.float(5.0, title='Trailing Stop %', minval=0)/100cl_low_Input = input(low, title="Trailing Stop Source")⋯sep2 = input(false, title="------ Macd Properties ------")-d_res = input(title="Short Term TimeFrame", type=input.resolution, defval="D") // Daily Time Frame+d_res = input.timeframe(title="Short Term TimeFrame", defval="D") // Daily Time Frame-w_res = input(title="Long Term TimeFrame", type=input.resolution, defval="W") // Weekly Time Frame+w_res = input.timeframe(title="Long Term TimeFrame", defval="W") // Weekly Time Framesrc = input(close, title="Source") // Indicator Price Source-fast_len = input(title="Fast Length", type=input.integer, defval=12) // Fast MA Length+fast_len = input.int(title="Fast Length", defval=12) // Fast MA Length-slow_len = input(title="Slow Length", type=input.integer, defval=26) // Slow MA Length+slow_len = input.int(title="Slow Length", defval=26) // Slow MA Length-sign_len = input(title="Sign Length", type=input.integer, defval=9) // Sign MA Length+sign_len = input.int(title="Sign Length", defval=9) // Sign MA Length-d_w = input(title="Daily or Weekly?", type=input.bool, defval=true) // Plot Daily or Weekly MACD+d_w = input.bool(title="Daily or Weekly?", defval=true) // Plot Daily or Weekly MACD// Color Plot for Macd⋯// Daily Macd-[d_macdLine, d_singleLine, d_histLine] = security(syminfo.tickerid, d_res, macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resolución+[d_macdLine, d_singleLine, d_histLine] = request.security(syminfo.tickerid, d_res, ta.macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resoluciónplot(d_w ? d_macdLine : na, color=color.blue)⋯// Weekly Macd-[w_macdLine, w_singleLine, w_histLine] = security(syminfo.tickerid, w_res, macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resolución+[w_macdLine, w_singleLine, w_histLine] = request.security(syminfo.tickerid, w_res, ta.macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resoluciónplot(d_w ? na : w_macdLine, color=color.blue)⋯bgcolor(trading_window ? bg_color : na)-buy_cond = crossover (w_macdLine, w_singleLine)+buy_cond = ta.crossover (w_macdLine, w_singleLine)-sell_cond = crossunder(d_macdLine, d_singleLine)+sell_cond = ta.crossunder(d_macdLine, d_singleLine)-re_entry_cond = crossover (d_macdLine, d_singleLine) and trading_window+re_entry_cond = ta.crossover (d_macdLine, d_singleLine) and trading_window// Entry Exit Conditions⋯ stopValue = long_TS- max(trailing_stop[1], stopValue)+ math.max(trailing_stop[1], stopValue)else ⋯if (buy_cond and notInTrade and start_time)- strategy.entry(id="First Entry", long=strategy.long, comment="First Long")+ strategy.entry(id="First Entry", direction = strategy.long, comment="First Long")if (sell_cond and inTrade)⋯if (re_entry_cond and notInTrade and start_time)- strategy.entry(id="Further Entry", long=strategy.long, comment="Further Entry")+ strategy.entry(id="Further Entry", direction = strategy.long, comment="Further Entry")if (sell_cond and inTrade)⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 19: input() → input.bool()
- Line 20: input() → input.bool()
- Line 21: input() → input.bool()
- Line 22: input() → input.bool()
- Line 26: input() → input.source()
- Line 30: input() → input.bool()
- Line 33: input() → input.source()
⋯f_time = input.time(defval = timestamp("9 Sep 2021 13:30 +0000"), title = "Finish Time") // Finishing time for Backtesting-sep1 = input(false, title="------ Profit & Loss ------")+sep1 = input.bool(false, title="------ Profit & Loss ------")-enable_TP = input(true, title="Enable Just a Profit Level?")+enable_TP = input.bool(true, title="Enable Just a Profit Level?")-enable_SL = input(false, title="Enable Just a S.Loss Level?")+enable_SL = input.bool(false, title="Enable Just a S.Loss Level?")-enable_TS = input(true, title=" Enable Only Trailing Stop")+enable_TS = input.bool(true, title=" Enable Only Trailing Stop")long_TP_Input = input.float(30.0, title='Take Profit %', minval=0)/100⋯long_TS_Input = input.float(5.0, title='Trailing Stop %', minval=0)/100-cl_low_Input = input(low, title="Trailing Stop Source")+cl_low_Input = input.source(low, title="Trailing Stop Source")long_TP = strategy.position_avg_price * (1 + long_TP_Input)⋯long_TS = cl_low_Input * (1 - long_TS_Input)-sep2 = input(false, title="------ Macd Properties ------")+sep2 = input.bool(false, title="------ Macd Properties ------")d_res = input.timeframe(title="Short Term TimeFrame", defval="D") // Daily Time Framew_res = input.timeframe(title="Long Term TimeFrame", defval="W") // Weekly Time Frame-src = input(close, title="Source") // Indicator Price Source+src = input.source(close, title="Source") // Indicator Price Sourcefast_len = input.int(title="Fast Length", defval=12) // Fast MA Length⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L107:C19: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// Re Entry Condition: Macd line crosses above Signal line only if [Trading Window MacdLine > Sgnal Line] (Weekly)-//@version=5+//@version=6strategy("Dual MACD Strategy",⋯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 |
|---|---|---|---|
| Start Time | timestamp("01 May 2018 13:30 +0000") | time | start_time |
| Finish Time | timestamp("9 Sep 2021 13:30 +0000") | time | start_time |
| ------ Profit & Loss ------ | false | bool | unused |
| Enable Just a Profit Level? | true | bool | line 85 line 97 TP Level |
| Enable Just a S.Loss Level? | false | bool | exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn line 86 line 90 line 98 line 102 SL Level |
| Enable Only Trailing Stop | true | bool | exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn exit Long TP & TS FiEn exit Long TP & TS FuEn line 86 line 90 line 98 line 102 TS Level |
| Take Profit % | 30.0 | float · min 0 | long_TP |
| Stop Loss % | 1.0 | float · min 0 | long_SL |
| Trailing Stop % | 5.0 | float · min 0 | long_TS |
| Trailing Stop Source | low | source | long_TS |
| ------ Macd Properties ------ | false | bool | unused |
| Short Term TimeFrame | D | timeframe (written input.resolution) | d_macdLine d_singleLine d_histLine |
| Long Term TimeFrame | W | timeframe (written input.resolution) | w_macdLine w_singleLine w_histLine |
| Source | close | source | d_macdLine d_singleLine d_histLine w_macdLine w_singleLine w_histLine |
| Fast Length | 12 | int (written input.integer) | d_macdLine d_singleLine d_histLine w_macdLine w_singleLine w_histLine |
| Slow Length | 26 | int (written input.integer) | d_macdLine d_singleLine d_histLine w_macdLine w_singleLine w_histLine |
| Sign Length | 9 | int (written input.integer) | d_macdLine d_singleLine d_histLine w_macdLine w_singleLine w_histLine |
| Daily or Weekly? | true | bool | plot |
What it calculates
- MACD (
macd,ta.macdin v5)Source (close), Fast Length (12), Slow Length (26), Sign Length (9)d_macdLine · line 46 - MACD (
macd,ta.macdin v5)Source (close), Fast Length (12), Slow Length (26), Sign Length (9)d_singleLine · line 46 - MACD (
macd,ta.macdin v5)Source (close), Fast Length (12), Slow Length (26), Sign Length (9)d_histLine · line 46 - MACD (
macd,ta.macdin v5)Source (close), Fast Length (12), Slow Length (26), Sign Length (9)w_macdLine · line 54 - MACD (
macd,ta.macdin v5)Source (close), Fast Length (12), Slow Length (26), Sign Length (9)w_singleLine · line 54 - MACD (
macd,ta.macdin v5)Source (close), Fast Length (12), Slow Length (26), Sign Length (9)w_histLine · line 54 - Crossover (
crossover,ta.crossoverin v5)w_macdLine, w_singleLinebuy_cond · line 66 - Crossunder (
crossunder,ta.crossunderin v5)d_macdLine, d_singleLinesell_cond · line 67
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open First Entry long | (buy_cond and notInTrade and start_time) | On | 77 |
| Close First Entry | (sell_cond and inTrade) | On | 79 |
| Open Further Entry long | (re_entry_cond and notInTrade and start_time) | On | 82 |
| Close Further Entry | (sell_cond and inTrade) | On | 84 |
| Exit Long TP & TS FiEn stop and limit | (enable_TS and not enable_SL) | On | 87 |
| Exit Long TP & TS FuEn stop and limit | (enable_TS and not enable_SL) | On | 88 |
| Exit Long TP & TS FiEn stop and limit | (enable_SL and not enable_TS) | On | 91 |
| Exit Long TP & TS FuEn stop and limit | (enable_SL and not enable_TS) | On | 92 |
| Exit Long TP & TS FiEn limit | (enable_SL and not enable_TS) | On | 94 |
| Exit Long TP & TS FuEn limit | (enable_SL and not enable_TS) | On | 95 |
| Exit Long TP & TS FiEn stop | (enable_TS and not enable_SL) | On | 99 |
| Exit Long TP & TS FuEn stop | (enable_TS and not enable_SL) | On | 100 |
| Exit Long TP & TS FiEn stop | (enable_SL and not enable_TS) | On | 103 |
| Exit Long TP & TS FuEn stop | (enable_SL and not enable_TS) | On | 104 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe data2 security call(s), none with lookahead on.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| Dual MACD Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Ichimoku Cloud with MACD (By Coinrule) by Coinrule | macd | v5 strategy | −8.4% | 6 | 19.3% |
| The Impeccable by zyberal by zyberal | macd | v5 strategy | +1.1% | 9 | 4.4% |
| Short Swing Bearish MACD Cross (By Coinrule) by Coinrule | macd | v5 strategy | −6.9% | 8 | 6.9% |
| [blackcat] L2 Reversal Labels Strategy by blackcat1402 | macd | v5 strategy | +13.9% | 7 | 2.7% |
| MACD Trend Strategy by Zeal Terminal | macd | v5 strategy | −1.0% | 21 | 3.5% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 38 ms | With a workaround 1,000 bars in 80 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 77, 82) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © maxits// Long Position: Weekly Macd line crosses above Signal line // [Trading Window Macd Line > Signal Line] (Weekly)// Close Position: Daily Macd Line crosses above Daily Signal line. // Re Entry Condition: Macd line crosses above Signal line only if [Trading Window MacdLine > Sgnal Line] (Weekly)//@version=4strategy("Dual MACD Strategy", shorttitle="Dual Macd Tester", overlay=false, initial_capital=1000, default_qty_value=20, default_qty_type=strategy.percent_of_equity, commission_value=0.1, pyramiding=0)// Define user inputsi_time = input(defval = timestamp("01 May 2018 13:30 +0000"), title = "Start Time", type = input.time) // Starting time for Backtestingf_time = input(defval = timestamp("9 Sep 2021 13:30 +0000"), title = "Finish Time", type = input.time) // Finishing time for Backtestingsep1 = input(false, title="------ Profit & Loss ------")enable_TP = input(true, title="Enable Just a Profit Level?")enable_SL = input(false, title="Enable Just a S.Loss Level?")enable_TS = input(true, title=" Enable Only Trailing Stop")long_TP_Input = input(30.0, title='Take Profit %', type=input.float, minval=0)/100long_SL_Input = input(1.0, title='Stop Loss %', type=input.float, minval=0)/100long_TS_Input = input(5.0, title='Trailing Stop %', type=input.float, minval=0)/100cl_low_Input = input(low, title="Trailing Stop Source")long_TP = strategy.position_avg_price * (1 + long_TP_Input)long_SL = strategy.position_avg_price * (1 - long_SL_Input)long_TS = cl_low_Input * (1 - long_TS_Input)sep2 = input(false, title="------ Macd Properties ------")d_res = input(title="Short Term TimeFrame", type=input.resolution, defval="D") // Daily Time Framew_res = input(title="Long Term TimeFrame", type=input.resolution, defval="W") // Weekly Time Framesrc = input(close, title="Source") // Indicator Price Sourcefast_len = input(title="Fast Length", type=input.integer, defval=12) // Fast MA Lengthslow_len = input(title="Slow Length", type=input.integer, defval=26) // Slow MA Lengthsign_len = input(title="Sign Length", type=input.integer, defval=9) // Sign MA Lengthd_w = input(title="Daily or Weekly?", type=input.bool, defval=true) // Plot Daily or Weekly MACD// Color Plot for Macdcol_grow_above = #26A69Acol_grow_below = #FFCDD2col_fall_above = #B2DFDBcol_fall_below = #EF5350// BG Colorbg_color = color.rgb(127, 232, 34, 75)// Daily Macd[d_macdLine, d_singleLine, d_histLine] = security(syminfo.tickerid, d_res, macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resoluciónplot(d_w ? d_macdLine : na, color=color.blue)plot(d_w ? d_singleLine : na, color=color.orange)plot(d_w ? d_histLine : na, style=plot.style_columns, color=(d_histLine>=0 ? (d_histLine[1] < d_histLine ? col_grow_above : col_fall_above) : (d_histLine[1] < d_histLine ? col_grow_below : col_fall_below))) // Weekly Macd[w_macdLine, w_singleLine, w_histLine] = security(syminfo.tickerid, w_res, macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resoluciónplot(d_w ? na : w_macdLine, color=color.blue)plot(d_w ? na : w_singleLine, color=color.orange)plot(d_w ? na : w_histLine, style=plot.style_columns, color=(w_histLine>=0 ? (w_histLine[1] < w_histLine ? col_grow_above : col_fall_above) : (w_histLine[1] < w_histLine ? col_grow_below : col_fall_below)))///////////////////////////////// Entry ConditionsinTrade = strategy.position_size != 0 // Posición abiertanotInTrade = strategy.position_size == 0 // Posición Cerradastart_time = time >= i_time and time <= f_time // Inicio y Fin de BackTesttrading_window = w_macdLine > w_singleLine // Weekly Macd Signal enables a trading window bgcolor(trading_window ? bg_color : na)buy_cond = crossover (w_macdLine, w_singleLine)sell_cond = crossunder(d_macdLine, d_singleLine)re_entry_cond = crossover (d_macdLine, d_singleLine) and trading_window// Entry Exit Conditionstrailing_stop = 0.0 // Code for calculating Long Positions Trailing Stop Losstrailing_stop := if (strategy.position_size != 0) stopValue = long_TS max(trailing_stop[1], stopValue)else 0if (buy_cond and notInTrade and start_time) strategy.entry(id="First Entry", long=strategy.long, comment="First Long")if (sell_cond and inTrade) strategy.close(id="First Entry", comment="Close First Long") if (re_entry_cond and notInTrade and start_time) strategy.entry(id="Further Entry", long=strategy.long, comment="Further Entry")if (sell_cond and inTrade) strategy.close(id="Further Entry", comment="Close First Long")if enable_TP if (enable_TS and not enable_SL) strategy.exit("Long TP & TS FiEn", "First Entry", limit = long_TP, stop = trailing_stop) strategy.exit("Long TP & TS FuEn", "Further Entry", limit = long_TP, stop = trailing_stop) else if (enable_SL and not enable_TS) strategy.exit("Long TP & TS FiEn", "First Entry", limit = long_TP, stop = long_SL) strategy.exit("Long TP & TS FuEn", "Further Entry", limit = long_TP, stop = long_SL) else strategy.exit("Long TP & TS FiEn", "First Entry", limit = long_TP) strategy.exit("Long TP & TS FuEn", "Further Entry", limit = long_TP)else if not enable_TP if (enable_TS and not enable_SL) strategy.exit("Long TP & TS FiEn", "First Entry", stop = trailing_stop) strategy.exit("Long TP & TS FuEn", "Further Entry", stop = trailing_stop) else if (enable_SL and not enable_TS) strategy.exit("Long TP & TS FiEn", "First Entry", stop = long_SL) strategy.exit("Long TP & TS FuEn", "Further Entry", stop = long_SL)plot(enable_TP ? long_TP : na, title="TP Level", color=color.green, style=plot.style_linebr, linewidth=2)plot(enable_SL ? long_SL : na, title="SL Level", color=color.red, style=plot.style_linebr, linewidth=2)plot(enable_TS and trailing_stop ? trailing_stop : na, title="TS Level", color=color.red, style=plot.style_linebr, linewidth=2)