// collect indicator data
let rsi10
let rsi20
gb.method.tulind.indicators.rsi.indicator([gb.data.candlesClose], [10], function (err, results) {
rsi10 = results[0]
});
gb.method.tulind.indicators.rsi.indicator([gb.data.candlesClose], [20], function (err, results) {
rsi20 = results[0]
});
// define trading conditions
const entryConditions = (
rsi10[rsi10.length - 1] > rsi20[rsi20.length - 1] &&
rsi10[rsi10.length - 2] < rsi20[rsi20.length - 2]
)
const exitConditions = (
gb.data.gotBag &&
rsi10[rsi10.length - 1] < rsi20[rsi20.length - 1] &&
rsi10[rsi10.length - 2] > rsi20[rsi20.length - 2]
)
// place orders when trading conditions happen
const buyAmount = parseFloat(gb.data.pairLedger.whatstrat.TRADING_LIMIT) / gb.data.bid
if (entryConditions) {
gb.method.buyMarket(buyAmount, gb.data.pairName)
}
else if (exitConditions) {
gb.method.sellMarket(gb.data.quoteBalance, gb.data.pairName)
}
This example shows how you can create a simple trading strategy. The strategy places a market buy order when a 10 period RSI crosses over a 20 period RSI, and places a market sell order on the crossdown. First you would generate your RSI data, once for a 10 period and once for a 20 period RSI. This is done using the tulind library, but you could use any method you want. Often you could use pre calculated indicator values, but in this case we need the full array to detect crosses. Then the crossing conditions are defined, when these happen an order gets sent.