Random Number Martingale Strategy
JavaScript strategy by Zer3192.
JavaScriptMartingale
The original spec has no written description. Read the source below.
Source JavaScript
// Random Number Martingale Strategy
// Before each order, determine the order direction and quantity based on a random number
// Set initial capital and order quantity
var initCapital = 10000; // Initial capital
var initAmount = 1; // Initial order quantity
// Set random number range and order ratio
var minRand = 0; // Minimum random number
var maxRand = 100; // Maximum random number
var buyRatio = 0.5; // Buy Ratio
var sellRatio = 0.5; // Sell Ratio
// Define order function
function placeOrder(direction, amount) {
if (direction == 'buy') {
exchange.Buy(-1,amount);
} else if (direction == 'sell') {
exchange.Sell(-1,amount);
}
}
// Define main function
function main() {
var capital = initCapital; // Current funds
var amount = initAmount; // Current order quantity
var lastDirection = ''; // Last order direction
while (true) {
// Generate random number
var rand = Math.floor(Math.random() * (maxRand - minRand + 1)) + minRand;
// Determine the order direction and quantity based on a random number
var direction = '';
if (rand <= buyRatio * maxRand) {
direction = 'buy';
} else if (rand >= (1 - sellRatio) * maxRand) {
direction = 'sell';
}
if (direction) {
// Reset the order quantity if the direction changes
if (direction != lastDirection) {
amount = initAmount;
}
// Place Order
placeOrder(direction, amount);
// Update funds and order quantity
var orderPrice = exchange.GetTicker().Last;
var orderAmount = amount * orderPrice;
if (direction == 'buy') {
capital -= orderAmount;
} else if (direction == 'sell') {
capital += orderAmount;
}
amount *= 2;
// Print Log
Log('Order Direction:', direction, 'Order quantity:', amount, 'Current funds:', capital);
// Update the direction of the last order
lastDirection = direction;
}
Sleep(1000);
}
}Published by Zer3192 on the FMZ strategy square · last modified 2023-06-09. 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 production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Random-Number-Martingale-Strategy.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
- CTA Strategy Commodity Futures Simple MartingaleJavaScript · Martingale · 1d
- Fibonacci Sequence StrategyJavaScript · Martingale · 1d
- MartinGale Strategy1JavaScript · Martingale
- Simple Martingale Long and Short Position Increase Ratio ModificationJavaScript · Martingale · 1d
- Simple Martingale BTC Contract Modify Add Position MultiplierJavaScript · Martingale · 1d
- Binance Multi Trading Pairs Spot Used for Market LiquidationJavaScript · Martingale