dYdX কৌশল নকশা উদাহরণ

লেখক:লিডিয়া, সৃষ্টিঃ ২০২২-১১-০৭ 10:59:29, আপডেটঃ ২০২৩-০৯-১৫ 21:03:43

img

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

স্টোকাস্টিক ট্রেডিং কৌশল নকশা

আসুন একটি মস্তিষ্ক ঝড় আছে! এটা এলোমেলো সূচক এবং দাম সঙ্গে এলোমেলো অর্ডার স্থাপন একটি কৌশল ডিজাইন করার পরিকল্পনা করা হয়। অর্ডার স্থাপন লং বা শর্ট যাচ্ছে ছাড়া আর কিছুই নয়, শুধু সম্ভাব্যতা উপর বাজি। তারপর আমরা র্যান্ডম সংখ্যা 1 ~ 100 ব্যবহার করা হবে দীর্ঘ বা শর্ট যেতে কিনা তা নির্ধারণ করতে।

লং যাওয়ার শর্তঃ র্যান্ডম নম্বর 1 ~ 50। শর্ট হওয়ার শর্তঃ র্যান্ডম নম্বর 51~100।

সুতরাং লং এবং শর্ট উভয়ই ৫০ টি সংখ্যা। এরপরে, আসুন কীভাবে অবস্থানটি বন্ধ করা যায় তা নিয়ে চিন্তা করি, যেহেতু এটি একটি বাজি, তাই জয়ের বা হারানোর জন্য অবশ্যই একটি মানদণ্ড থাকতে হবে। আমরা লেনদেনে স্থির স্টপ লাভ এবং ক্ষতির জন্য একটি মানদণ্ড সেট করি। জয়ের জন্য স্টপ লাভ, হারানোর জন্য স্টপ ক্ষতি। স্টপ লাভ এবং ক্ষতির পরিমাণ হিসাবে, এটি আসলে লাভ এবং ক্ষতির অনুপাতের প্রভাব, ওহ হ্যাঁ! এটি জয়ের হারকেও প্রভাবিত করে! (এই কৌশল নকশা কার্যকর? এটি ইতিবাচক গাণিতিক প্রত্যাশা হিসাবে গ্যারান্টিযুক্ত হতে পারে? প্রথমে এটি করুন! (তারপরে, এটি কেবল শেখার জন্য, গবেষণা!

ট্রেডিং খরচ মুক্ত নয়, আমাদের স্টোকাস্টিক ট্রেডিং জয়ের হারকে ৫০% এর নিচে নিয়ে যাওয়ার জন্য পর্যাপ্ত স্লিপ, ফি ইত্যাদি রয়েছে। তাহলে কীভাবে এটিকে ধারাবাহিকভাবে ডিজাইন করা যায়? পজিশন বাড়ানোর জন্য মাল্টিপ্লাইকার ডিজাইন করলে কেমন হয়? যেহেতু এটি একটি বাজি, তাই একটানা 8 ~ 10 বার এলোমেলো ট্রেডের জন্য হারানোর সম্ভাবনা কম হওয়া উচিত। সুতরাং প্রথম লেনদেনটি একটি ছোট পরিমাণ অর্ডার দেওয়ার জন্য ডিজাইন করা হয়েছিল, যতটা সম্ভব ছোট। তারপর যদি আমি হেরে যাই, আমি অর্ডার পরিমাণ বাড়াব এবং এলোমেলোভাবে অর্ডার দেওয়া চালিয়ে যাব।

ঠিক আছে, কৌশলটি সহজভাবে ডিজাইন করা হয়েছে।

সোর্স কোড ডিজাইন করা হয়েছেঃ

var openPrice = 0 
var ratio = 1
var totalEq = null 
var nowEq = null 

function cancelAll() {
    while (1) {
        var orders = _C(exchange.GetOrders)
        if (orders.length == 0) {
            break
        }
        for (var i = 0 ; i < orders.length ; i++) {
            exchange.CancelOrder(orders[i].Id, orders[i])
            Sleep(500)
        }
        Sleep(500)
    }
}

function main() {
    if (isReset) {
        _G(null)
        LogReset(1)
        LogProfitReset()
        LogVacuum()
        Log("reset all data", "#FF0000")
    }

    exchange.SetContractType(ct)

    var initPos = _C(exchange.GetPosition)
    if (initPos.length != 0) {
        throw "Strategy starts with a position!"
    }
    
    exchange.SetPrecision(pricePrecision, amountPrecision)
    Log("set the pricePrecision", pricePrecision, amountPrecision)
    
    if (!IsVirtual()) {
        var recoverTotalEq = _G("totalEq")
        if (!recoverTotalEq) {
            var currTotalEq = _C(exchange.GetAccount).Balance   // equity
            if (currTotalEq) {
                totalEq = currTotalEq
                _G("totalEq", currTotalEq)
            } else {
                throw "failed to obtain initial interest"
            }
        } else {
            totalEq = recoverTotalEq
        }
    } else {
        totalEq = _C(exchange.GetAccount).Balance
    }
    
    while (1) {
        if (openPrice == 0) {
            // Update account information and calculate profits
            var nowAcc = _C(exchange.GetAccount)
            nowEq = IsVirtual() ? nowAcc.Balance : nowAcc.Balance  // equity
            LogProfit(nowEq - totalEq, nowAcc)
            
            var direction = Math.floor((Math.random()*100)+1)   // 1~50 , 51~100
            var depth = _C(exchange.GetDepth)
            if (depth.Asks.length <= 2 || depth.Bids.length <= 2) {
                Sleep(1000)
                continue 
            }
            if (direction > 50) {
                // long
                openPrice = depth.Bids[1].Price
                exchange.SetDirection("buy")
                exchange.Buy(Math.abs(openPrice) + slidePrice, amount * ratio)
            } else {
                // short
                openPrice = -depth.Asks[1].Price
                exchange.SetDirection("sell")
                exchange.Sell(Math.abs(openPrice) - slidePrice, amount * ratio)
            }       
            Log("place", direction > 50 ? "buying order" : "selling order", ", price:", Math.abs(openPrice))
            continue
        }

        var orders = _C(exchange.GetOrders)
        if (orders.length == 0) {
            var pos = _C(exchange.GetPosition)
            if (pos.length == 0) {
                openPrice = 0
                continue
            }
            
            // Test for closing the position
            while (1) {
                var depth = _C(exchange.GetDepth)
                if (depth.Asks.length <= 2 || depth.Bids.length <= 2) {
                    Sleep(1000)
                    continue 
                }
                var stopLossPrice = openPrice > 0 ? Math.abs(openPrice) - stopLoss : Math.abs(openPrice) + stopLoss 
                var stopProfitPrice = openPrice > 0 ? Math.abs(openPrice) + stopProfit : Math.abs(openPrice) - stopProfit
                var winOrLoss = 0 // 1 win , -1 loss 
                
                // drawing the line
                $.PlotLine("bid", depth.Bids[0].Price)
                $.PlotLine("ask", depth.Asks[0].Price)
                
                // stop loss
                if (openPrice > 0 && depth.Bids[0].Price < stopLossPrice) {
                    exchange.SetDirection("closebuy")
                    exchange.Sell(depth.Bids[0].Price - slidePrice, pos[0].Amount)
                    winOrLoss = -1
                } else if (openPrice < 0 && depth.Asks[0].Price > stopLossPrice) {
                    exchange.SetDirection("closesell")
                    exchange.Buy(depth.Asks[0].Price + slidePrice, pos[0].Amount)
                    winOrLoss = -1
                }
                
                // stop profit
                if (openPrice > 0 && depth.Bids[0].Price > stopProfitPrice) {
                    exchange.SetDirection("closebuy")
                    exchange.Sell(depth.Bids[0].Price - slidePrice, pos[0].Amount)  
                    winOrLoss = 1
                } else if (openPrice < 0 && depth.Asks[0].Price < stopProfitPrice) {
                    exchange.SetDirection("closesell")
                    exchange.Buy(depth.Asks[0].Price + slidePrice, pos[0].Amount)
                    winOrLoss = 1
                }
                
                // Test the pending orders
                Sleep(2000)
                var orders = _C(exchange.GetOrders)                
                if (orders.length == 0) {
                    pos = _C(exchange.GetPosition)
                    if (pos.length == 0) {
                        if (winOrLoss == -1) {
                            ratio++
                        } else if (winOrLoss == 1) {
                            ratio = 1
                        }
                        break
                    }                    
                } else {
                    // cancel pending orders
                    cancelAll()
                    Sleep(2000)
                    pos = _C(exchange.GetPosition)
                    // update the position after cancellation, and check it again
                    if (pos.length == 0) {
                        if (winOrLoss == -1) {
                            ratio++
                        } else if (winOrLoss == 1) {
                            ratio = 1
                        }
                        break
                    }    
                }
                
                var tbl = {
                    "type" : "table", 
                    "title" : "info", 
                    "cols" : ["totalEq", "nowEq", "openPrice", "bid1Price", "ask1Price", "ratio", "pos.length"], 
                    "rows" : [], 
                }
                tbl.rows.push([totalEq, nowEq, Math.abs(openPrice), depth.Bids[0].Price, depth.Asks[0].Price, ratio, pos.length])
                tbl.rows.push(["pos", "type", "amount", "price", "--", "--", "--"])
                for (var j = 0 ; j < pos.length ; j++) {
                    tbl.rows.push([j, pos[j].Type, pos[j].Amount, pos[j].Price, "--", "--", "--"])
                }
                LogStatus(_D(), "\n", "`" + JSON.stringify(tbl) + "`")
            }
        } else {
            // cancel the pending orders
            // reset openPrice
            cancelAll()
            openPrice = 0
        }
        Sleep(1000)
    }
}

কৌশলগত পরামিতি:

img

ওহ হ্যাঁ! কৌশলটির একটি নাম দরকার, আসুন এটিকে "আকার অনুমান করুন (ডিওয়াইডিএক্স সংস্করণ) " বলি।

ব্যাকটেস্ট

ব্যাকটেস্টিং শুধুমাত্র রেফারেন্সের জন্য, >_

img

img

img

img

ব্যাকটেস্ট শেষ, কোন বাগ নেই।

এই কৌশল শুধুমাত্র শেখার এবং রেফারেন্সের জন্য ব্যবহার করা হয়, বাস্তব বট এটি ব্যবহার করবেন না!


সম্পর্কিত

আরো