"گرڈ حکمت عملی" کا نیا ورژن صرف 50 لائنز کوڈنگ پر مشتمل ہے!

مصنف:نیکی, تخلیق: 2018-08-28 14:18:15, تازہ کاری: 2019-12-03 17:27:50

"گرڈ حکمت عملی" کا نیا ورژن صرف 50 لائنز کوڈنگ پر مشتمل ہے!www.fmz.com

کیا آپ کو اب بھی مشہور یاد ہے grid strategy (https://www.fmz.com/bbs-topic/2268)?

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

کچھ دوستوں نے محسوس کیا کہ اس حکمت عملی کا اصل ورژن بہت پیچیدہ ہے، وہ سوچتے ہیں کہ کیا اس کا کوئی مختصر ورژن ہے؟

یہاں یہ آتا ہے، ہمارے ذہین پروگرامر کی خصوصی کوڈنگ کی مہارت کے تحت، ہم اسے دوبارہ لکھتے ہیں (اب بھی جاوا اسکرپٹ کا استعمال کرتے ہوئے) صرف 50 لائنوں کی کوڈنگ کا استعمال کرتے ہوئے۔ اصل میں 700 سے زیادہ کوڈنگ لائنیں ہیں۔

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

یہاں اصل 700+ کوڈ لائنز ہیں:https://www.fmz.com/bbs-topic/2268

var _StopLoss = 0
var _StopWin = 0
var _Grid = []

function UpdateGrid(nowBidsPrice, nowAsksPrice, direction){    // up 1, down -1
    if(_Grid.length == 0 || (direction == 1 && nowBidsPrice - _Grid[_Grid.length - 1].price > _GridPointDis) || 
        (direction == -1 && _Grid[_Grid.length - 1].price - nowAsksPrice > _GridPointDis)){

        var nowPrice = direction == 1 ? nowBidsPrice : nowAsksPrice
        _Grid.push({
            price: _Grid.length == 0 ? nowPrice : _Grid[_Grid.length - 1].price + _GridPointDis * direction,
            hold : {price: 0, amount: 0}, 
            coverPrice : _Grid.length == 0 ? nowPrice - direction * _GridCovDis : _Grid[_Grid.length - 1].price + _GridPointDis * direction - direction * _GridCovDis
        })

        var tradeInfo = direction == 1 ? $.Sell(_GridPointAmount) : $.Buy(_GridPointAmount)
        _Grid[_Grid.length - 1].hold.price = tradeInfo.price
        _Grid[_Grid.length - 1].hold.amount = tradeInfo.amount
        $.PlotFlag(new Date().getTime(), JSON.stringify(tradeInfo), "O")
    }
    if(_Grid.length > 0 && 
        ((direction == 1 && nowAsksPrice < _Grid[_Grid.length - 1].coverPrice) || (direction == -1 && nowBidsPrice > _Grid[_Grid.length - 1].coverPrice))){
        
        var coverInfo = direction == 1 ? $.Buy(_Grid[_Grid.length - 1].hold.amount) : $.Sell(_Grid[_Grid.length - 1].hold.amount)
        _Grid.pop()
        $.PlotFlag(new Date().getTime(), JSON.stringify(coverInfo), "C")
        _StopWin++
    } else if(_Grid.length > _GridNum){
        var coverfirstInfo = direction == 1 ? $.Buy(_Grid[0].hold.amount) : $.Sell(_Grid[0].hold.amount)
        _Grid.shift()
        $.PlotFlag(new Date().getTime(), JSON.stringify(coverfirstInfo), "C")
        _StopLoss++
    }

}

function main(){
    while(1){
        var ticker = _C(exchange.GetTicker)
        var records = _C(exchange.GetRecords)
        $.PlotRecords(records, "kline")
        UpdateGrid(ticker.Buy, ticker.Sell, direction)       
        var msg = ""
        for(var i = 0; i < _Grid.length; i++){
            msg += JSON.stringify(_Grid[i]) + "\n"
        }
        LogStatus(_D(), "_StopWin:", _StopWin, "_StopLoss:", _StopLoss, _C(exchange.GetAccount), "\n", "_Grid.length:", _Grid.length, "_GridNum:", _GridNum, "\n", msg)
        Sleep(500)
    }
}

مزید

چھوٹا سا خواببہت اچھا!