Skip to main content

RSI & moving averages strategy

This strategy aims to use technical analysis to identify entry and exit signals for a position trading strategy. It uses two popular indicators - moving averages and the Relative Strength Index (RSI) - to generate these signals.

Moving averages are commonly used to identify trends and support/resistance levels. The strategy likely involves calculating the moving average over a certain time period and using it as a guide for determining whether the trend is bullish or bearish.

The RSI is a momentum indicator that measures the strength of price movements. It typically ranges from 0 to 100 and is used to identify oversold and overbought conditions in the market. A value above 70 is considered overbought, while a value below 30 is considered oversold.

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 indicators
const ema1 = gb.data.ema1;
const ema2 = gb.data.ema2;
const rsi = gb.data.rsi;

console.log(`EMA1: ${ema1}, EMA2: ${ema2}, RSI: ${rsi}`);

if (enoughTimePassed) {
// calculate buy and sell conditions
const buyConditions = ema1 > ema2 && rsi < 30 && !gb.data.gotBag;
const sellConditions = ema1 < ema2 && rsi > 70 && gb.data.gotBag;

console.log(`Buy conditions: ${buyConditions}, Sell conditions: ${sellConditions}`);

// fire orders when conditions are met
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