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);
// 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
// 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)
Technical indicator
Absolute currency strength
Accumulation/distribution index
Advance-Decline Data
Average directional movement index
Average true range
Bollinger Bands
Commodity channel index
Detrended price oscillator
Donchian channel
Double exponential moving average
Ease of movement
Force index
Ichimoku Kinkō Hyō
Keltner channel
MACD
Mass index
Momentum (technical analysis)
Money flow index
Moving average crossover
Moving average envelope
Negative volume index
On-balance volume
Oscillator (technical analysis)
Parabolic SAR
Put/call ratio
Rahul Mohindar oscillator
Range expansion index
Relative currency strength
Relative strength index
Rising moving average
Smart money index
Stochastic oscillator
KST oscillator
Triple exponential moving average
Trix (technical analysis)
True strength index
Ulcer index
Ultimate oscillator
Volume analysis
Volume–price trend
Vortex indicator
Williams %R
Zero lag exponential moving average
The indicators above are just some ideas from Wikipedia. Please look for more and add/remove indicators as needed.
It would be nice to get some back-data to be able to average over daily trends by time of day. This could be a very helpfull indicator.