简体   繁体   中英

How can I display only part of candles on Tradingview Chart?

I`m using Premium membership So when I use BTCUSDT chart, there are 20K candles.

If I want to only display or call 10K or 15K candles, is it possible? then how?

(the reason why I want to display only 10K candles on the chart is like below. -> I`m using 40 request security functions with array functions which requires too many calculations. Eventhough I set time range for calculation, It seems that each 40 request security functions are calling whole candles according to the number of original chart candles which is 20K candles in this case And it usually causes error: pinescript calculation takes too long to execute)

So, How can I call only part of whole 20K candles?

Thanks!

I tried to find any functions to limit the number of total candles in the Tradingview chart. but I failed to find the function.

Even if the plot only lasts 100 bars, a security will be calculated for the whole dataset anyway:

//@version=5
indicator("My script")

sfunctions() =>
    s1 = request.security("NASDAQ:AAPL", "", close)
    s1 //.. s40

calcLast(int bars) =>
    if bar_index >= last_bar_index - bars or barstate.isrealtime
        sfunctions()
    else 
        na

// plot only last 100 bars. But security still will be calculated for the whole dataset! 
plot(calcLast(100))

The possible solution to your case could be a condition according to which heavy calculations would call last X bars, and other bars would send "na" for security functions:

//@version=5
indicator("My script")

CALC_LAST_BARS = 100

heavyCalculations() =>
    if bar_index >= last_bar_index - CALC_LAST_BARS or barstate.isrealtime
        2 + 2 //  <- heavy calculations here
    else 
        na

sfunctions() =>
    s1 = request.security("NASDAQ:AAPL", "", heavyCalculations())
    s1 //..s40

plot(sfunctions())

Also note that

no.1:

cl = request.security("BTCUSDT","60m",close)
sma = ta.sma(cl,14)
rsi = ta.sma(cl,14)

no.2

[sma,rsi] = request.security("BTCUSDT","60m",[ta.sma(close,14),ta.rsi(close,14)])

no.2 is faster, because in this case variables is calculated in other timeframe, while for the first option, each close bar will be returned and then calculated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM