Timeframes
Each timeframe is a global, from M1 to D1, holding the bars, past prices and indicators of that timeframe for the instrument your algorithm runs on. Every instrument in INSTRUMENTS has the same timeframes.
declare const M1: TimeframeAPI;
interface TimeframeAPI extends BuiltInIndicators { /** The open time of the current or closing bar. */ readonly TIME: Date; /** Mid prices of the current or closing bar. */ readonly OPEN: number; readonly HIGH: number; readonly LOW: number; readonly CLOSE: number; readonly MID: OHLC; readonly BID: OHLC; readonly ASK: OHLC; readonly PRICE: PriceBar; readonly price: PriceFunction; readonly prices: PricesFunction; /** Runs when a bar of this timeframe closes. */ onIntervalClose?: () => void;}M2, M5, M10, M15, M30, H1, H2, H4, H8, H12 and D1 are declared the same way.
What a timeframe has
Section titled “What a timeframe has”OPEN,HIGH,LOW,CLOSE: mid prices of its current or closing bar.MID,BIDandASKgive each side’s open, high, low and close, andPRICEhas the lot, withTIME, the bar’s open time.price()andprices()for that timeframe.- Every built-in indicator, calculated on that timeframe’s bars, such as
H4.rsi(14). onIntervalClose, which you can assign to run when its bars close.
Example
Section titled “Example”function onIntervalClose() { const trendUp = H4.ema(50) < H4.CLOSE; if (trendUp && rsi(14) < 30 && OPEN_POSITIONS_COUNT === 0) { openPosition("BUY", { quantity: 1000, stopLossPips: 20 }); } log("Daily high so far", D1.HIGH, "last hour's ask high", H1.ASK.HIGH);}
D1.onIntervalClose = function () { log("Day closed at", D1.CLOSE);};