Multi-Dimensional Trend Confluence Strategy

EMA RSI MACD ATR BB STOCH MFI MTF
Created on: 2025-11-12 17:01:17 Modified on: 2025-11-12 17:01:17
Copy: 0 Number of hits: 212
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 Multi-Dimensional Trend Confluence Strategy  Multi-Dimensional Trend Confluence Strategy

🎯 What’s This Amazing Strategy? 20 Indicators Working Together!

Did you know? This strategy is like having a super intelligent AI assistant for your trading! It simultaneously monitors 20 different market signals and only gives you trading advice when most indicators say “go”. It’s like buying a house - you check location, price, layout, transportation… only when everything looks good do you make the move!

Key point! This isn’t your ordinary single-indicator strategy, but a “multi-dimensional confluence system”. Imagine if only one friend recommended a stock, you might be skeptical; but if 20 professional friends all say it’s good, wouldn’t you be more confident?

📊 Core Arsenal Revealed

Trend Identification Triple Threat 🗡️ - Fast EMA(5) vs Slow EMA(13): Catches short-term trend reversals - Trend Filter EMA(34): Confirms medium-term direction
- Major Trend EMA(89): Captures the big picture, avoiding small noise

Multi-Timeframe Analysis ⏰ This feature is awesome! The strategy looks at both 1-hour and 4-hour trends simultaneously, like driving where you watch both the road ahead and your GPS route. Avoids the awkward situation of “short timeframe bullish, long timeframe bearish”!

Smart Risk Management 🛡️ - Dynamic position sizing: Auto-adjusts bet size based on market volatility - Partial profit taking: Don’t be greedy, secure some profits - Trailing stops: The profit protection hero

🔥 20-Layer Protection Trading Logic

Long Signal Requirements: - Upward trend: All EMAs in bullish alignment - Sufficient momentum: RSI, MACD, Stochastic RSI all green-light - Volume confirmation: Rising volume confirms real moves - Healthy market structure: Higher highs pattern - Liquidity support: Key support levels intact

Short signals work in reverse!

Pitfall Alert ⚠️: The strategy includes “Bollinger Band squeeze detection” - when markets are too quiet, it pauses trading to avoid getting whipsawed in choppy conditions!

💰 Profit Maximization Secret Weapons

Staged Profit Taking Strategy 📈 - First take profit: Sell 30% at 2x risk-reward - Second take profit: Sell another 40% at 3.5x - Remaining position: Protected by trailing stops, let profits run

Smart Stop Loss Upgrade 🎯 After reaching 2.5x profit, stops automatically move to breakeven, ensuring this trade at least doesn’t lose money. Like buying insurance for your profits!

Dynamic Trailing Stops 🏃‍♂️ When profits reach certain levels, stops follow price like a shadow, protecting gains while leaving room for further upside.

🚀 Why This Strategy Rocks?

  1. Complete Coverage: Technical analysis, money management, risk control - nothing missing
  2. Smart Filtering: 20 conditions layer by layer, dramatically improving success rates
  3. Highly Adaptive: Multi-timeframe analysis suits different market environments
  4. User-Friendly Design: Automated execution avoids emotional trading

This strategy is like having an experienced trading team coded into software, working 247 to find the best trading opportunities for you!

