পয়েন্ট ইন পয়েন্ট আউট পয়েন্ট বিক্রয়

লেখক:শূন্য, তারিখঃ ২০১৪-০৬-২০ 12:48:35
ট্যাগঃবাণিজ্যিকভাবে সহায়ক

আপনি কয়েক পয়েন্ট এন্ট্রি, কয়েক পয়েন্ট ছাড়তে পারেন, সিস্টেম বাধ্যতামূলক বিল্ডিং, বাধ্যতামূলক স্থিতিস্থাপক, নিরবচ্ছিন্নভাবে চেষ্টা করা হবে বিল্ডিং এবং স্থিতিস্থাপক, ডিফল্ট 0 পয়েন্ট এন্ট্রি কিনুন, 8 পয়েন্ট প্রস্থান বিক্রয়, সেট করুন প্রবেশদ্বার 23, প্রস্থান 8 মানে সন্ধ্যায় 23 এন্ট্রি, পরের দিন 8 পয়েন্ট ছাড়ুন, যদি সেট 8.5 হয় 8:30 মানে, সেট 8.6 হয় 836 পয়েন্ট, ছোট সংখ্যা পয়েন্ট গুণ 6 হয় মিনিট সংখ্যা, স্টপ লস নিষিদ্ধ করা যেতে পারে যদি স্লিপ খোলা স্টপ লস, স্টপ লস পয়েন্ট যদি 0.1 হয় তবে 0.1% পড়ে তবে জোর করে বিক্রি করা হবে। স্টপ লস সর্বোচ্চ রেফারেন্স মূল্য, যার অর্থ হল 1000 এন্ট্রি, 2000 এ জিতল, যদি 2000 হ্রাস পায় তবে 0.1% হ্রাস পায়, যদি সর্বোচ্চ রেফারেন্স মূল্য না হয় তবে এটি 0.1% হ্রাস পায়।



// 0 means wait buy, 1 means wait sell
var state = 0;
var lastBuyAmount = 0;
var lastHighPrice = 0;
var lastBuyPrice = 0;
var initBalance = 0;


function cancelAllOrders() {
    var orders = null;
    while (!(orders = exchange.GetOrders())) {
        Sleep(2000);
    }
    
    if (orders.length > 0) {
        for (var j = 0; j < orders.length; j++) {
            exchange.CancelOrder(orders[j].Id);
            if (j < (orders.length-1)) {
                Sleep(2000);
            }
        }
    }
}

function MustBuy() {
    var buyAmount = 0;
    var initAccount = _C(exchange.GetAccount);
    if (initBalance == 0) {
        initBalance = initAccount.Balance;
        if (initAccount.Balance < UsedFund) {
            throw "账户余额不足,少于设定值 " + UsedFund;
        }
    }

    
    UsedFund = Math.min(initAccount.Balance, UsedFund);
    
    var spend = 0;
    var buyAmount = 0;
    
    while (spend < UsedFund) {
        var ticker = _C(exchange.GetTicker);
        var amount = _N((UsedFund - spend) / (ticker.Last + SlidePrice));
        if (amount < 0.001) {
            break;
        }
        exchange.Buy(ticker.Last + SlidePrice, amount);
        Sleep(RetryInterval * 1000);
        cancelAllOrders();
        var account = _C(exchange.GetAccount);
        spend = initAccount.Balance - account.Balance;
        buyAmount = account.Stocks - initAccount.Stocks;
    }
    
    if (buyAmount > 0) {
        lastBuyPrice = lastHighPrice = (spend / buyAmount);
        Log("平均买入价", _N(lastHighPrice));
    }
    
    return buyAmount;
}

function MustSell(sellAmount) {
    var remaind = sellAmount;
    var initAccount = _C(exchange.GetAccount);
    while (remaind >= 0.001) {
        var ticker = _C(exchange.GetTicker);
        exchange.Sell(ticker.Last - SlidePrice, remaind);
        Sleep(RetryInterval * 1000);
        cancelAllOrders();
        var newAccount = _C(exchange.GetAccount);
        remaind -= (initAccount.Stocks - newAccount.Stocks);
        initAccount = newAccount;
    }
    LogProfit(initAccount.Balance - initBalance);
}

function onTick() {
    var now = new Date();
    var h = now.getHours() + (now.getMinutes() / 60);
    if (state == 0 && (
        (EnterHour < LeaveHour && h >= EnterHour && h < LeaveHour) || 
        (EnterHour > LeaveHour && (h >= EnterHour || h < LeaveHour))
        )) {
        lastBuyAmount = MustBuy();
        state = 1;
    } else if (state == 1 && (
        (EnterHour < LeaveHour && (h >= LeaveHour || h < EnterHour)) || 
        (EnterHour > LeaveHour && (h >= LeaveHour && h < EnterHour))
        )) {
        if (lastBuyAmount > 0) {
            MustSell(lastBuyAmount);
            lastBuyAmount = 0;
        }
        state = 0;
    } else if ((EnableStopProfit || EnableStopLoss) && lastBuyAmount > 0) {
        var ticker = _C(exchange.GetTicker);
        if (RefHigh) {
            lastHighPrice = Math.max(lastHighPrice, ticker.Last);
        }
        var ratioStopLoss = Math.abs((lastHighPrice - ticker.Last) / lastHighPrice);
        var ratioStopProfit = Math.abs((lastBuyPrice - ticker.Last) / lastBuyPrice);
        var shouldSell = false;
        
        if (EnableStopLoss && ticker.Last < lastHighPrice && (ratioStopLoss >= (StopLoss/100))) {
            // Stop loss
            Log("开始止损, 当前跌价点数:", _N(ratioStopLoss*100), "当前价格", ticker.Last, "对比价格", _N(lastHighPrice));
            shouldSell = true;
            
        } else if (EnableStopProfit && ticker.Last > lastBuyPrice && (ratioStopProfit >= (StopProfit/100))) {
            // Stop loss
            Log("开始止赢, 当前涨价点数:", _N(ratioStopProfit*100), "当前价格", ticker.Last, "对比价格", _N(lastBuyPrice));
            shouldSell = true;
        }
        
        if (shouldSell) {
            MustSell(lastBuyAmount);
            lastBuyAmount = 0;
        }
    }
}

function main() {
    if (EnterHour == LeaveHour) {
        throw "进场时间跟离场时间不能相等!";
    }
    Log(_C(exchange.GetAccount));
    while(true) {
        onTick();
        Sleep(60000);
    }
} 



সম্পর্কিত

আরো