Skip to main content

McClellan Summation Index & Aroon indicator

The strategy involves using two technical indicators, the McClellan Summation Index and the Aroon indicator, to generate entry and exit signals for trading. The strategy requires calculating these indicators without using built-in methods and logging every indicator and trading conditions.

The McClellan Summation Index is a breadth indicator that measures the number of advancing and declining stocks in an index. It is derived from the McClellan Oscillator, which is calculated by subtracting the 39-day exponential moving average (EMA) of advancing issues from the 39-day EMA of declining issues. The McClellan Summation Index is then calculated by adding the McClellan Oscillator values over a longer period of time, typically 19 days.

The Aroon indicator is a trend indicator that consists of two lines, the Aroon-Up line and the Aroon-Down line. It is used to identify the strength of a trend and potential trend reversals. The Aroon-Up line measures the number of days since the highest price over a given period, while the Aroon-Down line measures the number of days since the lowest price over the same period. The Aroon indicator is calculated as a percentage of the time elapsed since the highest high or lowest low over a given period.

By using these two indicators together, the strategy aims to identify potential buying and selling opportunities. The McClellan Summation Index can provide a broader market perspective, while the Aroon indicator can help identify individual markets with strong trends.

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 McClellan Summation Index
const msi = () => {
const ema19 = gb.data.ema1(gb.data.candlesClose, 19);
const ema39 = gb.data.ema1(gb.data.candlesClose, 39);
const msi = [];
for (let i = 0; i < ema19.length; i++) {
const value = ema19[i] - ema39[i];
msi.push(value);
}
return msi;
}

// calculate Aroon Up and Down
const aroon = () => {
const aroonUp = [];
const aroonDown = [];
for (let i = 0; i < gb.data.candlesClose.length - 25; i++) {
const high = Math.max(...gb.data.candlesHigh.slice(i, i + 25));
const low = Math.min(...gb.data.candlesLow.slice(i, i + 25));
const aroonUpValue = ((25 - (gb.data.candlesHigh.slice(i, i + 25).indexOf(high) + 1)) / 25) * 100;
const aroonDownValue = ((25 - (gb.data.candlesLow.slice(i, i + 25).indexOf(low) + 1)) / 25) * 100;
aroonUp.push(aroonUpValue);
aroonDown.push(aroonDownValue);
}
return { aroonUp, aroonDown };
}

// log indicators and trading conditions
console.log('MSI:', msi());
const { aroonUp, aroonDown } = aroon();
console.log('Aroon Up:', aroonUp);
console.log('Aroon Down:', aroonDown);
const buyConditions = aroonUp[aroonUp.length - 1] > 70 && msi()[msi().length - 1] > 0 && !gb.data.gotBag;
const sellConditions = aroonDown[aroonDown.length - 1] > 70 && msi()[msi().length - 1] < 0 && gb.data.gotBag;

if (enoughTimePassed) {
if (buyConditions) {
const buyAmount = parseFloat(gb.data.pairLedger.whatstrat.TRADING_LIMIT) / gb.data.bid;
gb.method.buyMarket(buyAmount, gb.data.pairName);
setTimestamp();
} else if (sellConditions) {
gb.method.sellMarket(gb.data.quoteBalance, gb.data.pairName);
setTimestamp();
}
}

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