0

有谁知道是否可以使用 request.security() 请求字符串数据以同时获取多个符号的信息?我编译的脚本没有错误,但问题是警报消息中的一些数据是针对主符号而不是安全符号的。示例:如果我设置了警报并且在我创建警报时恰好出现在图表上的符号(例如 AAPL),那么每次针对列表中的任何一个符号(“安全符号” ) 它每次都会显示 AAPL 的交易所 (syminfo.prefix) 而不是列表中的符号,例如 COINBASE:BTCUSD = NASDAQ。

我已经尝试了我能想到的一切,但无法获得正确的信息。否则我会得到一个错误。这个错误出现得最多:“Type series__string cannot be used as tuple element in request.security 'expression' argument” 阅读文档后,我想我明白为什么我不能在元组中请求字符串。那么,甚至可以在多个符号上请求 syminfo.prefix 之类的信息吗?

大部分脚本来自 TradingView 博客文章:https ://www.tradingview.com/blog/en/our-new-alerts-allow-for-dynamic-messages-22588/

我的脚本:

//@version=5

indicator('trigger RSI alert for multiple symbols')

// Just testing to see if something like this would work
my_func(_ticker) =>
    dTicker = str.tostring(syminfo.ticker) + ' : '
    dTitle = str.tostring(syminfo.prefix)
    returnString = ' test ' + dTicker + dTitle 
    returnString

// Most of the following is from the TradingView blog post
f_triggerRsi(_ticker) =>
    _r = ta.rsi(close, 14)
    _x = ta.crossover(_r, 60)
    _y = ta.crossunder(_r, 40)
    _p = close
    _c = syminfo.prefix
    _rt = barstate.isrealtime
    _tn = timenow
    // Trying few things:
    //_s = syminfo.prefix (can't use string in tuple error message)  
    //_ts = timenow (doesn't work)
    //_j = str.split(syminfo.ticker, ":") 
    
    [_rsi, _co, _cu, _px, _rt_bar] = request.security(_ticker, timeframe.period, [_r, _x, _y, _p, _rt])
    _msg = _ticker + ', ' + timeframe.period + ': ' + 'Test: ' + my_func(_ticker) 
    if _co and _rt_bar
        _msg += 'RSI (' + str.tostring(_rsi) + ') crossing up 60 level ' + 'Price: ' + str.tostring(_px, "#.##") + 'Test1: ' + syminfo.prefix 
        alert(_msg, alert.freq_once_per_bar) 

    else if _cu and _rt_bar
        _msg += 'RSI (' + str.tostring(_rsi) + ')  crossing down 40 level ' + 'Price: ' + str.tostring(_px, "#.##") + 'Test2: ' + syminfo.prefix 
        alert(_msg, alert.freq_once_per_bar) 
       
// This script currently returns:
//  GOOD: ticker correctly with _ticker
//  GOOD: RSI value correctly with _rsi
//  GOOD: timeframe correctly (but it's inherantly correct)
//  BAD: exchange incorrectly, returns the exchange of the main symbol and not the value of the security symbols
//  BAD: timestamp is always the time of the main symbol not the security symbols 

// Data I need in the alert message
//  a) tickerid that triggered the alert (NASDAQ:AAPL, COINBASE:BTCUSD, etc.)
//  b) timeframe that the ticker is on (Daily, 30 Minute, etc.)
//  c) the exchange separately without the ticker (syminfo.prefix)
//  d) the symbol without the exchange (syminfo.ticker)
//  d) timestamp - the time the alert for the security tickerid was triggered at the exchange time

// Security Symbols 
f_triggerRsi(syminfo.tickerid) 
f_triggerRsi('NASDAQ:MSFT') 
f_triggerRsi('NYSE:PLTR')
f_triggerRsi('NASDAQ:AAPL')
f_triggerRsi('NASDAQ:DWAC')
f_triggerRsi('NASDAQ:PHUN')
f_triggerRsi('NASDAQ:SBEA')
f_triggerRsi('NASDAQ:SEAC')
f_triggerRsi('NASDAQ:CFVI')
f_triggerRsi('NASDAQ:MSFT')
f_triggerRsi('NASDAQ:NVDA')
f_triggerRsi('NASDAQ:FB')
f_triggerRsi('NASDAQ:AMD')
f_triggerRsi('NASDAQ:TSLA')
f_triggerRsi("COINBASE:BTCUSD")
f_triggerRsi("COINBASE:ETHUSD")
f_triggerRsi("COINBASE:LTCUSD")
f_triggerRsi("BINANCE:SOLUSDT")
f_triggerRsi("FTX:RAYUSD")
f_triggerRsi("BINANCE:ICPUSDT")
4

0 回答 0