0bps

Strategy vault / Other

Python Simple Testing Strategy

You need to download the latest host. Each host machine needs to have python installed. (Linux comes with it and does not need to be installed.)

Author
Zero
Complexity
Starter · 59 lines
Parameters
4

You need to download the latest host. Each host machine needs to have python installed. (Linux comes with it and does not need to be installed.)

Parameters

NameDefaultWhat it controls
a1.2number
bHellohellostr
ctruebool
d0select: abc | def | xxx

Source Python

import time
import talib

def main():
    LogProfitReset()
    LogReset()
    Log("init OK", time.strftime('%Y-%m-%d %X', time.localtime(time.time())))
    Log(a,b,c,d)
    _G("ok", 123)
    Log(GetPid(), _G(), _G("ok"), _G("dummy"))
    Sleep(1000)
    _G(None)
    Log(_G("ok"))

    LogStatus("Time", time.time())
    EnableLog(True)
    SetErrorFilter("net")
    Log(GetLastError())
    Log(GetCommand())
    ticker = exchange.GetTicker()
    Log('ticker buy', ticker.Buy, ticker['Buy']);
    
    r = _C(exchange.GetRecords)
    Log(TA.ATR(r))
    Log(TA.EMA(r, 10))
    # test talib
    Log(str(talib.EMA(r.Close, 10)))

    for e in exchanges:
        Log(e.GetName(), e.GetRate(), e.GetCurrency())
        Log(e.GetAccount())
        Log(_C(e.GetOrders))
        Log(e.GetOrder(10))
        Log(e.CancelOrder(10000))
 
        Log(e.GetUSDCNY())
        #Log(e.GetPosition())
        #Log(e.SetContractType("next_week"))
        Log(e.GetTicker())
        Log('Asks:', len(e.GetDepth().Asks))
        #Log(e.SetMarginLevel(10))
        #Log(e.SetDirection("buy"))
        #Log(e.SetContractType("quarter"))
        #Log(e.GetRecords(PERIOD_M30)[0])
        Log(e.GetRecords()[0])
    x = Chart({
        'title' : { 'text' : 'test chart'},
        'xAxis': { 'type': 'datetime'},
        'series' : [{'name' : 'Buy', 'data' : []}, {'name' : 'Sell', 'data' : []}]
        })
    x.reset()
    Log("Strategy will each10Updates once every secondticker");
    for i in range(100):
        ts = int(time.time() * 1000)
        ticker = _C(exchange.GetTicker)
        x.add(0, [ts, ticker.Buy])
        x.add(1, [ts, ticker.Sell])
        LogStatus(ticker)
        Sleep(10000)

Published by Zero on the FMZ strategy square · last modified 2018-06-05. 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 production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Python-Simple-Testing-Strategy.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