50 लाइनों की जाल रणनीति (शिक्षण)

लेखक:छोटे सपने, दिनांक: 2018-08-24 16:32:24
टैगःअध्ययनग्रिड


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)
    }
}

संबंधित

अधिक

326538268Bitmex ने कोई अनुबंध सेट नहीं किया है

वूफूहाओ100डब्ल्यूक्या भगवान के पास कोई खाली पायथन संस्करण है?

अफ़ानक्सिंगझोउप्रश्नः वायदा सॉफ्टवेयर समतल होने पर, एक खोलने की स्थिति का चयन करना है, उस स्थिति को समतल करना है। मुझे लगता है कि कोड में समतल होने पर, संचालन और खोलने की स्थिति समान है, केवल एक नई स्थिति खोलना है जो पहले के विपरीत है। इसलिए तुलना उलझन में है, उम्मीद है कि छोटे सपने के मालिक के पास जवाब जानने का समय होगा:)

छोटे सपनेयह रणनीति एक नकदी है, और BITMEX एक वायदा एक्सचेंज है।

छोटे सपनेअच्छा है।

अफ़ानक्सिंगझोउठीक है, मैं भविष्य के बारे में और देखूंगा:)

छोटे सपनेओह, यह रणनीति केवल एक मौद्रिक संस्करण है, और भविष्य के संस्करण में बदलने में रुचि रखते हैं। वर्तमान वस्तु केवल खरीद और बिक्री है; खरीदा या अधिक है, बेचा या अधिक है (यदि पहले एक संबंधित खरीद ऑपरेशन था) या खुला है।