- Square
- 仓位均衡策略
仓位均衡策略
Author:
春哥, Date: 2017-09-06 21:28:03
Tags:
Balance
function main() {
while (true) {
Sleep(300000);
var account = $.GetAccount();
var ticker = exchange.GetTicker();
var stockValue = account.Stocks * ticker.Last;
var totalValue = stockValue + account.Balance;
var position = stockValue / totalValue;
var trade_amount = 0;
if ( position > TARGET_POSITION + ACT_DIFF ) {
trade_amount = (position - TARGET_POSITION) * totalValue / ticker.Buy;
$.Sell(trade_amount);
} else if ( position < TARGET_POSITION - ACT_DIFF ) {
trade_amount = (TARGET_POSITION - position) * totalValue / ticker.Sell;
$.Buy(trade_amount);
} else {
Sleep(60000);
continue;
}
$.CancelPendingOrders();
account = $.GetAccount();
stockValue = account.Stocks * ticker.Last;
LogProfit(account.Balance + stockValue);
}
}
Related
More