Williams strategy
This strategy involves creating a contrarian trading strategy, which means taking a position opposite to the prevailing trend in the market. The Stochastic oscillator and Williams %R indicators are used to identify potential entry and exit signals for trading.
The Stochastic oscillator is a momentum indicator that measures the current closing price in relation to its price range over a set period. It indicates whether the market is overbought or oversold, and traders can use this information to identify potential trend reversals. Similarly, the Williams %R is also a momentum indicator that measures the level of the current price in relation to its highest high over a set period. It also helps traders identify overbought or oversold conditions in the market.
Overall, this strategy attempts to identify potential trend reversals using the Stochastic oscillator and Williams %R indicators, and take a contrarian trading position based on the market's current trend.
This example strategy is machine generated using Gunbot AI. Review its behavior carefully in a simulated trading 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 Stochastic oscillator
const stochK = (gb.data.candlesClose[gb.data.candlesClose.length-1] - Math.min(...gb.data.candlesLow.slice(-14))) / (Math.max(...gb.data.candlesHigh.slice(-14)) - Math.min(...gb.data.candlesLow.slice(-14))) * 100;
const stochD = gb.data.slowSma.slice(-3).reduce((a, b) => a + b, 0) / 3;
// calculate Williams %R
const williamsR = (Math.max(...gb.data.candlesHigh.slice(-14)) - gb.data.candlesClose[gb.data.candlesClose.length-1]) / (Math.max(...gb.data.candlesHigh.slice(-14)) - Math.min(...gb.data.candlesLow.slice(-14))) * -100;
// log indicators and trading conditions
console.log(`Stochastic oscillator K: ${stochK}`);
console.log(`Stochastic oscillator D: ${stochD}`);
console.log(`Williams %R: ${williamsR}`);
console.log(`Bag status: ${gb.data.gotBag ? 'Has bag' : 'No bag'}`);
if (enoughTimePassed) {
// calculate buy and sell conditions
const buyConditions = stochK < 20 && stochD < 20 && williamsR < -80 && !gb.data.gotBag;
const sellConditions = stochK > 80 && stochD > 80 && williamsR > -20 && gb.data.gotBag;
// 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();
console.log('Buy order placed');
} else if (sellConditions) {
gb.method.sellMarket(gb.data.quoteBalance, gb.data.pairName);
setTimestamp();
console.log('Sell order placed');
}
}
// Code is machine generated, review it and run in simulator mode first