This strategy is based on the observation that the price tends to reverse/retrace from extremes and this algorithm captures such behavior.

When the price reaches local minimum (20 candles), the trade is executed, expecting the price correction in opposite direction.

entry position (white dot) and exit position (yellow square)

Below is the code that uses Badger algo-trading framework for backtesting and visualization:

// LOCAL MINIMUM STRATEGY

bool hasOpenPosition() {
	return 
		this.positions.length != 0 &&
		this.positions[$-1].action == Action.OPEN;
}

int trades = 0;

override bool trade() {
	if(!super.trade()) return false;
	// ALL CODE HERE - BEGIN //

	if (trades >= 1 && !hasOpenPosition()) {
		return false; // stop the bot
	}

	long window = 20; // 20-candles minimum
	Candle[] btcCandles = this.candles[c.BTCUSDT];
	double currentPrice = btcCandles[$-1].close;
	double lastCandleMinimum = btcCandles[$-2].low;
	Candle[] candlesWindow = btcCandles[$-window-1..$-1];
	double lowestPrice = candlesWindow.map!(c => c.low).minElement;

	if (
		!hasOpenPosition() &&
		lastCandleMinimum <= lowestPrice
	) {
		Order marketBuy = Order(
			c.BTCUSDT,
			OrderType.MARKET,
			Direction.BUY,
			currentPrice * 1.003, // target price
			currentPrice * 0.995, // stop price
		);
		this.order(marketBuy);
		trades++;
	}

	// ALL CODE HERE - END //
	return true;
}