McClellan Summation Index & Aroon indicator strategy
This strategy uses two indicators, the McClellan Summation Index and the Aroon indicator, to generate entry and exit signals. The example calculates both indicators directly and logs the outputs and conditions.
The McClellan Summation Index is a breadth indicator derived from the McClellan Oscillator, which compares 39-day EMAs of advancing and declining issues. The summation index accumulates those oscillator values, commonly over 19 periods.
The Aroon indicator tracks time since the highest high and lowest low over a period to gauge trend strength and reversals.
Together, the McClellan Summation Index provides a market breadth view while Aroon highlights trend timing for buys and sells.
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