Grid Pending Order Plus Martin Multiple Increase
JavaScript strategy by Zer3192.
JavaScriptGrid
The original spec has no written description. Read the source below.
Parameters
| Name | Default | What it controls |
|---|---|---|
| baseSpacing | 10 | Add Position Distance |
| baseAmount | 0.01 | Base position order quantity |
| ratio | 1.1 | Position growth coefficient |
| interval | 500 | Polling Interval |
| symbol | swap | Contract Code |
| profitTarget | 10 | Target profit spread |
| MarginLevel | 50 | Leverage settings |
Source JavaScript
/*backtest
start: 2017-06-26 00:00:00
end: 2022-02-16 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
var MarginLevel=20
exchange.SetMarginLevel(MarginLevel)
function cancelAll() {
while (true) {
var orders = _C(exchange.GetOrders)
if (orders.length == 0) {
break
}
for (var i = 0 ; i < orders.length ; i++) {
exchange.CancelOrder(orders[i].Id, orders[i])
Sleep(interval)
}
}
}
function getLong(arr, kind) {
var ret = null
for (var i = 0 ; i < arr.length ; i++) {
if (arr[i].Type == (kind == "pos" ? PD_LONG : ORDER_TYPE_BUY)) {
ret = arr[i]
}
}
return ret
}
function pendingBidOrders(firstPrice) {
var index = 0
var bet=ratio
var n = baseAmount
while (true) {
var pos = _C(exchange.GetPosition)
var price = firstPrice - index * baseSpacing
n=n*ratio
index++
exchange.SetDirection("buy")
exchange.Buy(price, amount=n)
if (pos.length != 0) {
var longPos = getLong(pos, "pos")
if (longPos) {
exchange.SetDirection("closebuy")
exchange.Sell(longPos.Price + profitTarget, longPos.Amount)
}
}
while (true) {
Sleep(interval)
if (!getLong(_C(exchange.GetOrders), "orders")) {
cancelAll()
break
}
if (!getLong(_C(exchange.GetPosition), "pos")) {
cancelAll()
return
}
}
}
}
function main() {
exchange.SetContractType(symbol)
while (true) {
pendingBidOrders(_C(exchange.GetTicker).Last)
}
}Published by Zer3192 on the FMZ strategy square · last modified 2022-04-11. 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 grid bot with inventory caps and order deduplication from strategies/Grid-Pending-Order-Plus-Martin-Multiple-Increase.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.
Related specs
- Bybit Inverse Contract Dynamic Grid Special GridJavaScript · Grid
- Single Commodity Small Shop Strategy V20 Annualized 130JavaScript · Grid · 1d
- Two Way Contract Grid Trading V102JavaScript · Grid · 1m
- Mesh Deformation Strategy for Single Sided MeshJavaScript · Grid
- Mesh Deformation Strategy for Single Sided Mesh NotesJavaScript · Grid · 1d
- U Based Grid Amplitude FilteringJavaScript · Grid