Strategy source code
/*backtest
start: 2024-11-12 00:00:00
end: 2025-11-10 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy('Amir Mohammad Lor ', shorttitle='MPF', overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=15, pyramiding=0, max_bars_back=1000)

// === INPUTS ===
// Core Indicators
ema_fast_len = input.int(5, 'EMA Fast Length', minval=1, group="Core Indicators")
ema_slow_len = input.int(13, 'EMA Slow Length', minval=1, group="Core Indicators")
ema_trend_len = input.int(34, 'EMA Trend Filter', minval=1, group="Core Indicators")
ema_major_len = input.int(89, 'EMA Major Trend', minval=1, group="Core Indicators")
rsi_len = input.int(21, 'RSI Length', minval=1, group="Core Indicators")

// Multi-Timeframe Analysis
use_mtf = input.bool(true, 'Use Multi-Timeframe Analysis', group="Multi-Timeframe")
htf1 = input.timeframe("60", "1H Timeframe", group="Multi-Timeframe")
htf2 = input.timeframe("240", "4H Timeframe", group="Multi-Timeframe")

// Advanced Risk Management
initial_rr = input.float(4.0, 'Initial Risk Reward Ratio', minval=2.0, step=0.5, group="Risk Management")
atr_mult_entry = input.float(0.8, 'ATR Entry Stop Multiplier', minval=0.3, step=0.1, group="Risk Management")
use_dynamic_sizing = input.bool(true, 'Use Dynamic Position Sizing', group="Risk Management")
max_risk_per_trade = input.float(1.5, 'Max Risk Per Trade %', minval=0.5, step=0.1, group="Risk Management")

// Profit Maximization
use_partial_tp = input.bool(true, 'Use Partial Take Profits', group="Profit Management")
tp1_percent = input.float(30.0, 'First TP % of Position', minval=10, maxval=50, step=5, group="Profit Management")
tp1_rr = input.float(2.0, 'First TP R:R Ratio', minval=1.0, step=0.25, group="Profit Management")
tp2_percent = input.float(40.0, 'Second TP % of Position', minval=10, maxval=50, step=5, group="Profit Management")
tp2_rr = input.float(3.5, 'Second TP R:R Ratio', minval=2.0, step=0.25, group="Profit Management")
use_breakeven = input.bool(true, 'Move to Breakeven After TP1', group="Profit Management")
use_profit_trail = input.bool(true, 'Use Profit Trailing', group="Profit Management")
trail_activation = input.float(2.5, 'Trail Activation R:R', minval=1.5, step=0.25, group="Profit Management")
trail_distance = input.float(1.0, 'Trail Distance ATR', minval=0.5, step=0.1, group="Profit Management")

// Market Structure
use_market_structure = input.bool(true, 'Use Market Structure Analysis', group="Market Structure")
swing_length = input.int(20, 'Swing Length', minval=5, group="Market Structure")
use_liquidity_zones = input.bool(true, 'Use Liquidity Zone Detection', group="Market Structure")

// Trend Strength Filters
min_trend_strength = input.float(0.6, 'Minimum Trend Strength', minval=0.3, maxval=1.0, step=0.1, group="Filters")
use_momentum_filter = input.bool(true, 'Use Momentum Confluence', group="Filters")
min_volume_ratio = input.float(1.8, 'Minimum Volume Ratio', minval=1.0, step=0.1, group="Filters")

// Alert Settings
enable_sound_alerts = input.bool(true, 'Enable Sound Alerts', group="Alert Settings")
enable_popup_alerts = input.bool(true, 'Enable Popup Alerts', group="Alert Settings")
enable_email_alerts = input.bool(false, 'Enable Email Alerts', group="Alert Settings")
alert_frequency = input.string("Once Per Bar Close", "Alert Frequency", options=["All", "Once Per Bar", "Once Per Bar Close"], group="Alert Settings")

// === INDICATORS ===
// EMAs
ema_fast = ta.ema(close, ema_fast_len)
ema_slow = ta.ema(close, ema_slow_len)
ema_trend = ta.ema(close, ema_trend_len)
ema_major = ta.ema(close, ema_major_len)

// Crossover calculations
fast_under_slow = ta.crossunder(ema_fast, ema_slow)
fast_over_slow = ta.crossover(ema_fast, ema_slow)

// RSI with divergence detection
rsi = ta.rsi(close, rsi_len)
rsi_ma = ta.sma(rsi, 5)

// ATR for dynamic stops
atr = ta.atr(14)
atr_ma = ta.sma(atr, 14)

// Volume analysis
volume_ma = ta.sma(volume, 20)
volume_ratio = volume / volume_ma

// Market Structure Analysis
swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)

var float[] swing_highs = array.new<float>()
var float[] swing_lows = array.new<float>()

if not na(swing_high)
    array.unshift(swing_highs, swing_high)
    if array.size(swing_highs) > 5
        array.pop(swing_highs)

if not na(swing_low)
    array.unshift(swing_lows, swing_low)
    if array.size(swing_lows) > 5
        array.pop(swing_lows)

// Trend strength calculation
trend_strength = math.abs(ema_fast - ema_major) / (ema_major * 0.01)
trend_strength_norm = math.min(trend_strength / 2, 1.0)

// Multi-timeframe trend analysis
htf1_trend = request.security(syminfo.tickerid, htf1, ema_fast > ema_slow and ema_slow > ema_trend, barmerge.gaps_on)
htf1_trend_bear = request.security(syminfo.tickerid, htf1, ema_fast < ema_slow and ema_slow < ema_trend, barmerge.gaps_on)
htf2_trend = request.security(syminfo.tickerid, htf2, ema_fast > ema_trend and close > ema_major, barmerge.gaps_on)
htf2_trend_bear = request.security(syminfo.tickerid, htf2, ema_fast < ema_trend and close < ema_major, barmerge.gaps_on)

// Advanced momentum indicators
macd_line = ta.ema(close, 12) - ta.ema(close, 26)
macd_signal = ta.ema(macd_line, 9)
macd_hist = macd_line - macd_signal

// Bollinger Bands with squeeze detection
bb_length = 20
bb_mult = 2.0
[bb_upper, bb_middle, bb_lower] = ta.bb(close, bb_length, bb_mult)
bb_width = (bb_upper - bb_lower) / bb_middle
bb_squeeze = bb_width < ta.percentile_linear_interpolation(bb_width, 50, 20)

// Stochastic RSI
stoch_rsi = ta.stoch(rsi, rsi, rsi, 14)

// Money Flow Index
mfi = ta.mfi(hlc3, 14)

// Liquidity zones detection
var float liquidity_high = na
var float liquidity_low = na
var int liq_high_touches = 0
var int liq_low_touches = 0

if array.size(swing_highs) >= 2
    recent_high = array.get(swing_highs, 0)
    prev_high = array.get(swing_highs, 1)
    if math.abs(recent_high - prev_high) / recent_high < 0.002
        liquidity_high := recent_high
        liq_high_touches := 2

if array.size(swing_lows) >= 2
    recent_low = array.get(swing_lows, 0)
    prev_low = array.get(swing_lows, 1)
    if math.abs(recent_low - prev_low) / recent_low < 0.002
        liquidity_low := recent_low
        liq_low_touches := 2

// Advanced trend detection
uptrend_structure = array.size(swing_lows) >= 2 ? array.get(swing_lows, 0) > array.get(swing_lows, 1) : false
downtrend_structure = array.size(swing_highs) >= 2 ? array.get(swing_highs, 0) < array.get(swing_highs, 1) : false

// === CONFLUENCE SYSTEM ===
// LONG Setup Confluences (20 factors)
long_c1 = ema_fast > ema_slow and ema_slow > ema_trend and ema_trend > ema_major
long_c2 = close > ema_fast and close > ema_slow
long_c3 = rsi > 50 and rsi < 75 and rsi > rsi[1]
long_c4 = macd_line > macd_signal and macd_hist > macd_hist[1]
long_c5 = volume_ratio > min_volume_ratio
long_c6 = not use_mtf or (htf1_trend and htf2_trend)
long_c7 = trend_strength_norm > min_trend_strength
long_c8 = stoch_rsi > 20 and stoch_rsi < 80
long_c9 = mfi > 40 and mfi < 80 and mfi > mfi[1]
long_c10 = not bb_squeeze
long_c11 = close > bb_middle
long_c12 = not use_market_structure or uptrend_structure
long_c13 = fast_over_slow or (ema_fast > ema_slow and ema_fast[1] <= ema_slow[1])
long_c14 = atr > atr_ma * 0.8
long_c15 = close > high[1] or close > open
long_c16 = not use_liquidity_zones or (not na(liquidity_low) and close > liquidity_low)
long_c17 = ta.change(close, 3) > 0
long_c18 = hl2 > ema_trend
long_c19 = ta.roc(close, 5) > 0
long_c20 = close > ta.highest(close, 3)[1]

long_confluences = (long_c1 ? 1 : 0) + (long_c2 ? 1 : 0) + (long_c3 ? 1 : 0) + 
     (long_c4 ? 1 : 0) + (long_c5 ? 1 : 0) + (long_c6 ? 1 : 0) + 
     (long_c7 ? 1 : 0) + (long_c8 ? 1 : 0) + (long_c9 ? 1 : 0) + 
     (long_c10 ? 1 : 0) + (long_c11 ? 1 : 0) + (long_c12 ? 1 : 0) + 
     (long_c13 ? 1 : 0) + (long_c14 ? 1 : 0) + (long_c15 ? 1 : 0) + 
     (long_c16 ? 1 : 0) + (long_c17 ? 1 : 0) + (long_c18 ? 1 : 0) + 
     (long_c19 ? 1 : 0) + (long_c20 ? 1 : 0)

// SHORT Setup Confluences (20 factors)
short_c1 = ema_fast < ema_slow and ema_slow < ema_trend and ema_trend < ema_major
short_c2 = close < ema_fast and close < ema_slow
short_c3 = rsi < 50 and rsi > 25 and rsi < rsi[1]
short_c4 = macd_line < macd_signal and macd_hist < macd_hist[1]
short_c5 = volume_ratio > min_volume_ratio
short_c6 = not use_mtf or (htf1_trend_bear and htf2_trend_bear)
short_c7 = trend_strength_norm > min_trend_strength
short_c8 = stoch_rsi < 80 and stoch_rsi > 20
short_c9 = mfi < 60 and mfi > 20 and mfi < mfi[1]
short_c10 = not bb_squeeze
short_c11 = close < bb_middle
short_c12 = not use_market_structure or downtrend_structure
short_c13 = fast_under_slow or (ema_fast < ema_slow and ema_fast[1] >= ema_slow[1])
short_c14 = atr > atr_ma * 0.8
short_c15 = close < low[1] or close < open
short_c16 = not use_liquidity_zones or (not na(liquidity_high) and close < liquidity_high)
short_c17 = ta.change(close, 3) < 0
short_c18 = hl2 < ema_trend
short_c19 = ta.roc(close, 5) < 0
short_c20 = close < ta.lowest(close, 3)[1]

short_confluences = (short_c1 ? 1 : 0) + (short_c2 ? 1 : 0) + (short_c3 ? 1 : 0) + 
     (short_c4 ? 1 : 0) + (short_c5 ? 1 : 0) + (short_c6 ? 1 : 0) + 
     (short_c7 ? 1 : 0) + (short_c8 ? 1 : 0) + (short_c9 ? 1 : 0) + 
     (short_c10 ? 1 : 0) + (short_c11 ? 1 : 0) + (short_c12 ? 1 : 0) + 
     (short_c13 ? 1 : 0) + (short_c14 ? 1 : 0) + (short_c15 ? 1 : 0) + 
     (short_c16 ? 1 : 0) + (short_c17 ? 1 : 0) + (short_c18 ? 1 : 0) + 
     (short_c19 ? 1 : 0) + (short_c20 ? 1 : 0)

// High probability entry requirements
min_confluences_required = 14
long_entry = long_confluences >= min_confluences_required
short_entry = short_confluences >= min_confluences_required

// Signal strength classification
long_strength = long_confluences >= 18 ? "ULTRA STRONG" : long_confluences >= 16 ? "VERY STRONG" : long_confluences >= 14 ? "STRONG" : "WEAK"
short_strength = short_confluences >= 18 ? "ULTRA STRONG" : short_confluences >= 16 ? "VERY STRONG" : short_confluences >= 14 ? "STRONG" : "WEAK"

// === DYNAMIC POSITION SIZING ===
confluence_multiplier = long_entry ? 
     (long_confluences - min_confluences_required + 1) * 0.2 : 
     short_entry ? 
     (short_confluences - min_confluences_required + 1) * 0.2 : 
     1.0

volatility_factor = atr / close
normalized_vol = math.min(volatility_factor / 0.02, 2.0)
vol_multiplier = 1.0 / math.max(normalized_vol, 0.5)

dynamic_size = use_dynamic_sizing ? confluence_multiplier * vol_multiplier : 1.0
position_size = math.min(dynamic_size * 15, 25)

// === POSITION MANAGEMENT VARIABLES ===
var float entry_price = na
var float initial_stop = na
var float current_stop = na
var float tp1_price = na
var float tp2_price = na
var float tp3_price = na
var bool tp1_hit = false
var bool tp2_hit = false
var bool breakeven_moved = false
var string position_direction = na
var int bars_in_position = 0
var float max_profit = 0.0
var float trail_trigger_price = na
var float unrealized_pnl = 0.0

// Alert trigger variables
var bool long_entry_triggered = false
var bool short_entry_triggered = false
var bool tp1_alert_sent = false
var bool tp2_alert_sent = false
var bool breakeven_alert_sent = false
var bool trail_alert_sent = false

// === ENTRY LOGIC ===
if long_entry and strategy.position_size == 0
    entry_price := close
    initial_stop := close - (atr * atr_mult_entry)
    current_stop := initial_stop
    tp1_price := close + ((close - initial_stop) * tp1_rr)
    tp2_price := close + ((close - initial_stop) * tp2_rr)
    tp3_price := close + ((close - initial_stop) * initial_rr)
    trail_trigger_price := close + ((close - initial_stop) * trail_activation)
    position_direction := "LONG"
    tp1_hit := false
    tp2_hit := false
    breakeven_moved := false
    bars_in_position := 0
    max_profit := 0.0
    long_entry_triggered := true
    tp1_alert_sent := false
    tp2_alert_sent := false
    breakeven_alert_sent := false
    trail_alert_sent := false
    
    if use_dynamic_sizing
        strategy.entry("LONG", strategy.long, qty=position_size, comment="L:" + str.tostring(long_confluences))
    else
        strategy.entry("LONG", strategy.long, comment="L:" + str.tostring(long_confluences))

if short_entry and strategy.position_size == 0
    entry_price := close
    initial_stop := close + (atr * atr_mult_entry)
    current_stop := initial_stop
    tp1_price := close - ((initial_stop - close) * tp1_rr)
    tp2_price := close - ((initial_stop - close) * tp2_rr)
    tp3_price := close - ((initial_stop - close) * initial_rr)
    trail_trigger_price := close - ((initial_stop - close) * trail_activation)
    position_direction := "SHORT"
    tp1_hit := false
    tp2_hit := false
    breakeven_moved := false
    bars_in_position := 0
    max_profit := 0.0
    short_entry_triggered := true
    tp1_alert_sent := false
    tp2_alert_sent := false
    breakeven_alert_sent := false
    trail_alert_sent := false
    
    if use_dynamic_sizing
        strategy.entry("SHORT", strategy.short, qty=position_size, comment="S:" + str.tostring(short_confluences))
    else
        strategy.entry("SHORT", strategy.short, comment="S:" + str.tostring(short_confluences))

// === POSITION MANAGEMENT ===
if strategy.position_size != 0
    bars_in_position += 1
    
    if position_direction == "LONG"
        current_profit = (close - entry_price) / entry_price
        max_profit := math.max(max_profit, current_profit)
        unrealized_pnl := (close - entry_price) * math.abs(strategy.position_size)
        
        // Partial take profits
        if use_partial_tp and not tp1_hit and close >= tp1_price
            strategy.close("LONG", qty_percent=tp1_percent, comment="TP1")
            tp1_hit := true
            tp1_alert_sent := true
            
        if use_partial_tp and not tp2_hit and close >= tp2_price and tp1_hit
            strategy.close("LONG", qty_percent=tp2_percent, comment="TP2")
            tp2_hit := true
            tp2_alert_sent := true
            
        // Move to breakeven after TP1
        if use_breakeven and tp1_hit and not breakeven_moved and close >= tp1_price
            current_stop := entry_price + (atr * 0.2)
            breakeven_moved := true
            breakeven_alert_sent := true
            
        // Profit trailing
        if use_profit_trail and close >= trail_trigger_price
            trail_stop = close - (atr * trail_distance)
            if trail_stop > current_stop
                current_stop := trail_stop
                trail_alert_sent := true
                
    else if position_direction == "SHORT"
        current_profit = (entry_price - close) / entry_price
        max_profit := math.max(max_profit, current_profit)
        unrealized_pnl := (entry_price - close) * math.abs(strategy.position_size)
        
        // Partial take profits
        if use_partial_tp and not tp1_hit and close <= tp1_price
            strategy.close("SHORT", qty_percent=tp1_percent, comment="TP1")
            tp1_hit := true
            tp1_alert_sent := true
            
        if use_partial_tp and not tp2_hit and close <= tp2_price and tp1_hit
            strategy.close("SHORT", qty_percent=tp2_percent, comment="TP2")
            tp2_hit := true
            tp2_alert_sent := true
            
        // Move to breakeven after TP1
        if use_breakeven and tp1_hit and not breakeven_moved and close <= tp1_price
            current_stop := entry_price - (atr * 0.2)
            breakeven_moved := true
            breakeven_alert_sent := true
            
        // Profit trailing
        if use_profit_trail and close <= trail_trigger_price
            trail_stop = close + (atr * trail_distance)
            if trail_stop < current_stop
                current_stop := trail_stop
                trail_alert_sent := true

// Exit conditions
var bool stop_loss_hit = false
var bool final_tp_hit = false
var bool trend_reversal_exit = false
var bool time_exit = false

// === EXIT LOGIC ===
if strategy.position_size > 0
    if close <= current_stop
        strategy.close_all(comment="SL")
        stop_loss_hit := true
        entry_price := na
        position_direction := na
    else if close >= tp3_price
        strategy.close_all(comment="TP3")
        final_tp_hit := true
        entry_price := na
        position_direction := na
    else if fast_under_slow and breakeven_moved
        strategy.close_all(comment="Trend Rev")
        trend_reversal_exit := true
        entry_price := na
        position_direction := na
    else if bars_in_position >= 100
        strategy.close_all(comment="Time Exit")
        time_exit := true
        entry_price := na
        position_direction := na

if strategy.position_size < 0
    if close >= current_stop
        strategy.close_all(comment="SL")
        stop_loss_hit := true
        entry_price := na
        position_direction := na
    else if close <= tp3_price
        strategy.close_all(comment="TP3")
        final_tp_hit := true
        entry_price := na
        position_direction := na
    else if fast_over_slow and breakeven_moved
        strategy.close_all(comment="Trend Rev")
        trend_reversal_exit := true
        entry_price := na
        position_direction := na
    else if bars_in_position >= 100
        strategy.close_all(comment="Time Exit")
        time_exit := true
        entry_price := na
        position_direction := na

// === PLOTTING ===
// EMAs
plot(ema_fast, color=color.lime, linewidth=2, title="EMA Fast")
plot(ema_slow, color=color.orange, linewidth=2, title="EMA Slow")
plot(ema_trend, color=color.blue, linewidth=2, title="EMA Trend")
plot(ema_major, color=color.purple, linewidth=3, title="EMA Major")

// Enhanced Entry signals with strength indication
plotshape(long_entry and long_confluences >= 18, style=shape.triangleup, location=location.belowbar, 
          color=color.new(color.lime, 0), size=size.large, title="ULTRA STRONG Long")
plotshape(long_entry and long_confluences >= 16 and long_confluences < 18, style=shape.triangleup, location=location.belowbar, 
          color=color.new(color.green, 20), size=size.normal, title="VERY STRONG Long")
plotshape(long_entry and long_confluences >= 14 and long_confluences < 16, style=shape.triangleup, location=location.belowbar, 
          color=color.new(color.green, 40), size=size.small, title="STRONG Long")

plotshape(short_entry and short_confluences >= 18, style=shape.triangledown, location=location.abovebar, 
          color=color.new(color.red, 0), size=size.large, title="ULTRA STRONG Short")
plotshape(short_entry and short_confluences >= 16 and short_confluences < 18, style=shape.triangledown, location=location.abovebar, 
          color=color.new(color.orange, 20), size=size.normal, title="VERY STRONG Short")
plotshape(short_entry and short_confluences >= 14 and short_confluences < 16, style=shape.triangledown, location=location.abovebar, 
          color=color.new(color.orange, 40), size=size.small, title="STRONG Short")

// Support and resistance
plot(liquidity_high, color=color.red, linewidth=2, style=plot.style_stepline, title="Liquidity High")
plot(liquidity_low, color=color.green, linewidth=2, style=plot.style_stepline, title="Liquidity Low")

// Position management levels
plot(strategy.position_size != 0 ? current_stop : na, color=color.red, linewidth=2, style=plot.style_linebr, title="Current Stop")
plot(strategy.position_size != 0 ? tp1_price : na, color=color.green, linewidth=1, style=plot.style_linebr, title="TP1")
plot(strategy.position_size != 0 ? tp2_price : na, color=color.green, linewidth=1, style=plot.style_linebr, title="TP2")
plot(strategy.position_size != 0 ? tp3_price : na, color=color.green, linewidth=2, style=plot.style_linebr, title="TP3")

// Background coloring
bgcolor(strategy.position_size > 0 ? color.new(color.green, 95) : strategy.position_size < 0 ? color.new(color.red, 95) : na, title="Position")