নতুনদের জন্য ক্রিপ্টোকারেন্সি পরিমাণগত ট্রেডিং - আপনাকে ক্রিপ্টোকারেন্সি পরিমাণগতের আরও কাছাকাছি নিয়ে যাওয়া (5)

লেখক:লিডিয়া, সৃষ্টিঃ ২০২২-০৮-০৩ ১৬ঃ০৮ঃ৫০, আপডেটঃ ২০২৩-০৯-২১ ২১ঃ০৭ঃ০২

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 এর নিচে থাকার জন্য একই (বাম জন্য নতুনদের এখানে চিন্তা করার জন্য) ।

সম্পূর্ণ কৌশল ব্যাকটেস্টিং

ব্যাকটেস্টিং চলাকালীন কিছু তথ্য দেখতে, একটি ফাংশন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

সুতরাং আমরা গ্রিড কৌশলটির বৈশিষ্ট্য দেখতে পাচ্ছি, যখন একটি ট্রেন্ডিং মার্কেট থাকে, তখন একটি বড় ভাসমান ক্ষতি হবে, এবং মুনাফা একটি অস্থির বাজারে পুনরুদ্ধার হবে। সুতরাং, গ্রিড কৌশল ঝুঁকিমুক্ত নয়। স্পট কৌশল এখনও স্কেট করা যেতে পারে, যখন ফিউচার চুক্তির গ্রিড কৌশল আরও ঝুঁকিপূর্ণ এবং গ্রিড পরামিতিগুলির জন্য সংরক্ষণশীলভাবে সেট করা দরকার।


সম্পর্কিত

আরো