50 Line Multi Platform Hedging Strategy Teaching
Teaching Strategies
JavaScriptOther
Teaching Strategies
Parameters
| Name | Default | What it controls |
|---|---|---|
| _HedgePrice | 10 | Hedging the difference |
| _HedgeAmount | 0.02 | Hedging amount |
| _CurrencyPrecision | 2 | Order quantity accuracy |
| _BaseCurrencyPrecision | 2 | Order price accuracy |
Source JavaScript
var preSumBalance = 0
var initSumBalance = 0
function UpdateAccount(isFirst){
var msg = ""
var sumStocks = 0
var sumBalance = 0
for(var i = 0; i < exchanges.length; i++){
if(exchanges[i].needUpdate == true || isFirst == true){
exchanges[i].account = _C(exchanges[i].GetAccount)
exchanges[i].needUpdate = false
if(isFirst == true){
initSumBalance += (exchanges[i].account.Balance + exchanges[i].account.FrozenBalance)
exchanges[i].SetPrecision(_CurrencyPrecision, _BaseCurrencyPrecision)
}
}
sumStocks += (exchanges[i].account.Stocks + exchanges[i].account.FrozenStocks)
sumBalance += (exchanges[i].account.Balance + exchanges[i].account.FrozenBalance)
msg += exchanges[i].GetName() + "Currency:" + exchanges[i].account.Stocks + "Frozen Coins:" + exchanges[i].account.FrozenStocks + "Money:" + exchanges[i].account.Balance + "Frozen Money:" + exchanges[i].account.FrozenBalance + "\n"
}
LogStatus(_D(), "Total Coins:" + sumStocks, "Total Money:" + sumBalance, "\n", msg)
if(preSumBalance != sumBalance){
LogProfit(sumBalance - initSumBalance, preSumBalance = sumBalance)
}
}
function main(){
UpdateAccount(true)
while(1){
for(var i = 0; i < exchanges.length; i++){
for(var j = 0; j < exchanges.length; j++){
if(i == 0 && j == 0){
for(var m = 0; m < exchanges.length; m++){
exchanges[m].thread = exchanges[m].Go("GetTicker")
}
for(var n = 0; n < exchanges.length; n++){
exchanges[n].ticker = exchanges[n].thread.wait()
}
}
if(exchanges[i].GetName() != exchanges[j].GetName() && exchanges[i].ticker && exchanges[j].ticker && exchanges[i].ticker.Buy - exchanges[j].ticker.Sell > _HedgePrice){
if(exchanges[i].account.Stocks > _HedgeAmount && exchanges[j].account.Balance / ((exchanges[i].ticker.Buy + exchanges[j].ticker.Sell) / 2) > _HedgeAmount){
var sellId_I = exchanges[i].Sell((exchanges[i].ticker.Buy + exchanges[j].ticker.Sell) / 2, _HedgeAmount, exchanges[i].GetName())
var buyId_J = exchanges[j].Buy((exchanges[i].ticker.Buy + exchanges[j].ticker.Sell) / 2, _HedgeAmount, exchanges[i].GetName())
exchanges[i].needUpdate = exchanges[j].needUpdate = true
}
}
}
}
UpdateAccount(false)
Sleep(300) // Test
}
}Published by 发明者量化-小小梦 on the FMZ strategy square · last modified 2018-08-25. 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/50-Line-Multi-Platform-Hedging-Strategy-Teaching.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.