Skip to main content

Average Directional Index (ADX) and Ichimoku Kinko Hyo strategy

The strategy aims to implement a momentum trading approach that uses two technical indicators, the Average Directional Index (ADX) and Ichimoku Kinko Hyo, to identify entry and exit signals.

The Average Directional Index (ADX) is a trend indicator that measures the strength of a current trend, whether it's an uptrend or downtrend. The ADX ranges from 0 to 100, with values above 25 indicating a strong trend.

Ichimoku Kinko Hyo is a complex indicator that consists of several lines and can be used to identify trends, support and resistance levels, and momentum. This indicator is primarily used in trending markets.

The strategy involves monitoring these indicators and identifying signals that suggest a high probability of a trend continuation. For instance, when the ADX is above 25 and the Ichimoku Kinko Hyo shows a bullish trend, it could suggest a buy signal. Conversely, if the ADX is below 25 and the Ichimoku Kinko Hyo indicates a bearish trend, it could suggest a sell signal.

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