Position Balancing Strategy
JavaScript strategy by 春哥.
JavaScriptOther
The original spec has no written description. Read the source below.
Parameters
| Name | Default | What it controls |
|---|---|---|
| TARGET_POSITION | 0.5 | Fixed position |
| ACT_DIFF | 0.1 | Position change |
Source JavaScript
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);
}
}
Published by 春哥 on the FMZ strategy square · last modified 2017-09-06. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Position-Balancing-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.