
یہ حکمت عملی ایک تجارتی نظام ہے جس میں دوہری مساوی لائن کراس سگنل اور متحرک رسک مینجمنٹ کا امتزاج ہے۔ مختصر اور طویل مدتی منتقل اوسط کی کراسنگ کے ذریعہ تجارتی سگنل تیار کیا جاتا ہے ، جبکہ اے ٹی آر اشارے کا استعمال کرتے ہوئے اسٹاپ نقصان اور فائدہ اٹھانے کی پوزیشن کو متحرک طور پر ایڈجسٹ کیا جاتا ہے ، اور وقت کے فلٹرنگ اور ٹھنڈک کی مدت کو تجارت کے معیار کو بہتر بنانے کے لئے متعارف کرایا جاتا ہے۔ اس حکمت عملی میں رسک ریٹرن اور فی تجارت کے خطرے کی فیصد کا انتظام بھی شامل ہے۔
حکمت عملی مندرجہ ذیل بنیادی اجزاء پر مبنی ہے:
اس حکمت عملی میں کلاسیکی تکنیکی تجزیہ کے طریقوں اور جدید رسک مینجمنٹ کے تصورات کو ملا کر ایک مکمل ٹریڈنگ سسٹم بنایا گیا ہے۔ اس کے بنیادی فوائد متحرک رسک مینجمنٹ اور ایک سے زیادہ فلٹرنگ میکانزم پر مبنی ہیں ، لیکن پھر بھی عملی استعمال میں مارکیٹ کی مخصوص خصوصیات کے مطابق پیرامیٹرز کو بہتر بنانے کی ضرورت ہے۔ اس حکمت عملی کے کامیاب آپریشن کے لئے تاجروں کو ہر اجزاء کے کردار کی گہرائی سے تفہیم کی ضرورت ہوتی ہے ، اور مارکیٹ میں تبدیلی کے مطابق پیرامیٹرز کو بروقت ایڈجسٹ کریں۔ تجویز کردہ اصلاحی سمت کے ذریعہ ، اس حکمت عملی کو مختلف مارکیٹ کے ماحول میں زیادہ مستحکم کارکردگی کا امکان ہے۔
/*backtest
start: 2024-09-18 00:00:00
end: 2025-02-19 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Profitable Moving Average Crossover Strategy", shorttitle="Profitable MA Crossover", overlay=true)
// Input parameters for the moving averages
shortPeriod = input.int(10, title="Short Period", minval=1)
longPeriod = input.int(100, title="Long Period", minval=1)
// Input parameters for time filter
startHour = input.int(0, title="Start Hour (UTC)", minval=0, maxval=23)
startMinute = input.int(0, title="Start Minute (UTC)", minval=0, maxval=59)
endHour = input.int(23, title="End Hour (UTC)", minval=0, maxval=23)
endMinute = input.int(59, title="End Minute (UTC)", minval=0, maxval=59)
// Cooldown period input (bars)
cooldownBars = input.int(10, title="Cooldown Period (Bars)", minval=1)
// Risk management inputs
riskRewardRatio = input.float(2, title="Risk-Reward Ratio", minval=1)
riskPercent = input.float(1, title="Risk Per Trade (%)", minval=0.1)
// ATR settings
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1.5, title="ATR Multiplier for Stop-Loss and Take-Profit")
// Calculate the moving averages
shortMA = ta.sma(close, shortPeriod)
longMA = ta.sma(close, longPeriod)
// Plot the moving averages
plot(shortMA, color=color.blue, title="Short MA")
plot(longMA, color=color.red, title="Long MA")
// Calculate ATR for dynamic stop-loss and take-profit
atr = ta.atr(atrLength)
stopLossOffset = atr * atrMultiplier
takeProfitOffset = stopLossOffset * riskRewardRatio
// Identify the crossover points
bullishCross = ta.crossover(shortMA, longMA)
bearishCross = ta.crossunder(shortMA, longMA)
// Get the current bar's time in UTC
currentTime = na(time("1", "UTC")) ? na : timestamp("UTC", year, month, dayofmonth, hour, minute)
// Define the start and end time in seconds from the start of the day
startTime = timestamp("UTC", year, month, dayofmonth, startHour, startMinute)
endTime = timestamp("UTC", year, month, dayofmonth, endHour, endMinute)
// Check if the current time is within the valid time range
isTimeValid = (currentTime >= startTime) and (currentTime <= endTime)
// Functions to check cooldown
var int lastSignalBar = na
isCooldownActive = (na(lastSignalBar) ? false : (bar_index - lastSignalBar) < cooldownBars)
// Handle buy signals
if (bullishCross and isTimeValid and not isCooldownActive)
entryPrice = close
stopLossBuy = entryPrice - stopLossOffset
takeProfitBuy = entryPrice + takeProfitOffset
strategy.entry("Buy", strategy.long)
strategy.exit("TakeProfit/StopLoss", "Buy", stop=stopLossBuy, limit=takeProfitBuy)
lastSignalBar := bar_index
// Handle sell signals
if (bearishCross and isTimeValid and not isCooldownActive)
entryPrice = close
stopLossSell = entryPrice + stopLossOffset
takeProfitSell = entryPrice - takeProfitOffset
strategy.entry("Sell", strategy.short)
strategy.exit("TakeProfit/StopLoss", "Sell", stop=stopLossSell, limit=takeProfitSell)
lastSignalBar := bar_index
// Plot signals on the chart
plotshape(series=bullishCross and isTimeValid and not isCooldownActive, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy", title="Buy Signal", textcolor=color.white)
plotshape(series=bearishCross and isTimeValid and not isCooldownActive, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell", title="Sell Signal", textcolor=color.white)
// Strategy performance tracking
strategy.close("Buy", when=not isTimeValid)
strategy.close("Sell", when=not isTimeValid)