The simplest code example for Badger algo-trading framework is “buy and hold” strategy where your main focus is picking a good entry point.

This code example picks the entry point at random (at the beginning of the backtestPeriod).

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

But you can decide based on variety of factors like:

// you can also add custom variables here
// their state is preserved between the loops
int minutesPassed = 0;

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

	Order marketBuy = Order(
		c.BTCUSDT,
		OrderType.MARKET,
		Direction.BUY,
		1_000_000, // target price
		0 // stop price
	);
	Order marketSell = Order(Action.CLOSE);

	if (this.positions.length == 0) {
		this.order(marketBuy);
	}

	if (minutesPassed >= 20) {
		this.order(marketSell);
		return false; // stop the bot
	}

	minutesPassed++;

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