دوہری حرکت پذیر اوسط کراس اوور ٹریڈنگ کی حکمت عملی

مصنف:چاؤ ژانگ، تاریخ: 2023-11-21 12:26:53
ٹیگز:

img

جائزہ

یہ حکمت عملی دوہری سادہ حرکت پذیر اوسط (ایس ایم اے) کے کراس اوور سگنلز کی بنیاد پر اندراجات اور باہر نکلنے کا تعین کرتی ہے۔ خاص طور پر ، قلیل مدتی ایس ایم اے کی مدت 14 ہے ، جبکہ طویل مدتی ایس ایم اے کی مدت 28 ہے۔ ایک طویل سگنل اس وقت شروع ہوتا ہے جب قلیل مدتی ایس ایم اے طویل مدتی ایس ایم اے کو عبور کرتا ہے۔ اس کے برعکس ، ایک مختصر سگنل اس وقت شروع ہوتا ہے جب قلیل مدتی ایس ایم اے طویل مدتی ایس ایم اے سے نیچے عبور کرتا ہے۔

حکمت عملی منطق

  1. ان پٹ

    • اشارے کی ترتیبات: تیز رفتار اور سست SMA کے لئے ادوار کی وضاحت کریں
    • لے منافع اور سٹاپ نقصان: منافع اور سٹاپ نقصان کے لئے فیصد تشکیل دیں
    • منی مینجمنٹ: ابتدائی سرمایہ، کمیشن فیس وغیرہ مقرر کریں
  2. متغیرات

    انٹرمیڈیٹ متغیرات کو منافع لینے کی قیمت، سٹاپ نقصان کی قیمت، پوزیشن سائزنگ وغیرہ کے لئے اقدار کو ذخیرہ کرنے کے لئے مقرر کیا جاتا ہے. اس سے بار بار حساب سے بچنے سے بچتا ہے.

  3. سگنل جنریشن

    ایس ایم اے کراس اوور کا استعمال لمبے اور مختصر سگنل کا تعین کرنے کے لئے کیا جاتا ہے۔

  4. داخلے کے قواعد

    جب ایک انٹری سگنل ٹرگر کیا جاتا ہے تو، حکمت عملی منطق کی بنیاد پر ایک نیا آرڈر رکھنے سے پہلے مخالف سمت میں کسی بھی موجودہ پوزیشن کو پہلے برابر کیا جاتا ہے.

  5. باہر نکلنے کے قواعد

    منافع لینے اور سٹاپ نقصان کے قواعد پوزیشن کے باہر نکلنے کے لئے ترتیب دیئے گئے ہیں.

  6. منی مینجمنٹ

    پوزیشن سائزنگ کا استعمال تجارت کے مطابق خطرے کا انتظام کرنے کے لئے کیا جاتا ہے۔

فوائد

  1. سادہ منطق، سمجھنے میں آسان
  2. قابل کنٹرول ڈرائنگ
  3. بہتر بنانے کے قابل پیرامیٹرز

خطرات اور تخفیف

  1. SMA کراس اوور سگنلز میں تاخیر

    مختصر SMA ادوار پر غور کریں، یا اضافی اشارے کے ساتھ مکمل کریں

  2. مختلف مارکیٹوں میں سٹاپ نقصان کا خطرہ

    سٹاپ نقصان فی صد کو وسیع کریں، یا ٹریلنگ اسٹاپ استعمال کریں

  3. سب سے کم پیرامیٹرز نقصانات کو بڑھا سکتے ہیں

    سختی سے بیک ٹیسٹ اور پیرامیٹرز کو بہتر بنائیں

بہتر مواقع

  1. اضافی اشارے کے ساتھ مکمل کریں

    مثال کے طور پر، سیگنل لیگ کو کم کرنے کے لئے MACD، KD وغیرہ

  2. ایس ایم اے ادوار کو بہتر بنائیں

    مختصر اور طویل SMA ادوار کے زیادہ مجموعے کی جانچ کریں

  3. دیگر منافع لینے / نقصان کو روکنے کی حکمت عملی کے ساتھ تجربہ

    مثال کے طور پر فکسڈ ڈالر ویلیو، ٹریلنگ اسٹاپ وغیرہ

نتیجہ

اس حکمت عملی میں واضح اور آسان منطق ہے ، بیک ٹیسٹ کے نتائج کا وعدہ ہے ، اور کام کرنا آسان ہے - ابتدائی تاجروں کے لئے موزوں ہے۔ حکمت عملی کو زیادہ مضبوط بنانے کے لئے اضافی اشارے ، منی مینجمنٹ کی تکنیک وغیرہ کے ذریعہ ابھی بھی بہتری کی گنجائش ہے۔


/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigJasTrades https://linktr.ee/bigjastrades 

// READ THIS BEFORE USE:
// This code is provided as an example strategy for educational purposes only.  It comes with NO warranty or claims of performance.
// It should be used as a basis for your own learning and development and to create your own strategies.
// It is NOT provided to enable you to profitably trade. 
// If you use this code or any part of it you agree that you have thoroughly tested it and determined that it is suitable for your own purposes prior to use.
// If you use this code or any part of it you agree that you accept all risk and you are responsibile for the results.

//@version=5
strategy(title = "Strategy Template", shorttitle = "ST v1.0", overlay = true, pyramiding = 1, initial_capital = 1000, commission_type = strategy.commission.percent, commission_value = 0.1, max_labels_count = 500)

