My-1-Wertdurchschnittliche Anlagestrategie

Schriftsteller:Lizza, bitte., Datum: 2015-12-20 23:05:41
Tags:Handelsunterstützt

Das ist ein echtes Video.https://www.fmz.com/m/robot/26018Diese Strategie ist geeignet für langfristig optimistische Bitcoin-Brainparasiten, die mit einer Wertdurchschnittsstrategie für das Positionieren arbeiten, um Marktfluktuationen wirksam zu widerstehen.

Die grundlegende Idee ist, zuerst darüber nachzudenken, wie viel Geld man jeden Monat investieren möchte (Strategievariable: MoneyEveryMonth), und dann zu entscheiden, wie lange man einmal handeln soll, wobei der Abstand zwischen den Transaktionen nicht weniger als 5 Minuten empfohlen wird (Strategieparameter: InvestInternal).

Hier ist ein Beispiel, um die strategische Idee und das Kauf- und Verkaufszeitpunkt zu beschreiben: Angenommen, man will monatlich 72.000 RMB an Bitcoin kaufen (einfache Berechnung) und es einmal pro Stunde verkauft, dann ist der Plan 24*30 = 720 Transaktionen pro Monat, wobei der geplante Kapitalwert für jede Investition 72.000/720 = 100 RMB (Variable A) ist.

Wenn Sie eine Währung, die Sie in Ihrem Konto haben, in Ihrem Konto haben, dann können Sie die Währung, die Sie in Ihrem Konto haben, in Ihrem Konto haben. 1 400 0 0 CE=0 AB-F=100 G/C=0,25
2 200 100 0.25 2000.25=50 1002-50=150 0.75 3 1000 250 1 1000 1003-1000=-700 -0.7 4 500 -550 0.3 150 1004-150=250 0.5

Das Endergebnis ist, dass man 300 Dollar investiert und 0,8 Bitcoins (im Wert von 400 US-Dollar) mit einem Durchschnittspreis von 375 US-Dollar kauft.

Erläuterung: Das Programm prüft jedes Mal die Differenz zwischen dem Geld und den Bitcoins im Konto und dem Startzeitpunkt, um die Anzahl der Käufe zu berechnen, die jedes Mal benötigt werden, also benutze keinen anderen Roboter, um ein Konto zu veröffentlichen, und mach keine Kauf- und Verkaufsaktionen manuell. Wenn alle Auf- und Verwertung im Handel erfolgt, sollte dies im interaktiven Teil des Programms ausgefüllt werden, sonst wird der Rechner einen Fehler machen.


var initAccount;
var startTime; //unix timestamp
var pause = false; //pause execution of strategy or continue
var moneyDeposit = 0; // positive means deposit, negative means withdraw
var sotckDeposit = 0; // positive means deposit, negative means withdraw

function AdjustFloat(v) {
    return Math.floor(v * 1000)/1000;
}

function GetAccount() {
    var account = null;
    while (!(account = exchange.GetAccount())) {
        Log('Get Account Error');
        Sleep(ErrorInterval);
    }
    return account;
}

function GetCurrentPrice() {
    var ticker = null;
    while (!(ticker = exchange.GetTicker())) {
        Log('Get Ticker Error');
        Sleep(ErrorInterval);
    }
    return AdjustFloat(ticker.Last);
}

function GetOrders(){
    var orders = null;
    while (!(orders = exchange.GetOrders())) {
        Log('Get Orders Error');
        Sleep(ErrorInterval);
    }
    return orders;
}

function CancelPendingOrders() {
    while(true){
        var orders = GetOrders();
        if (orders.length === 0) {
            return;
        }

        for (var i = 0; i < orders.length; i++) {
            exchange.CancelOrder(orders[i].Id);
            if (i < (orders.length-1)) {
                Sleep(ErrorInterval);
            }
        }
    }
}

function ProcessCommand() {
    var command = GetCommand();

    if (command !== null) {
        Log('command:', command);
        if (command === 'pause') {
            pause = true;
        }
        if (command === 'Continue') {
            pause = false;
        }
        if(command.indexOf('MoneyChange:') === 0){
            moneyDeposit += parseFloat(command.replace("MoneyChange:", ""));
            Log('Deposit Money:', moneyDeposit);
        }
        if(command.indexOf('StockChange:') === 0){
            stockDeposit += parseFloat(command.replace("StockChange:", ""));
            Log('Deposit Stock:',stockDeposit);
        }
    }
}

