تیراکی ٹرٹل ٹریڈنگ کی حکمت عملی


تخلیق کی تاریخ: 2024-02-29 15:15:54 آخر میں ترمیم کریں: 2024-02-29 15:15:54
کاپی: 4 کلکس کی تعداد: 974
1
پر توجہ دیں
1617
پیروکار

تیراکی ٹرٹل ٹریڈنگ کی حکمت عملی

جائزہ

یہ حکمت عملی دوہری منتقل اوسط کی تشکیل کے تجارتی سگنل کا استعمال کرتے ہوئے کم خطرہ والے رجحانات کی پیروی کرنے والی تجارت کو انجام دیتی ہے۔ اس کے معیاری داخلے اور باہر نکلنے کے قواعد ، تجارت کے خطرے کو مؤثر طریقے سے کنٹرول کرسکتے ہیں اور مستحکم فنڈ میں اضافے کو حاصل کرسکتے ہیں۔

حکمت عملی کا اصول

اسٹریٹجک ٹریڈنگ کی حکمت عملی 20 دن کی اونچائی ، 20 دن کی کم ، 55 دن کی اونچائی اور 55 دن کی کم قیمتوں کا حساب کتاب کرکے ، اے ٹی آر اشارے کے ساتھ مل کر اسٹاپ نقصان اور منافع کا ہدف طے کرتی ہے۔ جب قیمت 20 دن کی اونچائی سے تجاوز کرتی ہے تو طویل سگنل پیدا کرتی ہے۔ جب قیمت 20 دن کی کم سے نیچے آجاتی ہے تو خالی سگنل پیدا کرتی ہے۔ اس کے علاوہ ، اس حکمت عملی میں ایک باؤنسنگ میکانزم بھی موجود ہے ، اگر موجودہ قیمت 20 دن کی اونچائی اور کم سے تجاوز کر گئی ہے لیکن 55 دن کی اونچائی اور کم سے تجاوز نہیں کی گئی ہے تو ، اس بار کے تجارتی سگنل کو چھوڑ دیا جائے گا۔

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

طاقت کا تجزیہ

لچکدار تجارت کی حکمت عملی کا سب سے بڑا فائدہ یہ ہے کہ خطرہ کنٹرول کرنے کی بہترین صلاحیت ہے۔ معیاری داخلے اور باہر نکلنے کے قواعد سے ایک ہی تجارت میں ہونے والے نقصان کو مؤثر طریقے سے کنٹرول کیا جاسکتا ہے ، اور بائی پاس کرنے والے میکانزم سے راتوں رات اچھالنے سے بچنے سے بچنے سے بچنے کا امکان ہے۔ مستحکم نقصان کی روک تھام کی حکمت عملی بھی لگاتار نقصانات کی موجودگی کو محدود کرتی ہے۔

مزید برآں ، ٹریول ٹریڈنگ اسٹریٹجی اے ٹی آر اشارے کو متحرک طور پر روکنے کی حد مقرر کرنے کے لئے استعمال کرتی ہے ، جس سے اسٹاپ لائن کو خود بخود مارکیٹ کی اتار چڑھاؤ کی تبدیلیوں کے مطابق ڈھال لیا جاسکتا ہے۔ اس سے یہ یقینی بنتا ہے کہ اسٹاپ لائن نہ تو بہت زیادہ نقصان کا سبب بنے گی اور نہ ہی مارکیٹ میں معمول کی اتار چڑھاؤ کی وجہ سے بہت زیادہ تنگ ہوجائے گی۔

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

خطرے کا تجزیہ

لچکدار تجارت کی حکمت عملی کا بنیادی خطرہ یہ ہے کہ زلزلے کی صورتحال کو مؤثر طریقے سے فائدہ اٹھانا ممکن نہیں ہے۔ جب مارکیٹ میں طویل عرصے سے ہلچل ہوتی ہے تو ، اسٹاپ نقصان کی لائن اکثر نقصان کی وجہ سے متحرک ہوسکتی ہے۔ اور اس کو چھوڑنے سے بھی سگنل کی کمی اور ممکنہ تجارتی مواقع سے محروم ہوجاتا ہے۔

اس کے علاوہ ، اس حکمت عملی میں بنیادی تجزیہ کو نظرانداز کرنے کے لئے تکنیکی اشارے پر بہت زیادہ انحصار کیا گیا ہے۔ اس سے یہ ممکن ہے کہ اس میں اہم پالیسی تبدیلیوں کی نشاندہی نہ کی جاسکے ، جس سے غیر ضروری نقصانات کا سبب بنے گا۔

اصلاح کی سمت

