کوانٹیٹیو ٹریڈنگ پلیٹ فارم پر مبنی ایڈجسٹ نیٹ ٹریڈنگ کی حکمت عملی

مصنف:چاؤ ژانگ، تاریخ: 2024-02-21 10:55:21
ٹیگز:

img

جائزہ

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

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

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

  2. ہر نیٹ ورک کے لئے قیمت کے وقفے کو اوپری اور نچلی حد کی قیمتوں اور نیٹ ورک کی تعداد کی بنیاد پر حساب لگائیں۔

  3. گرڈ کے طور پر اوپری اور نچلی حد کی قیمتوں کے درمیان برابر وقفوں پر متعدد خرید اور فروخت کے مقامات کو ترتیب دیں.

  4. جب مارکیٹ کی قیمت گرڈ کی نیچے کی حد کو پار کرتی ہے تو ، گرڈ کے نیچے اگلے گرڈ پر خرید آرڈر رکھیں جہاں آخری غیر بند آرڈر واقع ہے۔ جب مارکیٹ کی قیمت گرڈ کی اوپری حد کو پار کرتی ہے تو ، گرڈ کے اوپر گرڈ پر فروخت آرڈر رکھیں جہاں آخری غیر بند آرڈر واقع ہے۔

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

فوائد کا تجزیہ

  1. گرڈ ٹریڈنگ رینج سے منسلک اور نوساناتی مارکیٹوں میں منافع بخش ہوسکتی ہے۔

  2. گرڈ رینج کی انکولی ایڈجسٹمنٹ دستی مداخلت کے بغیر مارکیٹ میں اتار چڑھاؤ کی بنیاد پر خود بخود ایڈجسٹ کر سکتے ہیں.

  3. سرمایہ کاری کی رقم کو پہلے سے مقرر کیا جاسکتا ہے تاکہ خطرات کو نیٹ ورکس میں تقسیم کیا جاسکے۔

  4. منطق سادہ اور سمجھنے میں آسان ہے، اور پیرامیٹرز کو ایڈجسٹ کرنے کے لئے لچکدار ہیں.

خطرے کا تجزیہ

  1. اوپری اور نچلی حدود کو توڑنے سے نقصانات ہوسکتے ہیں

    • حل: معقول طور پر سٹاپ نقصان کی پوزیشن مقرر کریں.
  2. مارکیٹوں میں رجحانات بار بار نقصانات کا باعث بن سکتے ہیں

    • حل: رجحانات کی نشاندہی کریں اور بروقت تجارت کو روکیں۔
  3. پیرامیٹر کی غلط ترتیبات

    • حل: گرڈ کی مقدار اور قیمت کے وقفے کے پیرامیٹرز کو ایڈجسٹ کریں۔

اصلاح کی ہدایات

  1. گرڈ پیرامیٹرز کو متحرک طور پر ایڈجسٹ کرنے کے لئے قیمتوں میں اتار چڑھاؤ کی حد اور رجحانات کی پیش گوئی کرنے کے لئے مشین لرننگ کا استعمال کریں۔

  2. گرڈ ٹریڈنگ کے نقصانات سے بچنے کے لئے رجحاناتی مارکیٹوں میں رجحان کی تجارت پر سوئچ کریں.

  3. سرمایہ کاری کے استعمال کی شرح، منافع کی شرح وغیرہ پر مبنی خطرے کے کنٹرول کے اقدامات شامل کریں.

  4. سرمایہ کے استعمال کو بڑھانے کے لئے اثاثوں کی اقسام میں تنوع پیدا کریں۔

نتیجہ

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


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-24 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//hk4jerry

strategy("Grid Bot Backtesting", overlay=false, pyramiding=3000, close_entries_rule="ANY", default_qty_type=strategy.cash, initial_capital=100.0, currency="USD", commission_type=strategy.commission.percent, commission_value=0.025)
i_autoBounds    = input(group="Grid Bounds", title="Use Auto Bounds?", defval=true, type=input.bool)                             // calculate upper and lower bound of the grid automatically? This will theorhetically be less profitable, but will certainly require less attention
i_boundSrc      = input(group="Grid Bounds", title="(Auto) Bound Source", defval="Hi & Low", options=["Hi & Low", "Average"])     // should bounds of the auto grid be calculated from recent High & Low, or from a Simple Moving Average
i_boundLookback = input(group="Grid Bounds", title="(Auto) Bound Lookback", defval=250, type=input.integer, maxval=500, minval=0) // when calculating auto grid bounds, how far back should we look for a High & Low, or what should the length be of our sma
i_boundDev      = input(group="Grid Bounds", title="(Auto) Bound Deviation", defval=0.10, type=input.float, maxval=1, minval=-1)  // if sourcing auto bounds from High & Low, this percentage will (positive) widen or (negative) narrow the bound limits. If sourcing from Average, this is the deviation (up and down) from the sma, and CANNOT be negative.
i_upperBound    = input(group="Grid Bounds", title="(Manual) Upper Boundry(상단 가격)", defval=0.285, type=input.float)                      // for manual grid bounds only. The upperbound price of your grid
i_lowerBound    = input(group="Grid Bounds", title="(Manual) Lower Boundry(하단 가격)", defval=0.225, type=input.float)                      // for manual grid bounds only. The lowerbound price of your grid.
i_gridQty       = input(group="Grid Lines",  title="Grid Line Quantity(그리드 수)", defval=30, maxval=999, minval=1, type=input.integer)       // how many grid lines are in your grid
initial_balance = input(group="Trading option", title="Initial balance(투자금액)", defval=100, step=0.01)


