0bps

Strategy vault / Other

Martin Strategy V001

JavaScript strategy by superMan.

JavaScriptOther
Author
superMan
Complexity
Intermediate · 128 lines
Parameters
4

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

Parameters

NameDefaultWhat it controls
DF0,1,2,3,4,5,6,7The ratio of each decrease, converted from string to array.
JYD$$$__enc__$$$BTCTrading pairs you bought yourself
startNumtrueThe quantity bought at the very beginning, unitUSTD
minWin1.3Take profit percentage

Source JavaScript





var DFlist = DF.split(',').map(item => 0 - item)  // Array of declining ranges, initially replaced by a string because array cannot be set;
var JYDlist = JYD.split(',')                   // Selected trading pair.
var account = 0;                               // Account balance
var index = 0;                                 // Number of positions covered
var accountNum = 0                             // Total Position Volume
var countPrice = false;                        // Total Position Value
var YKBL = 0                                   // Profit and loss ratio
var copyStartNum = startNum;
var FrozenBalance = 0;                         // Current frozen balance on the platform


// Function method area
// Initialization function
function initFn(isFirst){  
    account = _C(exchange.GetAccount)
    if(isFirst){
        Log('robot starts to run')
    } else {
        Log('robot Repeating')
    }
}

// Loop Function
function onTick() {
    
}

// Loop to ensure the order has been bought
function onSureBuy(FrozenBalance){
    
}

// Buy Function 
function onBuy(){
    let account = _C(exchange.GetAccount)
    if ((account.Balance / currentPrice > copyStartNum && accountNum == 0) || DFlist[index] > YKBL){
        exchange.Buy(currentPrice, copyStartNum);
        Log(`Order bought, the price is${currentPrice},Quantity is${copyStartNum}`,'#ff0000')
        FrozenBalance = currentPrice * copyStartNum
        let i = 0
        while(FrozenBalance){
            FrozenBalance = _C(exchange.GetAccount).FrozenBalance;
            if(i >= 5 ){
                let order = _C(exchange.GetOrders) 
                order = JSON.stringify(order)
                for(let i = 0; i < order.legnth; i++){
                    exchange.CancelOrder(order[i].Id);
                }
                Log('Cancel Buy,The platform's frozen balance is:',FrozenBalance, '#00ff00')
                break
            } else if(FrozenBalance) {
                i++
            } else {
                break
            }
            Sleep(200)
        }
                
        
        if(i >= 5 && FrozenBalance){
            FrozenBalance = 0
            return false 
        } else {
          // Reaching this point indicates the buy order was successful
          Log(`Order bought successfully, price is${currentPrice},Quantity is${copyStartNum}`,'#00ff00')
          accountNum += copyStartNum
          countPrice += currentPrice * copyStartNum
          copyStartNum = copyStartNum*2
          index++  
        }
            
    } 
    if(account.Balance / currentPrice < copyStartNum){
        // Log("Account balance is insufficient")
    }
}

// Entry Function
function main() {
    initFn(true)
    var num = 1;
    while(1){
        
        account = _C(exchange.GetAccount)
        currentPrice = _C(exchange.GetTicker).Low;
        //Log(`Loop Number${num}times`,'account',account,'currentPrice',currentPrice,'countPrice',countPrice,'YKBL',YKBL,'copyStartNum',copyStartNum)
    
        num++
        // Get the current price change
        if(!countPrice){
            countPrice = currentPrice * copyStartNum
        } else {
            // Calculate the current profit and loss ratio
            YKBL = (countPrice * copyStartNum - currentPrice * copyStartNum) / countPrice * copyStartNum *100
        }
    
        Log(`Current loop number${num}Secondary profit and loss ratio is`,YKBL)
        if(YKBL > 1000 ){
            Log('Current Total Price',YKBL,'Current total coin holdings',copyStartNum,'Current Selling Price',currentPrice,'#ff0000')
        }
        
    
        // Sell when the take-profit percentage is reached
        if(YKBL > minWin){
            // var diffStock = _N(countPrice / accountNum);
        
            var diffStock = _N(account.Stocks, 4);
            exchange.Sell(currentPrice, diffStock)
            countPrice = 0
            accountNum = 0
            copyStartNum = startNum
            Log("Sell price is:",currentPrice,diffStock,account,'#00ff00')
            index = 0
        
        }
        
        // buy
        onBuy()
    
        Sleep(1000*60)
    }
    
}

Published by superMan on the FMZ strategy square · last modified 2021-06-10. 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/Martin-Strategy-V001.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