Skip to content

Runs on every price update (tick) of the instrument your backtest or trading session runs on.

function onTick(): void

You write this function; Cloud9Trader calls it. An algorithm must define onTick, onIntervalClose, or both, or it does not start.

Once per tick, after BID, ASK, TIME and the account values are set for that tick. If the tick also closes a bar, onIntervalClose runs first.

To handle ticks of another instrument, assign a function to that instrument’s onTick at the top level of your script. Name the instrument with a literal string, so Cloud9Trader knows to load its prices.

An error thrown in onTick is written to the run’s log. A backtest stops at the first error. A live session stops if it errors three times within 60 seconds.

function onTick() {
if (SPREAD > 3) {
log("Wide spread at", TIME.toISOString(), SPREAD);
}
}
INSTRUMENTS["GBP_USD:OANDA"].onTick = function () {
log("GBP/USD bid", INSTRUMENTS["GBP_USD:OANDA"].BID);
};