function CaculateMoneyToInvest(currentPrice,investCount)
{
    var moneyEveryInvest = MoneyEveryMonth * InvestInternal / (30 * 24 * 60);
    var totalStockInvested = 0.0;
    var totalMoneyInvested = 0.0;
    var totalValueInvested = 0.0;
    var moneyToInvestThisTime = 0.0;

    CancelPendingOrders();
    var accountNow = GetAccount();
    totalMoneyInvested = initAccount.Balance + initAccount.FrozenBalance + moneyDeposit - accountNow.Balance - accountNow.FrozenBalance;
    totalStockInvested = accountNow.Stocks + accountNow.FrozenStocks - initAccount.Stocks - initAccount.FrozenStocks - stockDeposit;

    Log('Total Money Invested:',totalMoneyInvested);
    Log('Total Stock Invested:',totalStockInvested);

    totalValueInvested = AdjustFloat(totalStockInvested * currentPrice);
    Log('Total Value Invested:',totalValueInvested);

    var averagePrice = 0;
    if(totalStockInvested !== 0){
        averagePrice = AdjustFloat(totalMoneyInvested / totalStockInvested);
    }

    moneyToInvestThisTime = AdjustFloat(moneyEveryInvest * investCount - totalValueInvested);
    Log('Money to Invest This Time:', moneyToInvestThisTime);

    var profit = totalValueInvested - totalMoneyInvested;
    var totalValueNow = (accountNow.Stocks + accountNow.FrozenStocks) * currentPrice + accountNow.Balance + accountNow.FrozenBalance;
    LogStatus('Account Value Now:' + totalValueNow + '\n' + 'Count:',investCount,'  Money:', totalMoneyInvested, 'Stock:', totalStockInvested, 'Average:', averagePrice,'Profit:',profit);
    LogProfit(profit);

    return moneyToInvestThisTime;
}

function onTick(investCount) {
    var currentPrice = GetCurrentPrice();
    Log('Current Price', currentPrice);

    var moneyToInvestThisTime = CaculateMoneyToInvest(currentPrice,investCount);
    var stockToInvestThisTime = 0;
    if(moneyToInvestThisTime > 0){ //Buy
        stockToInvestThisTime = AdjustFloat(moneyToInvestThisTime / (currentPrice + SlidePrice));
    }else{ //Sell
        stockToInvestThisTime = AdjustFloat(moneyToInvestThisTime / (currentPrice - SlidePrice));
    }

    var minPrice = exchange.GetMinPrice();
    if(Math.abs(moneyToInvestThisTime) < minPrice){
        Log('Invest Less Than MinPrice:', minPrice);
        return;
    }

    var minStock = exchange.GetMinStock();
    if(Math.abs(stockToInvestThisTime) < minStock){
        Log('Invest Less Than MinStock:',minStock);
        return;
    }

    var account = GetAccount();
    if(stockToInvestThisTime > 0){ //Buy
        if(account.Balance < moneyToInvestThisTime){
            Log('Money not Enough.#ff0000@');
            return;
        }
    }else{ //Sell
        if(account.Stocks < Math.abs(stockToInvestThisTime)){
            Log('Stock not Enough.#ff0000@');
            return;
        }
    }

    var orderID = -1;
    if(stockToInvestThisTime > 0){ //Buy
        Log('Buy Stock:',stockToInvestThisTime);
        orderID = exchange.Buy(currentPrice + SlidePrice,stockToInvestThisTime);
    }

    if(stockToInvestThisTime < 0){ //Sell
        Log('Sell Stock:',Math.abs(stockToInvestThisTime));
        orderID = exchange.Sell(currentPrice - SlidePrice,Math.abs(stockToInvestThisTime));
    }


}

function main() {
    //exchange.IO("websocket");
    initAccount = _G('InitAccount');
    if(initAccount === null){
        initAccount = GetAccount();
        _G('InitAccount',initAccount);
        Log('Set Init account.');
        Log(exchange.GetName(), exchange.GetCurrency(), initAccount);
    }
    else{
        Log('Read Init Account:', initAccount);
    }

    startTime = _G('StartTime');
    if(startTime === null){
        startTime = new Date().getTime();
        _G('StartTime',startTime);
        Log('Set Start Time:', startTime);
    }else{
        Log('Read Start Time',new Date().setTime(startTime));
    }

    var investCount = _G('InvestCount' );
    if(investCount === null){
        investCount = 1;
        Log('Set Invest Starting from Count 1.');
    }
    else{
        Log('Invest Continuing from:', investCount);
    }

    moneyDeposit = _G('MoneyDeposit');
    if(moneyDeposit === null){
        moneyDeposit = 0;
        Log('Set Money Deposit 0.');
    }
    else{
        Log('Read Money Deposit:', moneyDeposit);
    }

    stockDeposit = _G('StockDeposit');
    if(stockDeposit === null){
        stockDeposit = 0;
        Log('Set Stock Deposit 0.');
    }
    else{
        Log('Read Stock Deposit:', stockDeposit);
    }

    while (true) {
        ProcessCommand();
        if (!pause) {
            Log('=================================================');
            Log('Invest Count', investCount);
            onTick(investCount);
            investCount += 1;
            _G('InvestCount',investCount);
        }
        Sleep(InvestInternal * 1000 * 60);
    }
}

function onexit(){
    _G('MoneyDeposit',moneyDeposit);
    _G('StockDeposit', stockDeposit);

    Log('Robot Stopped!#ff0000@');
}

Verwandt

Mehr

Faulheit.Sind Sie immer noch am Laufen?

ZuanxuanDanke fürs Teilen. Gut, ich hoffe, es geht weiter.

Der Mann von NingDanke fürs Teilen.

Lizza, bitte.Wer kann mir helfen, den Code zu lesen?

NullDank für das Teilen, das ist wie eine langfristige Investition, die mit Zeit gewogen wird, eine sehr zuverlässige Investitionsstrategie!