"그리드 전략"의 새로운 버전은 50줄의 코딩만 포함합니다.

저자:선함, 2018-08-28 14:18:15, 2019-12-03 17:27:50에서 업데이트되었습니다.

"그리드 전략"의 새로운 버전은 50줄의 코딩만 포함합니다.www.fmz.com

유명한 그리드 전략 (https://www.fmz.com/bbs-topic/2268)?

코드 자체보다 많은 코드 코멘트가 있는 것은 우리의 FMZ 플랫폼에서 전략을 작성하는 방법을 배우는 훌륭한 예입니다.

몇몇 친구들은 이 전략의 원래 버전이 너무 복잡하다고 생각했고, 더 짧은 버전이 있는지 궁금했습니다.

여기, 우리의 천재 프로그래머의 독점적인 코딩 기술 아래, 우리는 코딩의 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)
    }
}

더 많은

작은 꿈멋지네요