बहुआयामी प्रवृत्ति अनुनाद रणनीति

EMA RSI MACD ATR BB STOCH MFI MTF
निर्माण तिथि: 2025-11-12 17:01:17 अंत में संशोधित करें: 2025-11-12 17:01:17
कॉपी: 0 क्लिक्स: 209
2
ध्यान केंद्रित करना
319
समर्थक

बहुआयामी प्रवृत्ति अनुनाद रणनीति बहुआयामी प्रवृत्ति अनुनाद रणनीति

यह क्या है, 20 सूचकांकों का एक साथ सामना करना!

क्या आप जानते हैं? यह रणनीति आपके ट्रेडिंग को एक सुपर-बुद्धिमान एआई सहायक के साथ जोड़ने जैसा है! यह 20 अलग-अलग बाजार संकेतों की एक साथ निगरानी करता है और आपको केवल तभी ट्रेडिंग की सलाह देता है जब अधिकांश संकेतक “ठीक” कहते हैं। जैसे कि आप एक घर खरीदते हैं, आपको क्षेत्र, मूल्य, आवास प्रकार, यातायात पर विचार करना होगा … केवल सभी पहलुओं को पूरा करने के लिए!

यह एक साधारण एकल सूचकांक रणनीति नहीं है, बल्कि एक “बहु-आयामी प्रतिध्वनि प्रणाली” है। कल्पना कीजिए कि यदि केवल एक मित्र ने एक स्टॉक को अच्छा कहा है, तो आप आंशिक रूप से आश्वस्त हो सकते हैं; लेकिन अगर 20 पेशेवर मित्रों ने अच्छा कहा है, तो क्या आप अधिक आश्वस्त हैं?

ताइवान के परमाणु हथियारों के बारे में खुलासा

ट्रेंड पहचानना 🗡️

  • फास्ट ईएमए ((5) बनाम धीमी ईएमए ((13): अल्पकालिक रुझान मोड़ को पकड़ना
  • रुझान फ़िल्टर ईएमए ((34)): मध्य अवधि की दिशा की पुष्टि
  • मुख्य रुझान ईएमए ((89): छोटे उतार-चढ़ावों से भ्रमित न हों

बहु-समय-सीमा विश्लेषण ⏰ यह बहुत अच्छा है! रणनीति एक घंटे और चार घंटे के रुझानों को एक साथ देखती है, जैसे कि आप आगे की सड़क की स्थिति को देखते हुए ड्राइव करते हैं, लेकिन आप नेविगेट करने के लिए पूरे मार्ग को देखते हैं। यह “छोटे समय के फ्रेम में ऊपर, बड़े समय के फ्रेम में नीचे” की शर्मनाक स्थिति से बचा जाता है!

स्मार्ट जोखिम प्रबंधन 🛡️

  • गतिशील स्थिति समायोजनः बाजार में उतार-चढ़ाव के आधार पर स्वचालित रूप से दांव का आकार समायोजित करें
  • लोभ से बचें, भाग्यशाली बनें
  • मोबाइल स्टॉप लॉस: लाभ की रक्षा के लिए एक मंदिर

🔥 20 बहु-बीमा लेनदेन तर्क

यह एक बहुत ही आसान तरीका है।

  • ऊपर की ओर रुझानः सभी ईएमए बहुआयामी हैं
  • पर्याप्त गतिः आरएसआई, एमएसीडी, और यादृच्छिक आरएसआई ने हरी बत्ती दी
  • वज़न बढ़ाने के लिए व्यसनी होना
  • बाजार की संरचना स्वस्थ: ऊंचाइयों में वृद्धि
  • लिक्विडिटी सपोर्टः महत्वपूर्ण समर्थन पूर्ण

यह एक बहुत ही अजीब स्थिति है।

️: रणनीति और “बुलिन बेल्ट एक्सट्रैक्शन टेस्ट”, जब बाजार बहुत शांत हो जाता है, तो व्यापार को रोक दिया जाता है, ताकि बाजार में उतार-चढ़ाव के दौरान वापस आना न हो!

राजस्व को अधिकतम करने के लिए गुप्त हथियार

बैच बंद करने की रणनीति 📈

  • पहला स्टॉपः दो गुना रिस्क रिटर्न पर 30% पोजीशन बेचना
  • 3.5% के बाद 40% की बिक्री
  • अवशिष्ट स्थितिः मोबाइल स्टॉपलॉस प्रोटेक्शन के साथ, मुनाफे के लिए दौड़ें

स्मार्ट स्टॉप अपग्रेड 🎯 जब आप 2.5 गुना लाभ प्राप्त करते हैं, तो स्टॉप लॉस स्वचालित रूप से लागत मूल्य में स्थानांतरित हो जाता है, यह सुनिश्चित करने के लिए कि आप कम से कम कोई नुकसान नहीं करते हैं। यह आपके लाभ के लिए बीमा खरीदने जैसा है!

गतिशील ट्रैक रोक 🏃‍♂️ जब मुनाफा एक निश्चित स्तर तक पहुंच जाता है, तो स्टॉप लॉस कीमतों के पीछे छाया की तरह चलता है, जो मुनाफे की रक्षा करता है और साथ ही साथ स्टॉक को भी जगह देता है।

यह रणनीति इतनी बेवकूफ क्यों है?

  1. पूर्ण कवरेजतकनीकी विश्लेषण, धन प्रबंधन, जोखिम नियंत्रण, और बहुत कुछ।
  2. स्मार्ट फ़िल्टर20 सशर्त स्तरों की छानबीन, सफलता की दर में काफी वृद्धि
  3. अत्यधिक अनुकूलनीय: विभिन्न बाजार स्थितियों के लिए बहु-समय सीमा विश्लेषण
  4. मानवीय डिजाइन“मैंने कभी नहीं सोचा था कि मैं कभी भी किसी के साथ व्यापार कर सकता हूं।

यह रणनीति एक अनुभवी ट्रेडिंग टीम को कोड में डालती है, जो आपके लिए 24 घंटे बेहतरीन ट्रेडिंग अवसरों की तलाश में रहती है!

रणनीति स्रोत कोड
/*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")