CyberMensch

Last Available Bar Info

CyberMensch Uppdaterad   
Library "Last_Available_Bar_Info"

getLastBarTimeStamp()

getAvailableBars()

This simple library is built with an aim of getting the last available bar information for the chart. This returns a constant value that doesn't change on bar change.
For backtesting with accurate results on non standard charts, it will be helpful. (Especially if you are using non standard charts like Renko Chart).

Methods

getLastBarTimeStamp()
: Returns Timestamp of the last available bar (Constant)

getAvailableBars()
:Returns Number of Available Bars on the chart (Constant)


Example

import paragjyoti2012/Last_Available_Bar_Info/v1 as LastBarInfo

last_bar_timestamp=LastBarInfo.getLastBarTimeStamp()
no_of_bars=LastBarInfo.getAvailableBars()

If you are using Renko Charts, for backtesting, it's necesary to filter out the historical bars that are not of this timeframe.
In Renko charts, once the available bars of the current timeframe (based on your Tradingview active plan) are exhausted,
previous bars are filled in with historical bars of higher timeframe. Which is detrimental for backtesting, and it leads to unrealistic results.
To get the actual number of bars available of that timeframe, you should use this security function to get the timestamp for the last (real) bar available.

tf=timeframe.period
real_available_bars = request.security(syminfo.ticker, tf , LastBarInfo.getAvailableBars() , lookahead = barmerge.lookahead_off)
last_available_bar_timestamp = request.security(syminfo.ticker, tf , LastBarInfo.getLastBarTimeStamp() , lookahead = barmerge.lookahead_off)


Versionsinformation:
v2
Pinebibliotek

I sann TradingView-anda har författaren publicerat denna Pine-kod som ett bibliotek med öppen källkod så att andra Pine-programmerare från vår community kan återanvända den. Hatten av för författaren! Du kan använda det här biblioteket privat eller i andra publikationer med öppen källkod, men återanvändning av den här koden i en publikation regleras av våra ordningsregler.

Frånsägelse av ansvar

Informationen och publikationerna är inte avsedda att vara, och utgör inte heller finansiella, investerings-, handels- eller andra typer av råd eller rekommendationer som tillhandahålls eller stöds av TradingView. Läs mer i Användarvillkoren.

Vill du använda det här biblioteket?

Kopiera följande rad och klistra in det i ditt skript.