Last Available Bar InfoLibrary "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)
Barindex
SessionInfoLibrary "SessionInfo"
Utility functions for session specific information like the bar index of the session.
inSession(spec) Returns true if the current bar is in the session specification.
Parameters:
spec : session.regular (default), session.extended or other time spec.
Returns: True if the current is in session; otherwise false.
minutesToLen(minutes, multiple) Converts the number of minutes to a length to be used with indicators.
Parameters:
minutes : The number of minutes.
multiple : The length multiplier.
Returns: math.ceil(minutes * multiple / timeframe.multiplier)
bar(spec, res) Returns the intraday bar index. May not always map directly to time as a bars can be skipped.
Parameters:
spec : session.regular (default), session.extended or other time spec.
res : The resolution (default = "1440").
Returns: The integer index of the bar of the session.
isFirstBar(spec, res) Returns true if the current bar is the first one of the session.
Parameters:
spec : session.regular (default), session.extended or other time spec.
res : The resolution (default = "1440").
Returns: True if the current bar is the first one of the session.
wasLastBar(spec, res) Returns Returns true if the previous bar was the last of the session.
Parameters:
spec : session.regular (default), session.extended or other time spec.
res : The resolution (default = "1440").
Returns: True if was the last bar of the session.
Vertical line by bar_indexThis indicator helps in letting the trader focus on a particular date/candle across many symbols.
Tradingview currently has a bug in Bar Replay - when we switch symbols, the bar replay resets.
Hence if you are backtesting & running through a bunch of symbols, it is nearly impossible to focus on a particular historical candle across all symbols.
This indicator plots a vertical line on a given bar_index which remains as it is while you are switching symbols.
Feel free to copy, modify and use as you like!