🤝 Live!

Run custom code here to test a strategy:

length = 15; // length for the candlesticks.
startingCash = 5000;

strategy = function(){
	const shortTermMA = calculateMovingAverage(candles, 5);
	const longTermMA = calculateMovingAverage(candles, 45);

	if (shortTermMA > longTermMA) {
		return 'Buy';   // Recommend the bot buy.
	} else if (shortTermMA < longTermMA) {
		return 'Sell';  // Recommend the bot sell.
	} else {
		return 'Hold';  // Recommend the bot hold.
	}
}

bot = new BacktestingBot(startingCash);

Accessing data:

// Stock prices get put here 👇 as they are received.
	closingPrices // [44139.42, 44139.41, 44139.42, 44139.42, ...]
	candles   // [ {high:3.89, low:3.88, start:3.89, end:3.88} ... ]

// Try typing some of these in the console...
candles          // Show an array of all candles.
candles[0]       // Show the first candle.
candles[1].high  // Show the "high" value of the second candle
candles[2].end   // Show the "end" value of the third candle

bot = new BacktestingBot(startingCash); // Make a bot 🤖

// ...you can access his internals like this:
	bot.balance            // Starting balance
	bot.spendLimit         // Max spending limit.
	bot.position           // (0 for neutral, 1 for long, -1 for short)
	bot.previousShareValue // Stock price when last transaction took place.
	bot.currentShareValue  // Current stock price.
	bot.numberOfShares     // How many shares you own.
	bot.unit               // 1/this.currentShareValue

Accessing predefined functions:


// Create candles
candleStick(array, length)
// Functions that take candles:
calculateMovingAverage(candles, n); // Average over n candles. 

// Functions that take closingPrices:
calculateMACD(closingPrices, shortPeriod, longPeriod, signalPeriod);
calculateEMA(values, period)