INSTRUMENTS
Every instrument your algorithm names, by its identifier, such as INSTRUMENTS["EUR_USD:OANDA"]. Use it to read other markets, react to them, or trade them.
declare const INSTRUMENTS: { readonly [instrumentId: string]: InstrumentAPI };
interface InstrumentAPI extends Instrument, BuiltInIndicators { /** The instrument's identifier, such as "EUR_USD:OANDA". */ readonly ID: string; readonly BID: number; readonly ASK: number; readonly MID: number; /** The spread in pips. */ readonly SPREAD: number; /** Mid prices of the current or closing bar on the session's timeframe. */ readonly OPEN: number; readonly HIGH: number; readonly LOW: number; readonly CLOSE: number; readonly M1: TimeframeAPI; readonly M2: TimeframeAPI; readonly M5: TimeframeAPI; readonly M10: TimeframeAPI; readonly M15: TimeframeAPI; readonly M30: TimeframeAPI; readonly H1: TimeframeAPI; readonly H2: TimeframeAPI; readonly H4: TimeframeAPI; readonly H8: TimeframeAPI; readonly H12: TimeframeAPI; readonly D1: TimeframeAPI; /** Opens a position on this instrument at the market. */ openPosition(side: Side, options: OpenPositionOptions): void; /** Runs on every price update of this instrument. */ onTick?: () => void; /** Runs when a bar of this instrument closes, on the session's timeframe. */ onIntervalClose?: () => void;}Naming an instrument
Section titled “Naming an instrument”Name each instrument with a literal string, and write INSTRUMENTS["…"] in full each time you use it. Cloud9Trader reads your code before it runs to work out which prices to load, so an identifier built at run time, such as INSTRUMENTS[name], finds nothing. An instrument can have a shorter name, such as const eurusd = INSTRUMENTS["EUR_USD:OANDA"];, declared at the top level. Its handlers and indicators, such as eurusd.H4.onIntervalClose and eurusd.H4.sma(10), are wired as if written in full. Inside a function a shorter name is refused.
Each entry has the instrument’s current prices, the bars of the session timeframe (OPEN to CLOSE), every timeframe with its price() and prices(), every built-in indicator, and openPosition. An entry has no price() or prices() of its own: use a timeframe, such as INSTRUMENTS["EUR_USD:OANDA"].H1.prices(20).
Example
Section titled “Example”function onIntervalClose() { const closes = INSTRUMENTS["EUR_USD:OANDA"].H1.prices(24); log("EUR/USD bid", INSTRUMENTS["EUR_USD:OANDA"].BID, "24-hour high", Math.highest(closes)); if (INSTRUMENTS["EUR_USD:OANDA"].rsi(14) < 30 && OPEN_POSITIONS_COUNT === 0) { INSTRUMENTS["EUR_USD:OANDA"].openPosition("BUY", { quantity: 1000, stopLossPips: 20 }); }}
INSTRUMENTS["EUR_USD:OANDA"].onTick = function () { log("EUR/USD spread", INSTRUMENTS["EUR_USD:OANDA"].SPREAD);};