//INPUTS
//indicator values
shortSMAlength              = input.int(defval = 14, title = "Short SMA Length", tooltip = "Set the length of the short simple moving average here.", minval = 1, step = 1, group = "Indicator Settings")
longSMAlength               = input.int(defval = 28, title = "Long SMA Length", tooltip = "Set the length of the long simple moving average here.", minval = 1, step = 1, group = "Indicator Settings")
//compounding
compoundingSelected         = input.bool(defval = true, title = "Compounding", tooltip = "Select this option if you want to compound your net profits.", group = "Compounding")
//take profit and stop loss
takeProfitSelected          = input.bool(defval = true, title = "Use Take Profit", tooltip = "Select this to enable take profits.", group = "Take Profit and Stop Loss")
takeProfitPercent           = input.float(defval = 1.0, title = "Take Profit %", tooltip = "Set the value of take profits here.", minval = 0.1, step = 0.1, group = "Take Profit and Stop Loss")
stopLossSelected            = input.bool(defval = true, title = "Use Stop Loss", tooltip = "Select this to enable stop losses.", group = "Take Profit and Stop Loss")
stopLossPercent             = input.float(defval = 1.0, title = "Take Profit %", tooltip = "Set the value of stop losses here.", minval = 0.1, step = 0.1, group = "Take Profit and Stop Loss")
//trading window
startDate                   = input(defval = timestamp("1 Jan 2023 00:00:00"), title = "Start Date", tooltip = "Use this to set the date and time when Viva will start placing trades.  Set this to a time just after the last candle when activating auto trading.", group = "TRADING WINDOW")
endDate                     = input(defval = timestamp("1 Jan 2030 00:00:00"), title = "End Date", tooltip = "Use this to set the date and time when Viva will stop placing trades.", group = "TRADING WINDOW")

//VARIABLES
var float tradingCapital    = na //trading capital is used to calculate position size based on the intitial capital and, if compounding is selected, also the net profit
var float positionSize      = na //position size is used to set the quantity of the asset you want to buy.  It is based on the initial capital and the net profit if compounding is selected.
var float takeProfitPrice   = na //this is used for take profit targets if selected
var float stopLossPrice     = na //this is used for stop loss if selected

inTradeWindow               = true
strategy.initial_capital = 50000
//COMPOUNDING
if compoundingSelected // set the tradingCapital available to the strategy based on wither Compounding has been selected or not.  This will be used to determine the position size.
    tradingCapital := strategy.initial_capital + strategy.netprofit
else
    tradingCapital := strategy.initial_capital

//ENTRY CONDITIONS
//replace these with your own conditions
longCondition = ta.crossover(source1 = ta.sma(source = close, length = shortSMAlength), source2 =  ta.sma(source = close, length =longSMAlength))
shortCondition = ta.crossunder(source1 = ta.sma(source = close, length = shortSMAlength), source2 = ta.sma(source = close, length = longSMAlength))

//EXIT CONDITIONS
//Exit conditions are based on stop loss, take profit and the opposite entry condition being present.  Stop Loss and Take Profit are contained in the strategy.exit code below and are based on the value assigned in the Inputs.


//ENTRY ORDERS
//Enter Long
if longCondition and inTradeWindow
    //close any prior short positions
    if strategy.position_size < 0 //if in a short position
        strategy.close_all(comment = "Buy to Close")
    //set position size
    positionSize := tradingCapital / close
    //enter long position
    strategy.entry(id = "Buy to Open", direction =  strategy.long, qty = positionSize)

//Enter Short
if shortCondition and inTradeWindow
    //close any prior long positions
    if strategy.position_size > 0 //if in a long position
        strategy.close_all(comment = "Sell to Close")
    //set position size
    positionSize := tradingCapital / close
    //enter short position
    strategy.entry(id = "Sell to Open", direction =  strategy.short, qty = positionSize)

//IN-ORDER MANAGEMENT
//placeholder - none used in this template


//EXIT ORDERS
//Stop Loss and Take Profit for Long Positions
if strategy.opentrades > 0 and strategy.position_size > 0 and (takeProfitSelected or stopLossSelected)   //if there is an open position and it is a long position and either a take profit or sto ploss is selected.
    if takeProfitSelected
        takeProfitPrice := strategy.position_avg_price * (1 + (takeProfitPercent / 100))
    else
        takeProfitPrice := na
    if stopLossSelected
        stopLossPrice := strategy.position_avg_price * (1 - (stopLossPercent / 100))
    else
        stopLossPrice := na
    strategy.exit(id = "Exit", from_entry = "Buy to Open", qty_percent = 100, profit = takeProfitPrice, loss = stopLossPrice, comment_profit = "Take Profit", comment_loss = "Stop Loss")

//Stop Loss and Take Profit for Short Positions
if strategy.opentrades > 0 and strategy.position_size < 0 and (takeProfitSelected or stopLossSelected)   //if there is an open position and it is a short position and either a take profit or sto ploss is selected.
    if takeProfitSelected
        takeProfitPrice := strategy.position_avg_price * (1 - (takeProfitPercent / 100))
    else
        takeProfitPrice := na
    if stopLossSelected
        stopLossPrice := strategy.position_avg_price * (1 + (stopLossPercent / 100))
    else
        stopLossPrice := na
    strategy.exit(id = "Exit", from_entry = "Buy to Open", qty_percent = 100, profit = takeProfitPrice, loss = stopLossPrice, comment_profit = "Take Profit", comment_loss = "Stop Loss")


//VISUALISATIONS
plot(series = ta.sma(source = close, length = shortSMAlength), title = "Short SMA", color = color.new(color = color.red, transp = 50), linewidth = 2)
plot(series = ta.sma(source = close, length = longSMAlength), title = "Long SMA", color = color.new(color = color.blue, transp = 50), linewidth = 2)

bgcolor(color = longCondition ? color.new(color = color.green, transp = 95) : na, title = "Long")
bgcolor(color = shortCondition ? color.new(color = color.red, transp = 95) : na, title = "Short")

مزید