Skip to main content


The strategy is a contrarian trading strategy that uses two technical indicators, the Stochastic oscillator and Williams %R, to identify potential entry and exit points for trades.

The Stochastic oscillator is a momentum indicator that compares the closing price of an asset to its price range over a specified period of time. It measures whether the asset is overbought or oversold and can indicate potential turning points in the market.

Williams %R is another momentum indicator that measures overbought and oversold levels by comparing the closing price to the highest high and lowest low over a specified period of time. It is similar to the Stochastic oscillator but is calculated differently.

It looks for situations where the market is overbought or oversold according to these indicators and then take trades in the opposite direction of the current trend.

For example, if the Stochastic oscillator and Williams %R both indicate that the market is overbought, you would consider taking a short position (betting that the price will go down) in the asset. Conversely, if both indicators indicate that the market is oversold, you would consider taking a long position (betting that the price will go up).


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 = || {};

// forced wait time reduces risk of double orders
function checkTime() {
return ! || typeof !== "number"
? ( =, false)
: ( - > 8000);
const enoughTimePassed = checkTime();

// set timestamp for checkTime in next round
const setTimestamp = () => =;

// calculate Stochastic oscillator
const stochK = ([] - Math.min( / (Math.max( - Math.min( * 100;
const stochD =, 3);

// calculate Williams %R
const willR = (Math.max( -[]) / (Math.max( - Math.min( * -100;

// log indicators and trading conditions
console.log(`Stochastic K: ${stochK}`);
console.log(`Stochastic D: ${stochD}`);
console.log(`Williams %R: ${willR}`);

const buyConditions = stochK < 20 && willR < -80 && !;
const sellConditions = stochK > 80 && willR > -20 &&;

if (enoughTimePassed) {
if (buyConditions) {
const buyAmount = parseFloat( /;
} else if (sellConditions) {

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