0bps

Strategy vault / Tools & templates

Buy then Sell ping pong strategy

As the title suggests, you can set a buy price, and after successful purchase, automatically set a sell price to sell, The plug-in can be started with one click on the trading terminal, free of charge, and convenient…

Author
小草
Complexity
Starter · 29 lines
Parameters
4

As the title suggests, you can set a buy price, and after successful purchase, automatically set a sell price to sell, The plug-in can be started with one click on the trading terminal, free of charge, and convenient for manual trading. Detailed introduction:https://www.fmz.com/digest-topic/5051

Parameters

NameDefaultWhat it controls
BUYPRICE6200buy price
BUYAMOUNT0.1buy amount
SELLPRICE6400sell price after buying
Intervel6sleep time (second)

Source JavaScript

function CancelPendingOrders() {
    var orders = _C(exchange.GetOrders);
    for (var j = 0; j < orders.length; j++) {
        exchange.CancelOrder(orders[j].Id, orders[j]);
    }
}
function main() {
    Log('robot starts to run')
    if(BUYPRICE >= SELLPRICE){
        throw 'check buy and sell price'
    }
    CancelPendingOrders()
    var account = _C(exchange.GetAccount)
    var init_account = account
    Log('account: ', account.Balance);
    if(account.Balance > BUYPRICE*BUYAMOUNT){
        exchange.Buy(BUYPRICE, BUYAMOUNT);
    }else{
        throw 'account balances is not enough'
    }
    while(true){
        account = _C(exchange.GetAccount)
        if(account.Stocks >= init_account.Stocks + 0.01){
            exchange.Sell(SELLPRICE, account.Stocks - init_account.Stocks)
        }
        Sleep(Intervel*1000)
    }
}

Published by 小草 on the FMZ strategy square · last modified 2020-03-24. 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 tested, production-ready module from strategies/Buy-then-Sell-ping-pong-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