request.security brings the data of another market or timeframe into your script.
//@version=6 indicator("Daily Levels", overlay = true) // The high, low and close of the previous day, drawn on any intraday chart. dHigh = request.security(syminfo.tickerid, "1D", high[1], lookahead = barmerge.lookahead_on) dLow = request.security(syminfo.tickerid, "1D", low[1], lookahead = barmerge.lookahead_on) dClose = request.security(syminfo.tickerid, "1D", close[1], lookahead = barmerge.lookahead_on) plot(dHigh, "Previous high", color.red, style = plot.style_stepline) plot(dLow, "Previous low", color.green, style = plot.style_stepline) plot(dClose, "Previous close", color.gray, style = plot.style_stepline) // Another symbol next to this one. other = request.security("CAM_CFD:XAUUSD", timeframe.period, close) plot(other, "Gold (CFD)", color.orange, display = display.data_window)
The timeframe can be any you like: "15", "60", "240", "1D", "1W". Seconds work too ("5S"). Timeframes that CAM does not store are built from the next smaller one, and days follow the UTC day.
"15"
"60"
"240"
"1D"
"1W"
"5S"
syminfo.tickerid
"CAM_CFD:XAUUSD"
"SP:SPX"
"TVC:GOLD"
"BINANCE:BTCUSDT"
A symbol CAM does not have shows an error under the code, or gives na when you pass ignore_invalid_symbol = true.
ignore_invalid_symbol = true
Put two symbols such as "CAM_CFD:XAUUSD" and "CAM_CFD:XAGUSD" in one script to plot a spread or a correlation between them.
"CAM_CFD:XAGUSD"
A script can ask for up to 40 other series.