Martingale Test
JavaScript strategy by Zer3192.
JavaScriptMartingale
The original spec has no written description. Read the source below.
Source JavaScript
// Martingale strategy
var baseAmount = 0.001; // Initial order quantity
var martingaleFactor = 1.01; // Scaling Factor
var maxOrders = 100; // Maximum number of orders
var currentOrders = 0; // Current number of orders
var currentAmount = baseAmount; // Current order quantity
function main() {
while (true) {
var ticker = exchange.GetTicker();
var price = ticker.Last;
var buyPrice = price - 1000; // Set the buy price to current price minus1
var sellPrice = price + 500; // Set the sell price to current price plus1
if (currentOrders < maxOrders) {
// Place Order
if (currentOrders % 2 == 0) {
// Place an even number of orders to buy
var orderId = exchange.Buy(buyPrice, currentAmount);
if (orderId) {
currentOrders++;
currentAmount *= martingaleFactor;
}
} else {
// Place an odd number of orders to sell
var orderId = exchange.Sell(sellPrice, currentAmount);
if (orderId) {
currentOrders++;
currentAmount *= martingaleFactor;
}
}
} else {
// Reached the maximum number of order attempts, exit the loop
break;
}
Sleep(1000); // Wait 1 second
}
}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/Martingale-Test.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
- Random Number Martingale StrategyJavaScript · Martingale
- Simple Martingale BTC Contract Modify Add Position MultiplierJavaScript · Martingale · 1d