ابتدائیوں کے لئے کریپٹوکرنسی مقداری تجارت - آپ کو کریپٹوکرنسی مقداری کے قریب لے جا رہا ہے (5)

مصنف:لیدیہ, تخلیق: 2022-08-03 16:08:50, تازہ کاری: 2023-09-21 21:07:02

img

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

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

    پہلی تفصیل جس پر ہمیں غور کرنا ہے وہ ہے لامحدود گرڈ کا ڈیزائن۔ کیا آپ کو یاد ہے کہ ہم نے ایک فنکشن ڈیزائن کیا ہےcreateNetپچھلے مضمون میں مل کر ابتدائی گرڈ ڈیٹا ڈھانچہ پیدا کرنے کے لئے؟ یہ فنکشن گرڈ ڈیٹا ڈھانچہ تیار کرتا ہے جس میں گرڈ لائنوں کی ایک محدود تعداد ہوتی ہے۔ تو کیا ہوگا اگر حکمت عملی چل رہی ہے تو قیمت اس گرڈ ڈیٹا ڈھانچے کی حدود سے باہر جاتی ہے (اوپر گرڈ لائن سے آگے جہاں قیمت سب سے زیادہ ہے ، اور نیچے گرڈ لائن جہاں قیمت سب سے کم ہے) ؟ تو ہمیں پہلے گرڈ ڈیٹا ڈھانچے میں ایک توسیع میکانزم شامل کرنے کی ضرورت ہے۔

    آئیے اسٹریٹجی مین فنکشن لکھنا شروع کرتے ہیں، جو کہ وہ کوڈ ہے جہاں اسٹریٹجی کا عملدرآمد شروع ہوتا ہے۔

    var diff = 50                                 // Global variables and grid spacing can be designed as parameters for easy explanation. We write this parameter into the code.
    function main() {
        // After the real bot starts running, execute the strategy code from here
        var ticker = _C(exchange.GetTicker)       // To get the latest market data ticker, please refer to the FMZ API documentation for the structure of the ticker data: https://www.fmz.com/api#ticker
        var net = createNet(ticker.Last, diff)    // The function we designed in the previous article to construct the grid data structure initially, here we construct a grid data structure net
    
        while (true) {                            // Then the program logic enters this while infinite loop, and the strategy execution will continue to execute the code within the {} symbol here.
            ticker = _C(exchange.GetTicker)       // The first line of the infinite loop code section, get the latest market data and update it to the ticker variable
            // Check the grid range
            while (ticker.Last >= net[net.length - 1].price) {
                net.push({
                    buy : false,
                    sell : false,
                    price : net[net.length - 1].price + diff,
                })
            }
            while (ticker.Last <= net[0].price) {
                var price = net[0].price - diff
                if (price <= 0) {
                    break
                }
                net.unshift({
                    buy : false,
                    sell : false,
                    price : price,
                })
            }
            
            // There are other codes...
        }
    }
    

    گرڈ ڈیٹا ڈھانچے کو توسیع پذیر بنانے کے لئے یہ کوڈ ہے (اوپر والے کوڈ سے اقتباس):

          // Check the grid range
          while (ticker.Last >= net[net.length - 1].price) {   // If the price exceeds the grid line of the highest price of the grid
              net.push({                                       // Just add a new grid line after the grid line with the highest price of the grid
                  buy : false,                                 // Initialize sell marker
                  sell : false,                                // Initialize buy marker
                  price : net[net.length - 1].price + diff,    // dd a grid spacing to the previous highest price
              })
          }
          while (ticker.Last <= net[0].price) {                // If the price is lower than the grid line of the lowest price of the grid
              var price = net[0].price - diff                  // Different from adding upwards, it should be noted that the price of adding new grid lines downwards cannot be less than or equal to 0, so it is necessary to judge here
              if (price <= 0) {                                // Less than or equal to 0 will not be added, jump out of this loop
                  break
              }
              net.unshift({                                    // Add a new grid line just before the grid line with the lowest price of the grid
                  buy : false,
                  sell : false,
                  price : price,
              })
          }
    

    اگلا مرحلہ یہ ہے کہ تجارتی ٹرگر کو خاص طور پر کیسے لاگو کیا جائے۔

    var diff = 50
    var amount = 0.002       // Add a global variable, which can also be designed as a parameter. Of course, for the sake of simplicity, we also write it in the strategy code.
                             // This parameter controls the trade volume each time a trade is triggered on the grid line
    function main() {
        var ticker = _C(exchange.GetTicker)
        var net = createNet(ticker.Last, diff)
        var preTicker = ticker       // Before the main loop (fixed loop) starts, set a variable to record the last market data
        while (true) {
            ticker = _C(exchange.GetTicker)
            // Check the grid range
            while (ticker.Last >= net[net.length - 1].price) {
                net.push({
                    buy : false,
                    sell : false,
                    price : net[net.length - 1].price + diff,
                })
            }
            while (ticker.Last <= net[0].price) {
                var price = net[0].price - diff
                if (price <= 0) {
                    break
                }
                net.unshift({
                    buy : false,
                    sell : false,
                    price : price,
                })
            }  
    
            // Retrieve grid
            for (var i = 0 ; i < net.length ; i++) {     // Iterate over all grid lines in the grid data structure
                var p = net[i]
                if (preTicker.Last < p.price && ticker.Last > p.price) {         // Above the SMA, sell, the current node has already traded, regardless of SELL BUY, it will no longer be traded
                    if (i != 0) {
                        var downP = net[i - 1]
                        if (downP.buy) {
                            exchange.Sell(-1, amount, ticker)
                            downP.buy = false 
                            p.sell = false 
                            continue
                        }
                    }
                    if (!p.sell && !p.buy) {
                        exchange.Sell(-1, amount, ticker)
                        p.sell = true
                    }
                } else if (preTicker.Last > p.price && ticker.Last < p.price) {  // Below the SMA, buy
                    if (i != net.length - 1) {
                        var upP = net[i + 1]
                        if (upP.sell) {
                            exchange.Buy(-1, amount * ticker.Last, ticker)
                            upP.sell = false 
                            p.buy = false 
                            continue
                        }
                    }
                    if (!p.buy && !p.sell) {
                        exchange.Buy(-1, amount * ticker.Last, ticker)
                        p.buy = true 
                    } 
                }
            }
            preTicker = ticker    // Record the current market data in preTicker, and in the next cycle, use it as a comparison between the "previous" market data and the latest one to judge whether to be above the SMA or below the SMA.
            Sleep(500)
        }
    }  
    

    یہ دیکھا جا سکتا ہے کہ:

    • گرڈ لائنوں کے اوپر پار کرنے کی شرط:preTicker.Last < p.price && ticker.Last > p.price
    • گرڈ لائنوں کے نیچے پار کرنے کی شرط:preTicker.Last > p.price && ticker.Last < p.price

    پچھلی پوسٹ میں ہم نے یہی کہا تھا:

