
ایک کثیر ٹائم فریم صفر تاخیر رجحان سگنل ٹریڈنگ حکمت عملی ایک مقداری ٹریڈنگ سسٹم ہے جو صفر تاخیر اشاریہ منتقل اوسط ((ZLEMA) پر مبنی ہے جس کا مقصد روایتی منتقل اوسط کی تاخیر کو کم کرنا ہے اور تیزی سے درست رجحان کی نشاندہی کرنے والا سگنل فراہم کرنا ہے۔ حکمت عملی نہ صرف رجحان کی تبدیلی کی نشاندہی کرنے کے لئے اتار چڑھاؤ کے چینلز کو جوڑتی ہے بلکہ اس میں متعدد لچکدار باہر نکلنے کے طریقہ کار بھی شامل ہیں ، بشمول خطرے کی واپسی ، باہر نکلنے کے منافع کے ہدف سے باہر نکلنا ، اے ٹی آر پر مبنی اسٹاپ اور اسٹاپ نقصانات ، متحرک ٹریکنگ اسٹاپ نقصانات اور لائنوں کے ذریعے نکلنا وغیرہ۔ خاص طور پر درمیانے اور طویل مدتی تجارت کے لئے موزوں ہے۔ حکمت عملی کو صرف ایک یا دو طرفہ تجارت کرنے کے لئے تشکیل دیا جاسکتا ہے ، اور صفر لائن دوبارہ داخل کرنے کے اختیارات فراہم کرتا ہے ، جس سے تجارتی نظام کی لچک اور خطرے سے نمٹنے کی صلاحیت میں بہتری ہے۔
اس حکمت عملی کا بنیادی اصول صفر تاخیر اشاریہ منتقل اوسط ((ZLEMA) پر مبنی ہے ، جو ایک تکنیکی اشارے ہے جو قیمت کے اعداد و شمار کی تاخیر کو ختم یا کم کرکے منتقل اوسط کی ردعمل کی رفتار کو بہتر بناتا ہے۔ اس کو عملی جامہ پہنانے کے لئے اقدامات یہ ہیں:
صفر تاخیر حسابحکمت عملی: سب سے پہلے ZLEMA کا حساب لگائیں، فارمولے کے ذریعےzlema = ta.ema(src + (src - src[lag]), length)ان میں سےlagیہ طریقہ کار روایتی ای ایم اے میں تاخیر کو مؤثر طریقے سے کم کرتا ہے۔
رجحانات کی شناخت کا طریقہ کار:
zlemaUpTrendاورzlemaDownTrendمتغیرات کا نفاذمتنوع داخلے کی شرائط:
جامع متحرک آؤٹ سسٹم:
ایک سے زیادہ ٹائم فریم صفر تاخیر رجحان سگنل ٹریڈنگ حکمت عملی میں نمایاں فوائد ہیں:
سگنل کی تاخیر کو کم کرناZLEMA ٹکنالوجی کے ذریعہ ، روایتی منتقل اوسط کی تاخیر کو کم کیا گیا ہے ، جس سے رجحانات کی شناخت زیادہ بروقت ہوسکتی ہے ، اور رجحانات کے آغاز کو پہلے سے پکڑنے کے قابل ہوجاتا ہے۔
مکمل خطرے کے انتظام کا نظام: ایک مربوط کثیر سطح پر خطرے کے کنٹرول کے طریقہ کار ، جس میں فکسڈ اسٹاپ ، اے ٹی آر متحرک اسٹاپ ، ٹریکنگ اسٹاپ سے لے کر خسارے میں توازن اسٹاپ تک ، مختلف مارکیٹ کے حالات کے لئے بہترین تحفظ فراہم کیا گیا ہے۔
لچکدار تجارت کا انتخاب: مختلف مارکیٹ کی ترجیحات اور ریگولیٹری ماحول کو اپنانے کے لئے صرف ایک سے زیادہ حکمت عملی یا دو طرفہ تجارت کی حکمت عملی کے طور پر ترتیب دیا جاسکتا ہے۔
دوبارہ داخلے کا طریقہ کار: زیلیما زیرو لائن دوبارہ داخل ہونے کی خصوصیت کے ذریعہ ، ایک مضبوط رجحان میں مختصر مدت کے بعد دوبارہ داخل ہونے کی اجازت دیتا ہے ، جس سے رجحان کی آمدنی کو زیادہ سے زیادہ کیا جاسکتا ہے۔
خارج ہونے کی حکمت عملی: مختلف مارکیٹ کے حالات کے لئے متعدد باہر نکلنے کے اختیارات پیش کرتے ہیں ، جو منافع کو منافع کے اہداف کے ذریعہ مقفل کرسکتے ہیں ، یا منافع کو روکنے کے نقصانات کا سراغ لگانے کے ذریعہ چل سکتے ہیں۔
بصری معاون: ٹریڈنگ سگنل اور خطرے کے انتظام کی پوزیشن کو بصری عناصر جیسے رجحان کی سائے ، اسٹاپ نقصان کی لائن ، اسٹاپ باکس لائن اور رجحان اشارے کے ذریعہ دکھائیں۔
تفصیلی کارکردگی کے اعدادوشمارانٹیگریٹڈ ٹریڈنگ کے اعدادوشمار کی میزیں ، جو کلیدی اشارے جیسے جیت کی شرح ، خالص منافع اور زیادہ سے زیادہ واپسی کو ظاہر کرتی ہیں تاکہ حکمت عملی کا اندازہ لگانے اور بہتر بنانے میں مدد ملے۔
اگرچہ یہ حکمت عملی اچھی طرح سے ڈیزائن کی گئی ہے ، لیکن اس میں کچھ ممکنہ خطرات ہیں جن کے بارے میں آگاہ رہنا چاہئے:
پیرامیٹر کی حساسیتZLEMA لمبائی اور ATR ضرب جیسے بنیادی پیرامیٹرز حکمت عملی کی کارکردگی پر نمایاں اثر ڈالتے ہیں ، اور غلط ترتیب سے زیادہ یا کم سگنل کا سبب بن سکتا ہے۔
ہلچل مچانے والی مارکیٹ کے غلط اشارےاس کے نتیجے میں ، آپ کو ایک بار پھر نقصان کا سامنا کرنا پڑتا ہے ، اور آپ کو ایک بار پھر نقصان کا سامنا کرنا پڑتا ہے۔
رجحان کے الٹ جانے کا خطرہاگرچہ حکمت عملی میں ایک سے زیادہ باہر نکلنے کے طریقہ کار کو ڈیزائن کیا گیا ہے ، لیکن ایک شدید رجحان کے الٹ جانے پر ، یہ ممکن ہے کہ وہ باہر نکلنے سے پہلے ہی زیادہ نقصان اٹھائے۔
ملاپ کا خطرہ: متعدد پیرامیٹرز کا مجموعہ ممکنہ طور پر تاریخی اعداد و شمار پر زیادہ فٹ ہونے کا سبب بن سکتا ہے ، جو مستقبل کے مارکیٹ کے ماحول میں خراب کارکردگی کا مظاہرہ کرے گا۔
طویل دورانیے کا سگنل کمZLEMA کی طویل لمبائی کا استعمال کرتے وقت ، حکمت عملی کم تجارتی سگنل پیدا کرسکتی ہے ، جس سے فنڈز کے استعمال کی کارکردگی متاثر ہوتی ہے۔
چوڑائی کو روکنے کا چیلنجاے ٹی آر پر مبنی اسٹاپ نقصانات زیادہ اتار چڑھاؤ والی مارکیٹوں میں زیادہ وسیع ہوسکتے ہیں ، جس سے ایک ہی نقصان بہت زیادہ ہوتا ہے۔ جبکہ کم اتار چڑھاؤ والی مارکیٹوں میں یہ بہت تنگ ہوسکتا ہے ، جس کی وجہ سے اکثر ٹرگر ہوتا ہے۔
ان خطرات کو کم کرنے کے طریقوں میں شامل ہیں: سخت پیرامیٹرز کی واپسی اور آگے کی توثیق، مارکیٹ کی حالت کے اشارے کے ساتھ مل کر غیر مستحکم مارکیٹوں میں تجارت سے بچنے، سخت فنڈ مینجمنٹ کے قواعد کو نافذ کرنے، اور مارکیٹ میں تبدیلیوں کے مطابق حکمت عملی کے پیرامیٹرز کو باقاعدگی سے دوبارہ بہتر بنانے کے لئے.
اس حکمت عملی میں بہتری کی گنجائش موجود ہے اور اس میں مزید بہتری کی گنجائش موجود ہے:
متحرک پیرامیٹرز خود کو اپنانے: مارکیٹ کے اتار چڑھاؤ کے مطابق ZLEMA کی لمبائی اور ATR ضرب کو خود بخود ایڈجسٹ کرنے کے لئے ایک خود کار طریقے سے موافقت کا طریقہ کار تیار کریں ، تاکہ مارکیٹ کے مختلف حالات میں حکمت عملی کی موافقت کو بہتر بنایا جاسکے۔
مارکیٹ کی حالت کا فلٹر: مارکیٹ کی حیثیت کے اشارے متعارف کروائیں (جیسے ADX ، اتار چڑھاؤ کے اشارے) ، صرف سازگار مارکیٹ کے حالات میں تجارت کریں ، اور غیر موثر اتار چڑھاؤ والے بازاروں میں کثرت سے تجارت سے گریز کریں۔
ملٹی ٹائم فریم تصدیق: اعلی ٹائم فریم کے رجحانات کے ساتھ مل کر ، کامیابی کی شرح میں اضافہ صرف اس وقت ہوتا ہے جب رجحانات کی بڑی سمت سے مطابقت رکھتا ہو۔
ٹرانزیکشن کی تصدیق: تجارت کے حجم کے اشارے کو ضم کرنا بطور معاون تصدیق ، مثال کے طور پر رجحان میں تبدیلی کے اشارے کی تصدیق صرف اس وقت ہوتی ہے جب تجارت میں اضافہ ہوتا ہے۔
مشین لرننگ کی اصلاح: مشین لرننگ الگورتھم کا استعمال کرتے ہوئے بہترین پیرامیٹرز کا مجموعہ اور انٹری ٹائمنگ تلاش کریں ، خاص طور پر ماڈل کو یہ بتانے کے لئے تربیت دیں کہ کون سے سگنل زیادہ کامیاب ہوسکتے ہیں۔
موسمی اور وقت کے فلٹر: غیر موثر یا زیادہ خطرہ والے ٹریڈنگ کے اوقات سے بچنے کے لئے ٹریڈنگ کے اوقات اور کیلنڈر فلٹر شامل کریں۔
متعلقہ اثاثوں سے متعلقہ تجزیہ: متعلقہ اثاثوں کے متعلقہ تجزیہ کو متعارف کرانے کے لئے، متعدد اثاثوں کی ہم آہنگی کی تصدیق کے دوران سگنل کی وشوسنییتا کو بڑھانے کے لئے.
ان اصلاحات سے نہ صرف حکمت عملی کی استحکام اور منافع میں اضافہ ہوتا ہے بلکہ اس سے خطرے کو بھی کم کیا جاسکتا ہے ، جس سے یہ مختلف مارکیٹ کے حالات اور ذاتی خطرے کی ترجیحات کے لئے موزوں ہوجاتا ہے۔
ایک کثیر ٹائم فریم صفر تاخیر رجحان سگنل ٹریڈنگ حکمت عملی ایک جامع اور لچکدار مقداری ٹریڈنگ سسٹم ہے جو صفر تاخیر اشاریہ حرکت پذیر اوسط ((ZLEMA) ٹیکنالوجی اور اتار چڑھاؤ چینل کے ذریعہ تیزی سے اور درست رجحان کی شناخت کو یقینی بناتا ہے ، اور متحرک خطرے کے انتظام کے ایک کثیر سطح کے طریقہ کار کے ساتھ مل کر فنڈز کی حفاظت کرتا ہے۔ یہ حکمت عملی رجحانات کے ابتدائی مواقع پر قبضہ کرنے کے ساتھ ساتھ رجحانات کی ترقی میں دوبارہ داخل ہونے کے طریقہ کار کے ذریعہ زیادہ سے زیادہ منافع حاصل کرنے کے قابل ہے۔
حکمت عملی کا بنیادی فائدہ یہ ہے کہ سگنل کی تاخیر کو کم کیا جائے ، ایک جامع رسک مینجمنٹ سسٹم اور لچکدار تجارتی ترتیب کے اختیارات فراہم کیے جائیں۔ تاہم ، صارفین کو پیرامیٹرز کی حساسیت ، مارکیٹ کے جھٹکے والے جھوٹے سگنل اور ضرورت سے زیادہ موافقت جیسے ممکنہ خطرات سے آگاہ رہنے کی ضرورت ہے۔ حکمت عملی کی کارکردگی کو مزید بہتر بنانے کے لئے مارکیٹ کی حیثیت کو فلٹر کرنے ، کثیر وقتی فریم کی تصدیق اور متحرک پیرامیٹرز کی خود کو اپنانے جیسے اصلاحی سمتوں کے ذریعے حکمت عملی کی کارکردگی کو مزید بہتر بنایا جاسکتا ہے۔
تکنیکی اشارے پر مبنی ایک مقداری تجارتی نظام کی حیثیت سے ، یہ حکمت عملی خاص طور پر درمیانی اور طویل مدتی رجحانات کی تجارت کے لئے موزوں ہے ، جو مختلف مالیاتی منڈیوں میں لاگو ہوتی ہے۔ تاہم ، کسی بھی حکمت عملی کو انفرادی تجارتی اہداف ، خطرے کی برداشت اور مارکیٹ کی ترجیحات کے مطابق انفرادی طور پر ایڈجسٹ کرنے کی ضرورت ہوتی ہے ، اور سخت فنڈ مینجمنٹ اصولوں کے ساتھ مل کر اصل تجارت میں لاگو ہوتا ہے۔
//@version=6
// Quant Trading Pro www.quanttradingpro.com
// #1 Strategy Optimizer on the chrome extension store Quant Trading Strategy Optimizer
strategy(title="Quant Trading Zero Lag Trend Signals (MTF) Strategy", shorttitle="QT0️⃣Zero Lag Signals Strategy", overlay=true,
commission_type=strategy.commission.percent,
commission_value=0.1,
slippage=3,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
initial_capital=1000,
margin_long=0,
margin_short=0)
// === INPUT PARAMETERS ===
// 📌 1️⃣ Main Calculations
length = input.int(70, title="Length", minval=70, maxval=7000)
mult = input.float(1.2, "Band Multiplier", group="Main Calculations")
// === 📊 Trade Data Toggles ===
showFloatingTable = input.bool(true, "Show Floating Stats Table?", group="Trade Data")
showTradeLog = input.bool(false, "Show Trade Log Labels on Chart?", group="Trade Data")
enableCSVExport = input.bool(false, "Enable CSV Export", group="Trade Data")
// 📌 ZLEMA Trend Confirmation for Entries
useZlemaTrendConfirm = input.bool(false, "Use ZLEMA Trend Confirmation for entry?", group="Entry Conditions")
reEnterOnLongTrend = input.bool(false, "Re-Enter on Long Trend continuation", group="Entry Conditions")
// 📌 2️⃣ Short Trades
allowShortTrades = input.bool(false, "Allow Short Trades?", group="Short Trades")
// 📌 Performance Settings
useProfitTarget = input.bool(false, "Use Profit Target?", group="Performance Settings")
profitTargetRR = input.float(2.0, "Profit Target (Risk-Reward Ratio)", group="Performance Settings")
// 📌 4️⃣ Dynamic TP/SL (Each Setting with Its Parameters Directly Below)
useATRStopTP = input.bool(false, "Use ATR-Based Stop-Loss & Take-Profit?", group="Dynamic TP/SL")
atrLength = input.int(14, "ATR Length", group="Dynamic TP/SL")
atrMultiplier = input.float(1.5, "Stop-Loss ATR Multiplier", group="Dynamic TP/SL")
profitATRMultiplier = input.float(2.5, "Profit Target ATR Multiplier", group="Dynamic TP/SL")
useTrailingStop = input.bool(false, "Use ATR Trailing Stop?", group="Dynamic TP/SL")
trailStopMultiplier = input.float(1.5, "Trailing Stop ATR Multiplier", group="Dynamic TP/SL")
useBreakEven = input.bool(false, "Use Break-Even Stop-Loss?", group="Dynamic TP/SL")
breakEvenRR = input.float(1.5, "Move SL to Break-Even After RR", group="Dynamic TP/SL")
useTrendExit = input.bool(false, "Use Trend-Based Take Profit (EMA Exit)?", group="Dynamic TP/SL")
emaExitLength = input.int(9, "EMA Exit Length", group="Dynamic TP/SL")
// 📌 Debug Options
showZlemaDebug = input.bool(false, "Show ZLEMA Trend Debug?", group="Debug")
// ============================================================
// === 1️⃣ CALCULATIONS (Indicators, Trend, ATR, Stop/TP) ===
// ============================================================
src = close
lag = math.floor((length - 1) / 2)
zlema = ta.ema(src + (src - src[lag]), length)
volatility = ta.highest(ta.atr(length), length * 3) * mult
var trend = 0
if ta.crossover(close, zlema + volatility)
trend := 1
if ta.crossunder(close, zlema - volatility)
trend := -1
atrValue = ta.atr(atrLength)
emaExit = ta.ema(close, emaExitLength)
var float stopLossLongLevel = na
var float profitTargetLongLevel = na
var float stopLossShortLevel = na
var float profitTargetShortLevel = na
var int lastEntryBarIndex = na
var float lastEntryPrice = na
// ✅ Corrected ZLEMA DownTrend Logic: Ensure ZLEMA has decreased for 5 consecutive bars
// ✅ ZLEMA Increasing for 5 Bars → Bullish Trend (Green Triangle Up at the Bottom)
zlemaUpTrend = zlema > zlema[1] and zlema[1] > zlema[2] and zlema[2] > zlema[3] and zlema[3] > zlema[4]
// ✅ ZLEMA Decreasing for 5 Bars → Bearish Trend (Red Triangle Down at the Top)
zlemaDownTrend = zlema < zlema[1] and zlema[1] < zlema[2] and zlema[2] < zlema[3] and zlema[3] < zlema[4]
if ta.crossover(trend, 0) // Long Entry
stopLossLongLevel := useATRStopTP ? close - (atrValue * atrMultiplier) : zlema - volatility
profitTargetLongLevel := useProfitTarget ? (close + ((close - stopLossLongLevel) * profitTargetRR)) : na
if ta.crossunder(trend, 0) // Short Entry
stopLossShortLevel := useATRStopTP ? close + (atrValue * atrMultiplier) : zlema + volatility
profitTargetShortLevel := useProfitTarget ? (close - ((stopLossShortLevel - close) * profitTargetRR)) : na
// ATR-Based Stop-Loss Levels for Trade Exits
var float atrStopLossLong = na
var float atrStopLossShort = na
if useATRStopTP
if strategy.position_size > 0 // Long Position
atrStopLossLong := na(atrStopLossLong) or strategy.position_size[1] == 0 ? close - (atrValue * atrMultiplier) : math.max(nz(atrStopLossLong[1]), close - (atrValue * atrMultiplier)) // Prevents SL from decreasing
if strategy.position_size < 0 // Short Position
atrStopLossShort := na(atrStopLossShort) or strategy.position_size[1] == 0 ? close + (atrValue * atrMultiplier) : math.min(nz(atrStopLossShort[1]), close + (atrValue * atrMultiplier)) // Prevents SL from increasing
// ATR-Based Take-Profit Levels
var float atrTakeProfitLong = na
var float atrTakeProfitShort = na
if useATRStopTP
if strategy.position_size > 0 // Long Position
atrTakeProfitLong := strategy.position_avg_price + (atrValue * profitATRMultiplier) // Dynamic TP Based on ATR
if strategy.position_size < 0 // Short Position
atrTakeProfitShort := strategy.position_avg_price - (atrValue * profitATRMultiplier) // Dynamic TP Based on ATR
// ATR Trailing Stop Levels for Trade Exits and Visualization
var float trailStopLongLine = na
var float trailStopShortLine = na
if useTrailingStop
if strategy.position_size > 0 // Long Position
trailStopLongLine := na(trailStopLongLine) or strategy.position_size[1] == 0 ? close - (atrValue * trailStopMultiplier) :
math.max(nz(trailStopLongLine[1]), close - (atrValue * trailStopMultiplier))
if strategy.position_size < 0 // Short Position
trailStopShortLine := na(trailStopShortLine) or strategy.position_size[1] == 0 ? close + (atrValue * trailStopMultiplier) :
math.min(nz(trailStopShortLine[1]), close + (atrValue * trailStopMultiplier))
// ============================================================
// === 2️⃣ ENTRY & EXIT LOGIC (Conditions for Trading) ===
// ============================================================
// ✅ Entry Conditions for Long Trades
longCondition = ta.crossover(trend, 0) and close > zlema + volatility
canEnterLong = strategy.position_size == 0 or strategy.position_size[1] < 0 // Allows long entry right after short exit
if useZlemaTrendConfirm
longCondition := longCondition and zlemaUpTrend // Ensure ZLEMA Uptrend is true for long entries
// 🔥 Enforce that `longCondition` CANNOT be true if `zlemaUpTrend` is false
if useZlemaTrendConfirm and not zlemaUpTrend
longCondition := false
// ✅ Entry Conditions for Short Trades
shortCondition = allowShortTrades and ta.crossunder(trend, 0) and close < zlema - volatility
canEnterShort = strategy.position_size == 0 or strategy.position_size[1] > 0 // Allows short entry right after long exit
if useZlemaTrendConfirm
shortCondition := shortCondition and zlemaDownTrend // Ensure ZLEMA Downtrend is true for short entries
// ✅ Long Re-Entry Condition: ZLEMA is green, position is flat, price closed below and now above ZLEMA
reEntryLongCondition = reEnterOnLongTrend and
trend == 1 and
trend[1] == 1 and // ✅ Previous bar must also be in bullish trend (prevents triggering on trend change)
strategy.position_size == 0 and
close[1] < zlema[1] and
close > zlema
// ✅ Debugging: Display `longCondition` and `zlemaUpTrend` values only if the checkbox is checked
if showZlemaDebug and ta.crossover(trend, 0)
label.new(x=bar_index, y=low,
text="LongCondition: " + str.tostring(longCondition) +
"\nZLEMA UpTrend: " + str.tostring(zlemaUpTrend),
color=color.white, textcolor=color.black, size=size.small, style=label.style_label_down)
// ============================================================
// === 3️⃣ TRADE EXECUTIONS (Entries, ATR SL/TP, Trailing Stop, Trend Exit) ===
// ============================================================
// 📌 Entry Conditions
if (canEnterLong and longCondition) or reEntryLongCondition
lastEntryBarIndex := bar_index
lastEntryPrice := close
// 🛠️ Reset all SL/TP levels on Long Entry or Re-Entry
if reEntryLongCondition
// Trend-Based SL/TP
stopLossLongLevel := useATRStopTP ? na : zlema - volatility
profitTargetLongLevel := useProfitTarget and not useATRStopTP ? (close + ((close - stopLossLongLevel) * profitTargetRR)) : na
// ATR-Based SL/TP
atrStopLossLong := useATRStopTP ? close - (atrValue * atrMultiplier) : na
atrTakeProfitLong := useATRStopTP ? close + (atrValue * profitATRMultiplier) : na
// Trailing Stop
trailStopLongLine := useTrailingStop ? close - (atrValue * trailStopMultiplier) : na
strategy.entry(id="Long", direction=strategy.long, comment=reEntryLongCondition ? "Re-Entry Long" : "Bullish Trend Change")
if canEnterShort and shortCondition
lastEntryBarIndex := bar_index
lastEntryPrice := close
strategy.entry(id="Short", direction=strategy.short, comment="Bearish Trend Change")
// 📌 ATR-Based Stop-Loss Exits (Ensures SL Always Triggers Correctly)
if useATRStopTP and strategy.position_size > 0
if low <= atrStopLossLong
strategy.close("Long", comment="ATR SL Hit - Long")
if useATRStopTP and strategy.position_size < 0
if high >= atrStopLossShort
strategy.close("Short", comment="ATR SL Hit - Short")
// 📌 ATR-Based Stop-Loss & Take-Profit Exits (Ensures TP Always Executes)
if useATRStopTP and strategy.position_size > 0 and high >= atrTakeProfitLong
strategy.close("Long", comment="ATR TP Hit - Long")
if useATRStopTP and strategy.position_size < 0 and low <= atrTakeProfitShort
strategy.close("Short", comment="ATR TP Hit - Short")
// 📌 Profit Target Exits (Ensures TP Always Executes Independently)
if useProfitTarget and strategy.position_size > 0 and high >= profitTargetLongLevel
strategy.close("Long", comment="Profit Target Hit - Long")
if useProfitTarget and strategy.position_size < 0 and low <= profitTargetShortLevel
strategy.close("Short", comment="Profit Target Hit - Short")
// 📌 Stop-Loss for Profit Target Trades (Ensures Stop-Loss Works with TP)
if useProfitTarget and strategy.position_size > 0 and low <= stopLossLongLevel
strategy.close("Long", comment="Stop-Loss Hit - Long")
if useProfitTarget and strategy.position_size < 0 and high >= stopLossShortLevel
strategy.close("Short", comment="Stop-Loss Hit - Short")
// 📌 ATR Trailing Stop Loss (Ensures It Works Alongside Other Exits)
if useTrailingStop and strategy.position_size > 0 and low <= trailStopLongLine
strategy.close("Long", comment="Trailing Stop Hit - Long")
if useTrailingStop and strategy.position_size < 0 and high >= trailStopShortLine
strategy.close("Short", comment="Trailing Stop Hit - Short")
// 📌 Trend-Based Exit (Closes Position When Trend Reverses)
if strategy.position_size > 0 and ta.crossunder(trend, 0)
strategy.close("Long", comment="Trend Change to Bearish")
if strategy.position_size < 0 and ta.crossover(trend, 0)
strategy.close("Short", comment="Trend Change to Bullish")
// 📌 Break-Even Stop-Loss (Adjusts Stop to Entry Price at Set Risk-Reward Ratio)
if useBreakEven and strategy.position_size > 0 and high >= strategy.position_avg_price + (strategy.position_avg_price - atrStopLossLong) * breakEvenRR
atrStopLossLong := strategy.position_avg_price
if useBreakEven and strategy.position_size < 0 and low <= strategy.position_avg_price - (atrStopLossShort - strategy.position_avg_price) * breakEvenRR
atrStopLossShort := strategy.position_avg_price
// 📌 EMA Exit (Closes Position if Price Crosses EMA)
if useTrendExit and strategy.position_size > 0 and low < emaExit
strategy.close("Long", comment="Exit on EMA")
if useTrendExit and strategy.position_size < 0 and high > emaExit
strategy.close("Short", comment="Exit on EMA")
// ============================================================
// === 4️⃣ VISUALIZATIONS (Trend Shading, Stop-Loss, TP, ATR TS) ===
// ============================================================
// 🟢🔴 Restore Bullish/Bearish Trend Shading
zlemaColor = trend == 1 ? color.new(#00ffbb, 70) : color.new(#ff1100, 70)
m = plot(series=zlema, title="Zero Lag Basis", linewidth=2, color=zlemaColor)
upper = plot(zlema + volatility, style=plot.style_linebr, color=color.new(#ff1100, 90), title="Upper Deviation Band")
lower = plot(zlema - volatility, style=plot.style_linebr, color=color.new(#00ffbb, 90), title="Lower Deviation Band")
fill(plot1=m, plot2=upper, color=(trend == -1 ? color.new(#ff1100, 80) : na), title="Bearish Fill")
fill(plot1=m, plot2=lower, color=(trend == 1 ? color.new(#00ffbb, 80) : na), title="Bullish Fill")
// ✅ Plot a lime green TriangleUp at the bottom when ZLEMA has been going UP for 5 bars
plotshape(series=zlemaUpTrend ? low - ta.atr(5) * 0.5 : na,
location=location.bottom, style=shape.triangleup,
color=color.lime, title="ZLEMA Uptrend Detected")
// ✅ Plot a red TriangleDown at the top when ZLEMA has been going DOWN for 5 bars
plotshape(series=zlemaDownTrend ? high + ta.atr(5) * 0.5 : na,
location=location.top, style=shape.triangledown,
color=color.red, title="ZLEMA Downtrend Detected")
// 🔴 Default Stop-Loss Lines (Red) - Only Show If ATR SL/TP Is Not Used
plot(series=(not useATRStopTP and strategy.position_size > 0) ? stopLossLongLevel : na,
style=plot.style_linebr, color=color.red, linewidth=2, title="Trend Stop-Loss - Long")
plot(series=(not useATRStopTP and strategy.position_size < 0) ? stopLossShortLevel : na,
style=plot.style_linebr, color=color.red, linewidth=2, title="Trend Stop-Loss - Short")
// 🟠 ATR Trailing Stop Loss Line (Thin Orange Line) - Only Draw When Checkbox is Checked
plot(series=(useTrailingStop and strategy.position_size > 0) ? trailStopLongLine : na,
style=plot.style_linebr, color=color.new(color.orange, 70), linewidth=1, title="ATR Trailing Stop - Long")
plot(series=(useTrailingStop and strategy.position_size < 0) ? trailStopShortLine : na,
style=plot.style_linebr, color=color.new(color.orange, 70), linewidth=1, title="ATR Trailing Stop - Short")
// ✅ ATR-Based Stop-Loss Visualization (Ensures Line Stays Until Trade Closes)
plot(series=(useATRStopTP and strategy.position_size > 0) ? atrStopLossLong : na,
style=plot.style_linebr, color=color.new(color.red, 50), linewidth=2, title="ATR-Based Stop-Loss - Long")
plot(series=(useATRStopTP and strategy.position_size < 0) ? atrStopLossShort : na,
style=plot.style_linebr, color=color.new(color.red, 50), linewidth=2, title="ATR-Based Stop-Loss - Short")
// ✅ ATR-Based Take-Profit Visualization (Ensures Line Stays Until Trade Closes)
plot(series=(useATRStopTP and strategy.position_size > 0) ? atrTakeProfitLong : na,
style=plot.style_linebr, color=color.new(color.green, 50), linewidth=2, title="ATR-Based Take-Profit - Long")
plot(series=(useATRStopTP and strategy.position_size < 0) ? atrTakeProfitShort : na,
style=plot.style_linebr, color=color.new(color.green, 50), linewidth=2, title="ATR-Based Take-Profit - Short")
// ✅ Standard Profit Target Visualization (Only Active if ATR SL/TP is NOT Used)
plot(series=(useProfitTarget and not useATRStopTP and strategy.position_size > 0) ? profitTargetLongLevel : na,
style=plot.style_linebr, color=color.green, linewidth=2, title="Profit Target - Long")
plot(series=(useProfitTarget and not useATRStopTP and strategy.position_size < 0) ? profitTargetShortLevel : na,
style=plot.style_linebr, color=color.green, linewidth=2, title="Profit Target - Short")
// === 📋 FLOATING TABLE: STRATEGY PERFORMANCE & SETTINGS ===
// === Track first and last trade times ===
var int firstTradeTime = na
var int lastTradeTime = na
if strategy.opentrades > 0 and na(firstTradeTime)
firstTradeTime := time
if strategy.closedtrades > 0
lastTradeTime := time
// === Format trade date strings safely ===
firstDateStr = "N/A"
lastDateStr = "N/A"
if not na(firstTradeTime)
firstDateStr := str.tostring(month(firstTradeTime)) + "/" + str.tostring(dayofmonth(firstTradeTime)) + "/" + str.tostring(year(firstTradeTime) % 100)
if not na(lastTradeTime)
lastDateStr := str.tostring(month(lastTradeTime)) + "/" + str.tostring(dayofmonth(lastTradeTime)) + "/" + str.tostring(year(lastTradeTime) % 100)