ADX and Ichimoku Trading Strategy
This spot strategy uses the 9/26/52 Ichimoku cloud to check trend direction and the 14-period Average Directional Index (ADX) to check trend strength.
- Buy when the close is above both cloud spans, the conversion line is above the base line, and ADX is at least 20.
- Sell when the close falls below the Ichimoku base line.
Follow the backtest setup to run this example on a spot pair.
// Read completed candles. The newest candle can still be forming.
const candleTime = Number(gb.data.candlesTimestamp.at(-2));
if (!(candleTime > 0) || !(gb.data.ask > 0) || !(gb.data.bid > 0)) return;
const store = gb.data.pairLedger.customStratStore ??= {};
if (store.adxichimokuOrderCandle === candleTime || gb.data.openOrders.length > 0) return;
const highs = gb.data.candlesHigh.slice(0, -1);
const lows = gb.data.candlesLow.slice(0, -1);
const closes = gb.data.candlesClose.slice(0, -1);
if (closes.length < 79 || highs.length !== closes.length || lows.length !== closes.length) return;
// Use the same synchronous Tulind callback as the editor's spot starter.
function indicator(name, inputs, options) {
let series = [];
gb.method.tulind.indicators[name].indicator(inputs, options, (error, results) => {
if (error) throw error;
series = results;
});
return series;
}
const [adx] = indicator("adx", [highs, lows], [14]);
function midpoint(period, offset = 0) {
const end = highs.length - offset;
return (Math.max(...highs.slice(end - period, end)) +
Math.min(...lows.slice(end - period, end))) / 2;
}
const conversion = midpoint(9);
const base = midpoint(26);
// The cloud at this candle was projected from 26 candles earlier.
const spanA = (midpoint(9, 26) + midpoint(26, 26)) / 2;
const spanB = midpoint(52, 26);
const close = closes.at(-1);
const buySignal = close > Math.max(spanA, spanB) && conversion > base && adx.at(-1) >= 20;
const sellSignal = close < base;
// Spot market order amounts are in the asset being traded (BTC in USDT-BTC).
if (gb.data.gotBag && sellSignal && gb.data.quoteBalance > 0) {
store.adxichimokuOrderCandle = candleTime;
await gb.method.sellMarket(gb.data.quoteBalance, gb.data.pairName, gb.data.exchangeName);
} else if (!gb.data.gotBag && buySignal) {
const budget = Number(gb.data.pairLedger.whatstrat.TRADING_LIMIT);
if (!Number.isFinite(budget) || budget <= 0 || gb.data.baseBalance <= budget) return;
const amount = budget / gb.data.ask;
store.adxichimokuOrderCandle = candleTime;
await gb.method.buyMarket(amount, gb.data.pairName, gb.data.exchangeName);
}

This Binance spot backtest filled 45 buys and 44 sells on 1-hour USDT-BTC candles from January through March 2024, using a 1,000 USDT starting balance, a 100 USDT buy budget and 0.1% trading fees.