Buy then Sell (ping-pong strategy)


Created on: 2019-10-08 17:12:00 Modified on: 2021-10-09 09:51:14
Copy: 0 Number of hits: 33
avatar of Zero Zero
6
Follow
792
Followers
Strategy source code
/*backtest
start: 2019-09-08 00:00:00
end: 2019-10-07 00:00:00
period: 1h
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/

function main() {
    Log('robot starts to run')
    if(BUYPRICE >= SELLPRICE){
        throw 'check buy and sell price'
    }
    var account = _C(exchange.GetAccount)
    Log('account: ', account.Balance);
    if (account.Balance > BUYPRICE*BUYAMOUNT){
        exchange.Buy(BUYPRICE, BUYAMOUNT);
    } else {
        throw 'account balances is not enough'
    }
    while(true){
        var nowAccount = _C(exchange.GetAccount)
        var diffStock = _N(nowAccount.Stocks - account.Stocks, 4);
        if (diffStock > 0.01 * BUYAMOUNT){
            exchange.Sell(SELLPRICE, diffStock)
        }
        Sleep(5000)
    }
}