Use several timeframes and instruments
Check the bigger picture before you trade.
An algorithm runs on one instrument and one interval, chosen when you start a backtest or session. It can still read other timeframes and other instruments.
Read a higher timeframe
Section titled “Read a higher timeframe”Put the timeframe in front of an indicator:
function onIntervalClose() { const hourlyTrendUp = H1.sma(5) > H1.sma(20); const fastAbove = sma(5) > sma(20);
if (hourlyTrendUp && fastAbove && OPEN_POSITIONS_COUNT === 0) { openPosition("BUY", { riskPercentage: 1, stopLossPips: 20 }); }}Here sma(5) uses the run’s own interval, say 15 minutes, while H1.sma(5) uses hourly bars. The intervals are M1, M2, M5, M10, M15, M30, H1, H2, H4, H8, H12 and D1.
Read another instrument
Section titled “Read another instrument”function onIntervalClose() { if (INSTRUMENTS["GBP_USD:OANDA"].H1.sma(5) > INSTRUMENTS["GBP_USD:OANDA"].H1.sma(20)) { log("GBP/USD is rising on the hour"); }}Name the instrument exactly as the Instrument: list shows it, including the broker after the colon, and write INSTRUMENTS["…"] out in full each time. Cloud9Trader reads your code before it runs to work out which prices to load, so the name must be a literal string. You can give the instrument a shorter name at the top level, such as const gbpusd = INSTRUMENTS["GBP_USD:OANDA"];, and use it in place of the full form. See INSTRUMENTS.
Trade another instrument
Section titled “Trade another instrument”function onIntervalClose() { if (OPEN_POSITIONS_COUNT === 0) { INSTRUMENTS["GBP_USD:OANDA"].openPosition("BUY", { quantity: 10000, stopLossPips: 25 }); }}Limits
Section titled “Limits”- An algorithm can use at most 10 indicator settings in total, counting each timeframe and instrument separately.
sma(5)andH1.sma(5)are two. - A misspelled instrument stops the run with “Instrument ‘…’ is not available”.
- Each extra instrument must have price history for the backtest’s dates.