img

یہ فیصلہ کرنا کہ ایس ایم اے سے اوپر یا نیچے ہونا صرف پہلا قدم ہے کہ آیا آرڈر دیا جاسکتا ہے ، اور یہ بھی ضروری ہے کہ گرڈ لائن ڈیٹا میں نشانات کا فیصلہ کیا جائے۔

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

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

پروسیسنگ منطق SMA سے نیچے ہونے کے لئے ایک ہی ہے (بائیں ابتدائیوں کے لئے یہاں سوچنے کے لئے).

مکمل حکمت عملی بیک ٹسٹنگ

backtesting کے دوران کچھ اعداد و شمار کو دیکھنے کے لئے، ایک تقریبshowTblاعداد و شمار کو ظاہر کرنے کے لئے لکھا جاتا ہے.

function showTbl(arr) {
    var tbl = {
        type : "table", 
        title : "grid",
        cols : ["grid information"],
        rows : []
    }
    var arrReverse = arr.slice(0).reverse()
    _.each(arrReverse, function(ele) {
        var color = ""
        if (ele.buy) {
            color = "#FF0000"
        } else if (ele.sell) {
            color = "#00FF00"
        }
        tbl.rows.push([JSON.stringify(ele) + color])
    })
    LogStatus(_D(), "\n`" + JSON.stringify(tbl) + "`", "\n account Information:", exchange.GetAccount())
}

