The premise of this strategy is that whatever is happening will continue happening (especially when it comes to a strong trend).

In this example, I’m using 5 consecutive green candles as an indicator of a strong trend. Because something is obviously causing such a clear move in one direction.

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

The code

In the code below, using the Badger algo-bot starter code, you can see how I’m checking whether 5 back-to-back candles are green.

And if they are, the trade is executed.

// TREND FOLLOWING STRATEGY

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

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

	Candle[] btcCandles = this.candles[c.BTCUSDT];
	double currentPrice = btcCandles[$-1].close;

	bool is5green = 
		btcCandles[$-2].color == Color.GREEN &&
		btcCandles[$-3].color == Color.GREEN &&
		btcCandles[$-4].color == Color.GREEN &&
		btcCandles[$-5].color == Color.GREEN &&
		btcCandles[$-6].color == Color.GREEN;

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

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

Test results

After 1748 trades we (again) blew our account.

What is also funny (or at least interesting) is that we blew our account when trying to go against the trend, and here again we blew our account when trying to follow the trend.

Some might say that this trading thing is much more difficult that it may appear at first 😉

----------------------------
| PERFORMANCE    |
----------------------------
- Initial capital: 100000.00
- Final capital::: 2807.78
- Total trades:::: 1748

- ROI:::::: -97.19 %
- Min. ROI: -97.19 %
- Max. ROI: 0.40 %

- Drawdown: -97.20 %
- Pushup::: 1.40 %
----------------------------

Want to develop your own AI instead of hardcoding the trading rules?