TradingView
ImmortalFreedom
5 ott 2020 13:54

Visualizing Behaviors of barstate Variables 

Descrizione

The title pretty much sums up what this script does. It's intended for Pine Script developers, but especially for newcomers to Pine Editor contemplating the use of barstate variables. I would recommend using this on 15 second or 1 minute chart intervals for a quick and obvious analysis of barstate behaviors.

These barstate variables change from TRUE to FALSE or FALSE to TRUE during specific times/conditions of script operation. One unique state you might not ever see change is barstate.isfirst. This is only TRUE when bar_index==0, most easily viewed on the monthly "All" chart on the far left. I provided a label displaying the current bar_index for perspective. I hope this provides an improved grasp of barstate understanding for fellow members, as it did for myself.

When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members , I may implement more ideas when they present themselves as worthy additions. Have a profitable future everyone!

Note di rilascio

Added textalign=text.align_left to dress up the labels with formatting finesse

Note di rilascio

barstate.islastconfirmedhistory is now a newly added barstate variable.
Commenti
Yelian
My intuition tells me this may play well with a Markov-Chain Process type indicator
syrinxflunki
Thanks !
GregFord2689
Thank you so much. This solved an enormous problem that I was having with an indicator to the right of the last bar.
The solution was to test for barstate.isconfirmed
The indicator was being over-written - but not any longer. Thank you.
The indicator comprises six consecutive single character labels. And it orks fine - 90% of the time. Ha!
ImmortalFreedom
@GregFord2689, I did have _label as a variable which is inside the function _label(), so that may have caused an anomaly at times. The newest version has been altered.
Time_Out_2021
Thank you for this publication
It helped me to gain the understanding I was looking for ...
it's wonderful how in pine script we can use a visual representation of the scripts to see the difference or results much easier :)
ImmortalFreedom
@Sneaker_Wave, By necessity I plot or display in some manner every complex variable type I have in indicators for inspection. label.new() combined with tostring() is a wonderful duo for any development where dynamic information can be conveyed in a textual form. In this script, I added a bonus bar_index label that comes in handy with rare scenarios. I often snag this _label() function for reuse when I start losing hair on a project.
sickojacko
Funny script btw :p
sickojacko
How do you explain that "islast" == true before the last bar ?
ImmortalFreedom
@sickojacko, When a chart is not real time, barstate.islast will be false until the very last bar of the historical data set. You will see the line jump upwards connecting the prior false(0.0) state to the true(1.0) condition. It may appear to be preceding the true condition, but it's just drawn after the fact to the "point" of true from the prior "point" of false.

In a real time chart scenario each NEW bar will newly become true, as it continually becomes the new last bar upon creation. Return to your charts after market closure and you will see the reported logic previously drawn will have changed. Watching the chart real time on 1min or even seconds charts when markets are open for an enduring amount of time is observationally informative.

Also, you can switch tickers in your "Watchlist and details" very expediently to repeatedly assist with identification of the transition from historical bars to newly generated ones. barstate.isnew can be extremely fast and very momentary, so if you blink at times, you may just miss it.
Altro