
یہ حکمت عملی ایک اعلی درجے کی مقداری تجارتی نظام ہے جو متعدد اوسط اور متعدد ٹائم پیریڈ پر مبنی ہے۔ اس سے تاجروں کو مختلف قسم کی حرکت پذیر اوسطوں (بشمول ایس ایم اے ، ای ایم اے ، ڈبلیو ایم اے ، ایچ ایم اے اور ایس ایم ایم اے) کو آزادانہ طور پر منتخب کرنے کی اجازت ملتی ہے ، اور مارکیٹ کے حالات کے مطابق متعدد ٹائم پیریڈ جیسے سورج ، ہفتہ وار یا قمری لائنوں میں آزادانہ طور پر تبدیل ہوسکتی ہے۔ حکمت عملی کا بنیادی منطق یہ ہے کہ خرید و فروخت کے سگنل کا تعین منتخب اوسط کے مقام کے ساتھ موازنہ کرکے کیا جائے ، جبکہ مختلف ٹائم سائیکل چیک کے ساتھ مل کر تجارت کی درستگی کو بہتر بنایا جائے۔
حکمت عملی میں ماڈیولر ڈیزائن کا استعمال کیا گیا ہے ، جس میں بنیادی طور پر چار بنیادی اجزاء شامل ہیں: اوسط لائن کی قسم کا انتخاب ماڈیول ، ٹائم پیریڈ سلیکشن ماڈیول ، سگنل جنریٹر ماڈیول اور پوزیشن مینجمنٹ ماڈیول۔ جب اختتامی قیمت پر منتخب اوسط لائن کو عبور کیا جاتا ہے تو ، اگلے تجارتی دور کے آغاز پر سسٹم متعدد سگنل جاری کرتا ہے۔ جب اختتامی قیمت اوسط لائن کو عبور کرتی ہے تو ، اگلے تجارتی دور کے آغاز پر سسٹم ایک صفائی سگنل جاری کرتا ہے۔ حکمت عملی میں request.security فنکشن کے ذریعہ دورانیہ کے اعداد و شمار کا حساب کتاب کیا جاتا ہے ، جس سے مختلف فریم ٹائم کے تحت سگنل کی درستگی کو یقینی بنایا جاتا ہے۔
حکمت عملی ایک اچھی طرح سے ڈیزائن کیا گیا ، منطقی طور پر واضح تجارتی نظام ہے ، جو لچکدار پیرامیٹرز کی ترتیب اور متعدد تصدیق کے طریقہ کار کے ذریعہ تاجروں کو ایک قابل اعتماد تجارتی آلہ مہیا کرتا ہے۔ حکمت عملی کا ماڈیولر ڈیزائن اس کی مضبوط توسیع پذیری کو یقینی بناتا ہے ، جس کی مسلسل اصلاح کے ذریعہ اس کی کارکردگی کو مزید بہتر بنایا جاسکتا ہے۔ یہ تجویز کی جاتی ہے کہ جب تاجر ریئل اسٹیٹ میں استعمال ہوتا ہے تو ، پہلے مختلف پیرامیٹرز کے مجموعوں کی جانچ پڑتال کی جائے ، تاکہ اپنے لئے بہترین تجارتی حکمت عملی کی تشکیل تلاش کی جاسکے۔
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Flexible Moving Average Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Input to select the review frequency (Daily, Weekly, Monthly)
check_frequency = input.string("Weekly", title="Review Frequency", options=["Daily", "Weekly", "Monthly"])
// Input to select the Moving Average method (SMA, EMA, WMA, HMA, SMMA)
ma_method = input.string("EMA", title="Moving Average Method", options=["SMA", "EMA", "WMA", "HMA", "SMMA"])
// Input to select the length of the Moving Average
ma_length = input.int(30, title="Moving Average Length", minval=1)
// Input to select the timeframe for Moving Average calculation
ma_timeframe = input.string("W", title="Moving Average Timeframe", options=["D", "W", "M"])
// Calculate all Moving Averages on the selected timeframe
sma_value = request.security(syminfo.tickerid, ma_timeframe, ta.sma(close, ma_length), lookahead=barmerge.lookahead_off)
ema_value = request.security(syminfo.tickerid, ma_timeframe, ta.ema(close, ma_length), lookahead=barmerge.lookahead_off)
wma_value = request.security(syminfo.tickerid, ma_timeframe, ta.wma(close, ma_length), lookahead=barmerge.lookahead_off)
hma_value = request.security(syminfo.tickerid, ma_timeframe, ta.hma(close, ma_length), lookahead=barmerge.lookahead_off)
smma_value = request.security(syminfo.tickerid, ma_timeframe, ta.rma(close, ma_length), lookahead=barmerge.lookahead_off) // Smoothed Moving Average (SMMA)
// Select the appropriate Moving Average based on user input
ma = ma_method == "SMA" ? sma_value :
ma_method == "EMA" ? ema_value :
ma_method == "WMA" ? wma_value :
ma_method == "HMA" ? hma_value :
smma_value // Default to SMMA
// Variable initialization
var float previous_close = na
var float previous_ma = na
var float close_to_compare = na
var float ma_to_compare = na
// Detect the end of the period (Daily, Weekly, or Monthly) based on the selected frequency
var bool is_period_end = false
if check_frequency == "Daily"
is_period_end := ta.change(time('D')) != 0
else if check_frequency == "Weekly"
is_period_end := ta.change(time('W')) != 0
else if check_frequency == "Monthly"
is_period_end := ta.change(time('M')) != 0
// Store the close and Moving Average values at the end of the period
if is_period_end
previous_close := close[0] // Closing price of the last day of the period
previous_ma := ma[0] // Moving Average value at the end of the period
// Strategy logic
is_period_start = is_period_end
// Check if this is the first bar of the backtest
is_first_bar = barstate.isfirst
if (is_period_start or is_first_bar)
// If the previous period values are not available, use current values
close_to_compare := not na(previous_close) ? previous_close : close[0]
ma_to_compare := not na(previous_ma) ? previous_ma : ma[0]
if close_to_compare < ma_to_compare
// Close price below the MA -> Sell
if strategy.position_size > 0
strategy.close("Long")
else
// Close price above the MA -> Buy/Hold
if strategy.position_size == 0
strategy.entry("Long", strategy.long)
// Close all positions at the end of the backtest period
if barstate.islastconfirmedhistory
strategy.close_all(comment="Backtest End")
// Plot the previous period's close price for comparison
plot(previous_close, color=color.red, title="Previous Period Close", style=plot.style_stepline)
plot(close_to_compare, color=color.blue, title="Close to Compare", style=plot.style_line)
// Plot the selected Moving Average
plot(ma, color=color.white, title="Moving Average", style=plot.style_line, linewidth=3)