Skip to main content

Gann Fan and Williams Fractal indicator strategy

The trading strategy that utilizes both the Gann Fan and Williams Fractal indicator for entry and exit signals is a technical analysis approach that attempts to identify potential trends in the price movement of a security.

The Gann Fan is a tool that is used to identify potential support and resistance levels in the market. It is based on the theory that markets move in predictable geometric patterns and uses a series of diagonal lines to help traders identify potential trend lines.

On the other hand, the Williams Fractal indicator is a technical analysis tool that uses fractal geometry to identify potential reversal points in the market. It identifies turning points where the price movement changes direction, indicating potential opportunities for traders to enter or exit the market.

When combining these two tools, traders can use the Gann Fan to identify potential support and resistance levels, and the Williams Fractal indicator to confirm a reversal or continuation of the trend. Traders can enter long or short positions depending on the signals given by the indicators and exit the position when the indicators signal a potential reversal or when the price reaches a support or resistance level identified by the Gann Fan.

Overall, this trading strategy can provide traders with a comprehensive approach to identifying potential trends and market opportunities, and can help them make informed decisions about when to enter and exit positions.

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 Gann Fan indicator
function calculateGannFan() {
const highs = gb.data.candlesHigh.slice(-9);
const lows = gb.data.candlesLow.slice(-9);
const fanLevels = [];
for (let i = 0; i < 9; i++) {
const fanLevel = (highs[i] + lows[i]) / 2;
fanLevels.push(fanLevel);
}
return fanLevels;
}

// calculate Williams Fractal indicator
function calculateWilliamsFractal() {
const highs = gb.data.candlesHigh.slice(-5);
const lows = gb.data.candlesLow.slice(-5);
const fractals = [];
for (let i = 2; i < 5; i++) {
if (highs[i] > highs[i - 2] && highs[i] > highs[i - 1] && highs[i] > highs[i + 1] && highs[i] > highs[i + 2]) {
fractals.push({ type: "high", value: highs[i] });
}
if (lows[i] < lows[i - 2] && lows[i] < lows[i - 1] && lows[i] < lows[i + 1] && lows[i] < lows[i + 2]) {
fractals.push({ type: "low", value: lows[i] });
}
}
return fractals;
}

// log indicators and trading conditions
console.log("Gann Fan:", calculateGannFan());
console.log("Williams Fractal:", calculateWilliamsFractal());
console.log("Stoch RSI:", gb.data.stochRsi);
console.log("Got Bag:", gb.data.gotBag);

if (enoughTimePassed) {
const buyAmount = parseFloat(gb.data.pairLedger.whatstrat.TRADING_LIMIT) / gb.data.bid;
const gannFan = calculateGannFan();
const williamsFractal = calculateWilliamsFractal();
const buyConditions = gannFan[0] < gb.data.bid && williamsFractal.some(fractal => fractal.type === "low") && gb.data.stochRsi < 0.1 && !gb.data.gotBag;
const sellConditions = gannFan[8] > gb.data.ask && williamsFractal.some(fractal => fractal.type === "high") && gb.data.gotBag;

if (buyConditions) {
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