start_time = input(group="Trading option",defval=timestamp('15 March 2023 06:00'), title='Start Time', type = input.time)
end_time = input(group="Trading option",defval=timestamp('31 Dec 2035 20:00'), title='End Time', type = input.time)
isAfterStartDate = true

tradingtime= (timenow - start_time)/(86400000*30)
yeartime=tradingtime/12


f_getGridBounds(_bs, _bl, _bd, _up) =>
    if _bs == "Hi & Low"
        _up ? highest(close, _bl) * (1 + _bd) : lowest(close, _bl)  * (1 - _bd)
    else
        avg = sma(close, _bl)
        _up ? avg * (1 + _bd) : avg * (1 - _bd)

f_buildGrid(_lb, _gw, _gq) =>
    gridArr = array.new_float(0)
    for i=0 to _gq-1
        array.push(gridArr, _lb+(_gw*i))
    gridArr

f_getNearGridLines(_gridArr, _price) =>
    arr = array.new_int(3)
    for i = 0 to array.size(_gridArr)-1
        if array.get(_gridArr, i) > _price
            array.set(arr, 0, i == array.size(_gridArr)-1 ? i : i+1)
            array.set(arr, 1, i == 0 ? i : i-1)
            break
    arr

var upperBound      = i_autoBounds ? f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, true) : i_upperBound  // upperbound of our grid
var lowerBound      = i_autoBounds ? f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, false) : i_lowerBound // lowerbound of our grid
var gridWidth       = (upperBound - lowerBound)/(i_gridQty-1)                                                       // space between lines in our grid
var gridLineArr     = f_buildGrid(lowerBound, gridWidth, i_gridQty)                                                 // an array of prices that correspond to our grid lines
var orderArr        = array.new_bool(i_gridQty, false)                                                              // a boolean array that indicates if there is an open order corresponding to each grid line

var closeLineArr    = f_getNearGridLines(gridLineArr, close)                                                        // for plotting purposes - an array of 2 indices that correspond to grid lines near price
var nearTopGridLine = array.get(closeLineArr, 0)                                                                    // for plotting purposes - the index (in our grid line array) of the closest grid line above current price
var nearBotGridLine = array.get(closeLineArr, 1)                                                                    // for plotting purposes - the index (in our grid line array) of the closest grid line below current price
if isAfterStartDate
    for i = 0 to (array.size(gridLineArr) - 1)
        if close < array.get(gridLineArr, i) and not array.get(orderArr, i) and i < (array.size(gridLineArr) - 1)
            buyId = i
            array.set(orderArr, buyId, true)
            strategy.entry(id=tostring(buyId), long=true, qty=(initial_balance/(i_gridQty-1))/close, comment="#"+tostring(buyId))
        if close > array.get(gridLineArr, i) and i != 0
            if array.get(orderArr, i-1)
                sellId = i-1
                array.set(orderArr, sellId, false)
                strategy.close(id=tostring(sellId), comment="#"+tostring(sellId))

    if i_autoBounds
        upperBound  := f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, true)
        lowerBound  := f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, false)
        gridWidth   := (upperBound - lowerBound)/(i_gridQty-1)
        gridLineArr := f_buildGrid(lowerBound, gridWidth, i_gridQty)

    closeLineArr    := f_getNearGridLines(gridLineArr, close)
    nearTopGridLine := array.get(closeLineArr, 0)
    nearBotGridLine := array.get(closeLineArr, 1)






var table table = table.new(position.top_right,6,8, frame_color = color.rgb(255, 255, 255),frame_width = 2,border_width = 2, border_color=color.rgb(255, 255, 255))
        