مکمل حکمت عملی کا کوڈ:

/*backtest
start: 2021-04-01 22:00:00
end: 2021-05-22 00:00:00
period: 1d
basePeriod: 1m
exchanges: [{"eid":"OKEX","currency":"ETH_USDT","balance":100000}]
*/

var diff = 50
var amount = 0.002
function createNet(begin, diff) {
    var oneSideNums = 10
    var up = []
    var down = []
    for (var i = 0 ; i < oneSideNums ; i++) {
        var upObj = {
            buy : false,
            sell : false, 
            price : begin + diff / 2 + i * diff,
        }
        up.push(upObj)

        var j = (oneSideNums - 1) - i
        var downObj = {
            buy : false,
            sell : false,
            price : begin - diff / 2 - j * diff,
        }
        if (downObj.price <= 0) {  // The price cannot be less than or equal to 0
            continue
        }
        down.push(downObj)
    }

    return down.concat(up)
}

function showTbl(arr) {
    var tbl = {
        type : "table", 
        title : "grid",
        cols : ["grid Information"],
        rows : []
    }
    var arrReverse = arr.slice(0).reverse()
    _.each(arrReverse, function(ele) {
        var color = ""
        if (ele.buy) {
            color = "#FF0000"
        } else if (ele.sell) {
            color = "#00FF00"
        }
        tbl.rows.push([JSON.stringify(ele) + color])
    })
    LogStatus(_D(), "\n`" + JSON.stringify(tbl) + "`", "\n account Information:", exchange.GetAccount())
}

function main() {
    var ticker = _C(exchange.GetTicker)
    var net = createNet(ticker.Last, diff)
    var preTicker = ticker 
    while (true) {
        ticker = _C(exchange.GetTicker)
        // Check the grid range
        while (ticker.Last >= net[net.length - 1].price) {
            net.push({
                buy : false,
                sell : false,
                price : net[net.length - 1].price + diff,
            })
        }
        while (ticker.Last <= net[0].price) {
            var price = net[0].price - diff
            if (price <= 0) {
                break
            }
            net.unshift({
                buy : false,
                sell : false,
                price : price,
            })
        }

        // Retrieve grid
        for (var i = 0 ; i < net.length ; i++) {
            var p = net[i]
            if (preTicker.Last < p.price && ticker.Last > p.price) {         // Being above the SMA, sell, the current node has already traded, regardless of SELL BUY, it will no longer be traded
                if (i != 0) {
                    var downP = net[i - 1]
                    if (downP.buy) {
                        exchange.Sell(-1, amount, ticker)
                        downP.buy = false 
                        p.sell = false 
                        continue
                    }
                }
                if (!p.sell && !p.buy) {
                    exchange.Sell(-1, amount, ticker)
                    p.sell = true
                }
            } else if (preTicker.Last > p.price && ticker.Last < p.price) {  // Being below the SMA, buy
                if (i != net.length - 1) {
                    var upP = net[i + 1]
                    if (upP.sell) {
                        exchange.Buy(-1, amount * ticker.Last, ticker)
                        upP.sell = false 
                        p.buy = false 
                        continue
                    }
                }
                if (!p.buy && !p.sell) {
                    exchange.Buy(-1, amount * ticker.Last, ticker)
                    p.buy = true 
                } 
            }
        }

        showTbl(net)
        preTicker = ticker 
        Sleep(500)
    }
}

حکمت عملی بیک ٹسٹنگ:

img

img

img

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


متعلقہ

مزید