Ladder Order Trigger Price Can Be Set
Ladder orders can be bought or sold. The program places a specified number of buy orders or sell orders according to the order interval. If it is a buy order, the first order will be the highest priced order, and the…
Ladder orders can be bought or sold. The program places a specified number of buy orders or sell orders according to the order interval. If it is a buy order, the first order will be the highest priced order, and the prices of subsequent orders will decrease in sequence. The first sell order will be the cheapest sell order, and the prices of subsequent orders will increase in sequence.
Parameters
| Name | Default | What it controls |
|---|---|---|
| OpType | 0 | Place a buy order: Buy | Sell |
| StartPrice | 20 | Initial order price |
| PriceDiff | 0.2 | Order Interval |
| OrderNum | 10 | Number of Orders |
| Amount | 0.8 | Number of coins per order |
| EnableTrigger | false | Use trigger conditions |
| TriggerPrice | 18 | Trigger price |
Source JavaScript
function adjustFloat(v) {
return Math.floor(parseFloat(v.toFixed(10))*1000)/1000;
}
function GetAccount(e) {
var account;
while (!(account = exchange.GetAccount())) {
Sleep(Interval);
}
return account;
}
function GetTicker() {
var ticker;
while (!(ticker = exchange.GetTicker())) {
Sleep(1000);
}
return ticker;
}
function main() {
var ticker = GetTicker();
var InitPrice = ticker.Last;
if (EnableTrigger) {
Log('Current Price: ', InitPrice, InitPrice > TriggerPrice ? 'Price drops below' : 'Price rises above', TriggerPrice, 'triggers ladder order placement');
while (true) {
if (InitPrice > TriggerPrice && ticker.Last < TriggerPrice) {
Log('Current Price', ticker.Last, 'Price drops below ', TriggerPrice, 'element, Start ordering');
break;
} else if (InitPrice < TriggerPrice && ticker.Last > TriggerPrice) {
Log('Current Price', ticker.Last, 'Price rises above ', TriggerPrice, 'element, Start ordering');
break;
}
ticker = GetTicker();
Sleep(1000);
}
}
var account = GetAccount();
var needMoney = 0;
var needStocks = 0;
for (var i = 0; i < OrderNum; i++) {
needMoney += (StartPrice - (i * PriceDiff)) * Amount;
needStocks += Amount;
}
if (OpType == 0) {
if (needMoney > account.Balance) {
throw "Not enough money to place an order";
}
for (var i = 0; i < OrderNum; i++) {
exchange.Buy(adjustFloat(StartPrice - (i * PriceDiff)), Amount);
}
} else {
if (needStocks > account.Stocks) {
throw "Not enough coins to place an order";
}
for (var i = 0; i < OrderNum; i++) {
exchange.Sell(adjustFloat(StartPrice + (i * PriceDiff)), Amount);
}
}
Log("All orders completed");
}Published by Zero on the FMZ strategy square · last modified 2015-04-22. 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/Ladder-Order-Trigger-Price-Can-Be-Set.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.