Skip to main content

Average Directional Index (ADX) and Ichimoku Kinko Hyo strategy

This strategy uses the Average Directional Index (ADX) and Ichimoku Kinko Hyo to identify momentum-based entry and exit signals.

ADX measures trend strength on a 0–100 scale, with values above 25 indicating a strong trend. Ichimoku Kinko Hyo uses multiple lines to show trend direction, support/resistance, and momentum, and is most useful in trending markets.

Signals are based on trend continuation. For example, a buy signal can occur when ADX is above 25 and Ichimoku indicates a bullish trend. A sell signal can occur when ADX is below 25 and Ichimoku indicates a bearish trend.

tip

This example strategy is machine generated using Gunbot AI. Review its behavior carefully in a simulated bot instance before using parts of this code in production.

// initialize customStratStore within pairLedger object
gb.data.pairLedger.customStratStore = gb.data.pairLedger.customStratStore || {};

// forced wait time reduces risk of double orders
function checkTime() {
return !gb.data.pairLedger.customStratStore.timeCheck || typeof gb.data.pairLedger.customStratStore.timeCheck !== "number"
? (gb.data.pairLedger.customStratStore.timeCheck = Date.now(), false)
: (Date.now() - gb.data.pairLedger.customStratStore.timeCheck > 8000);
}
const enoughTimePassed = checkTime();

// set timestamp for checkTime in next round
const setTimestamp = () => gb.data.pairLedger.customStratStore.timeCheck = Date.now();

// calculate ADX
const adx = gb.data.adx;
console.log("ADX:", adx);

// calculate Ichimoku Kinko Hyo
const tenkan = gb.data.tenkan;
const kijun = gb.data.kijun;
const senkouSpanA = gb.data.senkouSpanA;
const senkouSpanB = gb.data.senkouSpanB;
const chikou = gb.data.chikou;
console.log("Tenkan:", tenkan);
console.log("Kijun:", kijun);
console.log("Senkou Span A:", senkouSpanA);
console.log("Senkou Span B:", senkouSpanB);
console.log("Chikou:", chikou);

if (enoughTimePassed) {
// calculate trading conditions
const adxCondition = adx > 25;
const ichimokuCondition = tenkan > kijun && gb.data.candlesClose[gb.data.candlesClose.length-2] < senkouSpanA && gb.data.candlesClose[gb.data.candlesClose.length-2] < senkouSpanB && gb.data.candlesClose[gb.data.candlesClose.length-1] > senkouSpanA && gb.data.candlesClose[gb.data.candlesClose.length-1] > senkouSpanB;
const sellCondition = chikou > gb.data.candlesClose[gb.data.candlesClose.length-1];

// fire orders when conditions are met
if (adxCondition && ichimokuCondition && !gb.data.gotBag) {
const buyAmount = parseFloat(gb.data.pairLedger.whatstrat.TRADING_LIMIT) / gb.data.bid;
gb.method.buyMarket(buyAmount, gb.data.pairName);
setTimestamp();
} else if (sellCondition && gb.data.gotBag) {
gb.method.sellMarket(gb.data.quoteBalance, gb.data.pairName);
setTimestamp();
}
}

// Code is machine generated, review it and run in simulator mode first