//제목
table.cell(table,0,0,"상단 라인 :", bgcolor=color.new(color.black,0),text_color =color.white)    
table.cell(table,0,1,"하단 라인 :",bgcolor=color.new(color.black,0),text_color =color.white)
table.cell(table,0,2,"그리드 수 :",bgcolor=color.new(color.black,0),text_color =color.white)
table.cell(table,0,3,"투자금액 :",text_color =color.white,bgcolor=color.new(color.black,0))
table.cell(table,0,4,"그리드당 투자금액 :",text_color =color.white,bgcolor=color.new(color.black,0))
//수치
table.cell(table,1,0, tostring(upperBound, '###.#####')+ "  USDT", bgcolor=color.new(#5a637e, 0),text_color =color.white)    
table.cell(table,1,1, tostring(lowerBound, '###.#####')+ "  USDT", bgcolor=color.new(#5a637e, 0),text_color =color.white)
table.cell(table,1,2, tostring(i_gridQty, '###'), bgcolor=color.new(#5a637e, 0),text_color =color.white)
table.cell(table,1,3, tostring(initial_balance,'###.##')+ "  USDT", bgcolor=color.new(#5a637e, 0),text_color =color.white)
table.cell(table,1,4, tostring(initial_balance/i_gridQty,'###.##')+ "  USDT", bgcolor=color.new(#5a637e, 0),text_color =color.white)

//제목
table.cell(table,2,0,"현재 포지션 :",text_color =color.white,bgcolor=color.new(color.black,0))
table.cell(table,2,1,"현재 포지션 평단가 :",text_color =color.white,bgcolor=color.new(color.black,0))
table.cell(table,2,2,"현재 포지션 수익 :",bgcolor=color.new(color.black,0),text_color =color.white)
table.cell(table,2,3,"현재 포지션 수익 % :",bgcolor=color.new(color.black,0),text_color =color.white)
table.cell(table,2,4,"현재 포지션 수수료 :",text_color =color.white,bgcolor=color.new(color.black,0))

//수치
table.cell(table,3,0, tostring(strategy.position_size) +   syminfo.basecurrency + "\n"  + tostring(strategy.position_size*strategy.position_avg_price/1, '###.##') + "USDT" ,text_color =color.white,bgcolor=color.new(#5a637e, 0))
table.cell(table,3,1, text=strategy.position_size>0 ? tostring(strategy.position_avg_price,'###.####')+ "  USDT" : "NOT TRADING",text_color =color.white,bgcolor=color.new(#5a637e, 0))
table.cell(table,3,2, tostring(strategy.openprofit, '###.##')+ "  USDT",text_color =color.white,bgcolor=strategy.openprofit > 0 ? color.teal : color.maroon)
table.cell(table,3,3, tostring(strategy.openprofit/initial_balance*100, '###.##')+ "%",text_color =color.white,bgcolor=strategy.openprofit > 0 ? color.teal : color.maroon)
table.cell(table,3,4, "-" + tostring(strategy.position_avg_price*strategy.position_size*0.025/100,'###.##')+ "  USDT",text_color =color.white,bgcolor=color.new(#5a637e, 0))

//제목
table.cell(table,4,0,"그리드 수익 :",text_color =color.white,bgcolor=color.new(color.black,0))
table.cell(table,4,1,"그리드 수익률 :",text_color =color.white,bgcolor=color.new(color.black,0))
table.cell(table,4,2,"총 수익 :", bgcolor=color.new(color.black,0),text_color =color.white)    
table.cell(table,4,3,"총 수익률 :",bgcolor=color.new(color.black,0),text_color =color.white)
table.cell(table,4,4,"현재 자산 :",bgcolor=color.new(color.black,0),text_color =color.white)


//수치
table.cell(table,5,0, tostring(strategy.netprofit, '###.#####')+ "USDT", text_color =color.white,bgcolor=strategy.netprofit > 0 ? color.teal : color.maroon)
table.cell(table,5,1, tostring((strategy.netprofit)/initial_balance*100/tradingtime, '####.##') + "%",text_color =color.white,bgcolor=strategy.netprofit > 0 ? color.teal : color.maroon)
table.cell(table,5,2, tostring(strategy.netprofit+strategy.openprofit, '###.##') + "  USDT",text_color =color.white,bgcolor=strategy.netprofit+strategy.openprofit > 0 ? color.teal : color.maroon)
table.cell(table,5,3, tostring((strategy.netprofit+strategy.openprofit)/initial_balance*100, '####.##') + "%",text_color =color.white,bgcolor=strategy.netprofit+strategy.openprofit > 0 ? color.teal : color.maroon)
table.cell(table,5,4, tostring(initial_balance+strategy.netprofit+strategy.openprofit, '###.##')+ "  USDT", text_color =color.white,bgcolor=color.new(#3d4d7c, 0))





// plot(strategy.initial_capital+ strategy.netprofit+strategy.openprofit, "총 수익 USDT",color=color.rgb(81, 137, 128))
// plot(initial_balance, "투자금액",color=color.rgb(81, 137, 128))

مزید