اس کے علاوہ ، یہ بھی کہا گیا ہے کہ ٹریڈنگ کی حکمت عملی کو مندرجہ ذیل پہلوؤں سے بہتر بنایا جاسکتا ہے:

  1. اتار چڑھاؤ کے اشارے کے ساتھ مل کر ، بائی پاس کے طریقہ کار کی حساسیت کو ایڈجسٹ کریں ، اور ہلچل کے حالات میں تجارت کی فریکوئنسی میں اضافہ کریں

  2. بنیادی سگنل کو فلٹر کے طور پر شامل کریں تاکہ غیر متوقع واقعات کو روکنے سے بچنے کے لۓ

  3. اے ٹی آر پیرامیٹرز کی ترتیبات کو بہتر بنائیں تاکہ اسٹاپ لائن کو حقیقی اتار چڑھاؤ کے مطابق بنایا جاسکے

  4. مجموعی توانائی کے اشارے ، نقصانات کے بعد غیر موثر الٹ جانے سے بچنے کے لئے

خلاصہ کریں۔

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

حکمت عملی کا ماخذ کوڈ
/*backtest
start: 2024-01-29 00:00:00
end: 2024-02-28 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("TURTLE STRATEGY", precision=2, overlay=true, initial_capital=1000, commission_type=strategy.commission.percent, commission_value=0.18, slippage=3, pyramiding=5, close_entries_rule="ANY", margin_long=100, margin_short=100)



//------------------------------TOOL TIPS--------------------------------//

t1 = "Percentage of the account the trader is willing to lose. This percentage is used to define the position size based on previous gains or losses. Turtle traders default to 1%."
t2 = "ATR Length"
t3 = "ATR Multiplier to fix the Stop Loss"
t4 = "Pyramiding : ATR Multiplier to set a profit target to increase position size"
t5 = "System 1 enter long if there is a new high after this selected period of time"
t6 = "System 2 enter long if there is a new high after this selected period of time"
t7 = "Exit Long from system 1 if there is a new low after this selected period of time"
t8 = "Exit Long from system 2 if there is a new low after this selected period of time"
t9 = "System 1 enter short if there is a new low after this selected period of time"
t10 = "System 2 enter short if there is a new low after this selected period of time"
t11 = "Exit short from system 1 if there is a new high after this selected period of time"
t12 = "Exit short from system 2 if there is a new high after this selected period of time"


//----------------------------------------FUNCTIONS---------------------------------------//

//@function Displays text passed to `txt` when called.
debugLabel(txt, color) =>
    label.new(bar_index, high, text=txt, color=color, style=label.style_label_lower_right, textcolor=color.black, size=size.small)

//@function which looks if the close date of the current bar falls inside the date range
inBacktestPeriod(start, end) => (time >= start) and (time <= end)


//---------------------------------------USER INPUTS--------------------------------------//

//Risk Management and turtle system input
percentage_to_risk = input.float(1, "Risk % of capital", maxval=100, minval=0, group="Turtle Parameters", tooltip=t1) 
atr_period = input.int(20, "ATR period", minval=1, group="Turtle Parameters", tooltip=t2)
stop_N_multiplier = input.float(1.5, "Stop ATR", minval=0.1, group="Turtle Parameters", tooltip=t3)
pyramid_profit = input.float(0.5, "Pyramid Profit", minval=0.01, group="Turtle Parameters", tooltip=t4)
S1_long = input.int(20, "S1 Long", minval=1, group="Turtle Parameters", tooltip=t5)
S2_long = input.int(55, "S2 Long", minval=1, group="Turtle Parameters", tooltip=t6)
S1_long_exit = input.int(10, "S1 Long Exit", minval=1, group="Turtle Parameters", tooltip=t7)
S2_long_exit = input.int(20, "S2 Long Exit", minval=1, group="Turtle Parameters", tooltip=t8)
S1_short = input.int(15, "S1 Short", minval=1, group="Turtle Parameters", tooltip=t9)
S2_short = input.int(55, "S2 Short", minval=1, group="Turtle Parameters", tooltip=t10)
S1_short_exit = input.int(7, "S1 Short Exit", minval=1, group="Turtle Parameters", tooltip=t11)
S2_short_exit = input.int(20, "S2 Short Exit", minval=1, group="Turtle Parameters", tooltip=t12)
//Backtesting period
startDate = input(title="Start Date", defval=timestamp("1 Jan 2020 00:00:00"), group="Backtesting Period")
endDate = input(title="End Date", defval=timestamp("1 July 2034 00:00:00"), group="Backtesting Period")


//----------------------------------VARIABLES INITIALISATION-----------------------------//

//Turtle variables
atr = ta.atr(atr_period)
var float buy_price_long = na
var float buy_price_short = na
var float stop_loss_long = na
var float stop_loss_short = na
float account = na
//Entry variables
day_high_syst1 = ta.highest(high, S1_long)
day_low_syst1 = ta.lowest(low, S1_short)
day_high_syst2 = ta.highest(high, S2_long)
day_low_syst2 = ta.lowest(low, S2_short)
var bool skip = false
var bool unskip_buffer_long = false
var bool unskip_buffer_short = false
//Exit variables
exit_long_syst1 = ta.lowest(low, S1_long_exit)
exit_short_syst1 = ta.highest(high, S1_short_exit)
exit_long_syst2 = ta.lowest(low, S2_long_exit)
exit_short_syst2 = ta.highest(high, S2_short_exit)
float exit_signal = na
//Backtesting period
bool inRange = na


//------------------------------CHECKING SOME CONDITIONS ON EACH SCRIPT EXECUTION-------------------------------//

//Checking if the date belong to the range
inRange := true
strategy.initial_capital = 50000
//Checking if the current equity is higher or lower than the initial capital to adjusted position size
if strategy.equity - strategy.openprofit < strategy.initial_capital
    account := (strategy.equity-strategy.openprofit)*(strategy.equity-strategy.openprofit)/strategy.initial_capital
else
    account := strategy.equity - strategy.openprofit

//Checking if we close all trades in case where we exit the backtesting period
if strategy.position_size!=0 and not inRange
    strategy.close_all()
    debugLabel("END OF BACKTESTING PERIOD : we close the trade", color=color.rgb(116, 116, 116))


//--------------------------------------SKIP MANAGEMENT------------------------------------//
    
//Checking if a long signal has been skiped and system2 is not triggered
if skip and high>day_high_syst1[1] and high<day_high_syst2[1]
    unskip_buffer_long := true

//Checking if a short signal has been skiped and system2 is not triggered
if skip and low<day_low_syst1[1] and low>day_low_syst2[1]
    unskip_buffer_short := true

//Checking if current high is lower than previous 20_day_high after a skiped long signal to set skip to false
if unskip_buffer_long
    if high<day_high_syst1[1]
        skip := false
        unskip_buffer_long := false

//Checking if current low is higher than previous 20_day_low after a skiped short signal to set skip to false
if unskip_buffer_short
    if low>day_low_syst1[1]
        skip := false
        unskip_buffer_short := false

//Checking if we have an open position to reset skip and unskip buffers
if strategy.position_size!=0 and skip
    skip := false
    unskip_buffer_long := false
    unskip_buffer_short := false


//--------------------------------------------ENTRY CONDITIONS--------------------------------------------------//

//We calculate the position size based on turtle calculation
unit = (percentage_to_risk/100)*account/atr*syminfo.pointvalue

//Long order for system 1
if not skip and not (strategy.position_size>0) and inRange and unit>0
    strategy.cancel("Long Syst 2")
    //We check that position size doesn't exceed available equity
    if unit*day_high_syst1>account
        unit := account/day_high_syst1
    stop_loss_long := day_high_syst1 - stop_N_multiplier*atr
    //We adjust SL if it's greater than 10% of trade value and fix it to 10%
    if stop_loss_long < day_high_syst1*0.9
        stop_loss_long := day_high_syst1*0.9
    strategy.order("Long Syst 1", strategy.long, unit, stop=day_high_syst1)
    buy_price_long := day_high_syst1

//Long order for system 2
if skip and not (strategy.position_size>0) and inRange and unit>0
    //We check that position size doesn't exceed available equity
    if unit*day_high_syst2>account
        unit := account/day_high_syst2
    stop_loss_long := day_high_syst2 - stop_N_multiplier*atr
    //We adjust SL if it's greater than 10% of trade value and fix it to 10%
    if stop_loss_long < day_high_syst2*0.9
        stop_loss_long := day_high_syst2*0.9
    strategy.order("Long Syst 2", strategy.long, unit, stop=day_high_syst2)
    buy_price_long := day_high_syst2

//Short order for system 1
if not skip and not (strategy.position_size<0) and inRange and unit>0
    strategy.cancel("Short Syst 2")
    //We check that position size doesn't exceed available equity
    if unit*day_low_syst1>account
        unit := account/day_low_syst1
    stop_loss_short := day_low_syst1 + stop_N_multiplier*atr
    //We adjust SL if it's greater than 10% of trade value and fix it to 10%
    if stop_loss_short > day_low_syst1*1.1
        stop_loss_short := day_low_syst1*1.1
    strategy.order("Short Syst 1", strategy.short, unit, stop=day_low_syst1)
    buy_price_short := day_low_syst1

//Short order for system 2
if skip and not (strategy.position_size<0) and inRange and unit>0
    //We check that position size doesn't exceed available equity
    if unit*day_low_syst2>account
        unit := account/day_low_syst2
    stop_loss_short := day_low_syst2 + stop_N_multiplier*atr
    //We adjust SL if it's greater than 10% of trade value and fix it to 10%
    if stop_loss_short > day_low_syst2*1.1
        stop_loss_short := day_low_syst2*1.1
    strategy.order("Short Syst 2", strategy.short, unit, stop=day_low_syst2)
    buy_price_short := day_low_syst2


//-------------------------------PYRAMIDAL------------------------------------//

//Pyramid for long orders
if close > buy_price_long + (pyramid_profit*atr) and strategy.position_size>0
    //We calculate the remaining capital
    remaining_capital = account - strategy.position_size*strategy.position_avg_price*(1-0.0018)
    //We calculate units to add to the long position
    units_to_add = (percentage_to_risk/100)*remaining_capital/atr*syminfo.pointvalue
    if remaining_capital > units_to_add and units_to_add>0
        //We set the new Stop loss
        stop_loss_long := stop_loss_long + pyramid_profit*atr
        strategy.entry("Pyramid Long", strategy.long, units_to_add)
        buy_price_long := close

//Pyramid for short orders
if close < buy_price_short - (pyramid_profit*atr) and strategy.position_size<0
    //We calculate the remaining capital
    remaining_capital = account + strategy.position_size*strategy.position_avg_price*(1-0.0018)
    //We calculate units to add to the short position
    units_to_add = (percentage_to_risk/100)*remaining_capital/atr*syminfo.pointvalue
    if remaining_capital > units_to_add and units_to_add>0
        //We set the new Stop loss
        stop_loss_short := stop_loss_short - pyramid_profit*atr
        strategy.entry("Pyramid Short", strategy.short, units_to_add)
        buy_price_short := close


//----------------------------EXIT ORDERS-------------------------------//

//Checking if exit_long_syst1 is higher than stop_loss_long
if strategy.opentrades.entry_id(0)=="Long Syst 1"
    if exit_long_syst1[1] > stop_loss_long
        exit_signal := exit_long_syst1[1]
    else
        exit_signal := stop_loss_long

//Checking if exit_long_syst2 is higher than stop_loss_long
if strategy.opentrades.entry_id(0)=="Long Syst 2"
    if exit_long_syst2[1] > stop_loss_long
        exit_signal := exit_long_syst2[1]
    else
        exit_signal := stop_loss_long

//Checking if exit_short_syst1 is lower than stop_loss_short
if strategy.opentrades.entry_id(0)=="Short Syst 1"
    if exit_short_syst1[1] < stop_loss_short
        exit_signal := exit_short_syst1[1]
    else
        exit_signal := stop_loss_short

//Checking if exit_short_syst2 is lower than stop_loss_short
if strategy.opentrades.entry_id(0)=="Short Syst 2"
    if exit_short_syst2[1] < stop_loss_short
        exit_signal := exit_short_syst2[1]
    else
        exit_signal := stop_loss_short

//If the exit order is configured to close the position at a profit, we set 'skip' to true (we substract commission)
if strategy.position_size*exit_signal>strategy.position_size*strategy.position_avg_price*(1-0.0018)
    strategy.cancel("Long Syst 1")    
    strategy.cancel("Short Syst 1")
    skip := true
if strategy.position_size*exit_signal<=strategy.position_size*strategy.position_avg_price*(1-0.0018)
    skip := false

//We place stop exit orders
if strategy.position_size > 0
    strategy.exit("Exit Long", stop=exit_signal)

if strategy.position_size < 0
    strategy.exit("Exit Short", stop=exit_signal)


//------------------------------PLOTTING ELEMENTS-------------------------------//

plotchar(atr, "ATR", "", location.top, color.rgb(131, 5, 83))
//Plotting enter threshold
plot(day_high_syst1[1], "20 day high", color.rgb(118, 217, 159))
plot(day_high_syst2[1], "55 day high", color.rgb(4, 92, 53))
plot(day_low_syst1[1], "20 day low", color.rgb(234, 108, 108))
plot(day_low_syst2[1], "55 day low", color.rgb(149, 17, 17))
//Plotting Exit Signal
plot(exit_signal, "Exit Signal", color.blue, style=plot.style_circles)
//Plotting our position
exit_long_syst2_plot = plot(exit_long_syst2[1], color=na)
day_high_syst2_plot = plot(day_high_syst2[1], color=na)
exit_short_syst2_plot = plot(exit_short_syst2[1], color=na)
day_low_syst2_plot = plot(day_low_syst2[1], color=na)
fill(exit_long_syst2_plot, day_high_syst2_plot, color=strategy.position_size>0 ? color.new(color.lime, 90) : na)
fill(exit_short_syst2_plot, day_low_syst2_plot, color=strategy.position_size<0 ? color.new(color.red, 90) : na)