onTick
Runs on every price update (tick) of the instrument your backtest or trading session runs on.
function onTick(): voidYou write this function; Cloud9Trader calls it. An algorithm must define onTick, onIntervalClose, or both, or it does not start.
When it runs
Section titled “When it runs”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.
Errors
Section titled “Errors”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.
Example
Section titled “Example”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);};