0bps

Strategy vault / Grid

grid

Python strategy by CYZWX.

PythonGrid
Author
CYZWX
Complexity
Starter · 36 lines
Parameters
0

The original spec has no written description. Read the source below.

Source Python

last_tick = []
line = []
grid_buy_list = []

def net(now_price):
    global line
    print(now_price)
    line = [now_price*(1+0.003*i) for i in range(-1000,1000)]
    Log(line)
    
def ontick():
    global last_tick
    global  line
    global grid_buy_list
    account = exchange.GetAccount()
    ticker = exchange.GetTicker()
    last_tick.append(ticker['Last'])
    if len(last_tick) == 1:return
    elif len(last_tick) == 100:del last_tick[0]
    for i in range(len(line)):
        if last_tick[-1] > line[i] and last_tick[-2] < line[i] and len(grid_buy_list)!= 0 and i > min(grid_buy_list)  and account['Stocks'] >= 0.001:
            exchange.Sell(last_tick[-1],0.01)
            del grid_buy_list[grid_buy_list.index(min(grid_buy_list))]
            Log(exchange.GetAccount())
        elif last_tick[-1] < line[i] and last_tick[-2] > line[i] and i not in grid_buy_list:
            exchange.Buy(last_tick[-1],0.01)
            grid_buy_list.append(i)
            Log(exchange.GetAccount())

def main():
    net(exchange.GetTicker()['Last'])
    Log(exchange.GetAccount())
    while(True):
        ontick()
        Sleep(1000)

Published by CYZWX on the FMZ strategy square · last modified 2021-06-17. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a grid bot with inventory caps and order deduplication from strategies/grid.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open