TradingView
allanster
5 sty 2020 18:25

How To Color Prior Bars 

Bitcoin / United States DollarCoinbase

Opis

Example how to color the trigger bar of the condition and n-1 prior bars using only 1 barcolor() function.

Currently when offsets are used in barcolor(), bgcolor(), plot(), plotarrow(), plotchar(), or plotshape(), the offset only works with a simple (static) integer. If series (dynamic) integers are used instead, there is not an error, but the series values are ignored. Because of this limitation of offset being constrained to using only fixed offsets, the normal way to paint 3 Black Crows would be to use 3 barcolor() functions. Since there are a known number of bars to be painted in that scenario, this can be easily accomplished.

If a condition encompassed a variable length of n bars, then the number of barcolor() functions needed to use would be unknown. How to color the trigger bar of the condition and n-1 prior bars using only 1 barcolor() function? Dual examples below solves issue but requires n "future" bars, because of this it will not paint the most recent condition in realtime and may not be applicable for use in certain realtime situations. It paints similar in behavior to how a pivot does. Special thanks to LucF and RicardoSantos for illumination!

NOTICE: This is an example script and not meant to be used as an actual strategy. By using this script or any portion thereof, you acknowledge that you have read and understood that this is for research purposes only and I am not responsible for any financial losses you may incur by using this script!

Informacje o Wersji

Updated for Pine Script v5.

Informacje o Wersji

Cosmetic.
Komentarze
UnknownUnicorn15320316
is repaint?
allanster
@Bafrali1453, no, at least not in the way that term is sometimes meant to apply. When "repaint" is used as a negative term it generally refers to where something painted becomes unpainted, whereas the example script above does the opposite, the example shows how to paint something in the past which was originally unpainted. So "retroactive paint" would be a better description for what this example does. The offset causes a "repainting" of the past.

There are a lot of misperceptions that are prevalent in this community regarding repaint. What this term actually means is simply to recalculate and redraw (or update) as prices fluctuate.

Repaint in and of itself is not a bad thing. Most traditional (and respected) indicators repaint, which is a good thing. Load an RSI indicator and watch it's leading edge, as price moves, the RSI value does as well. This updating of the RSI value is repaint. Without repaint the current value of your RSI indicator would quickly be stale after bar open. I assume we agree that we both want our indicators to report current live values (repaint).

it is only when repaint is misused in strategies or alerts that repaint becomes an issue. If you set an alert to trigger when RSI crosses up 50 and you react to receiving this alert by going long, you may return to find that RSI only briefly crossed over, and within the same bar has now fallen back below level 50, more importantly price has fallen as well. You have just become a "victim" of repaint. Is RSI bad? No, you made a decision to go long BEFORE bar close, hopefully understanding the ramifications of this.

The same concept applies to automated strategies, if the author's logic used within their script does not allow for fully formed bars, then repaint may occur there also. Some script authors may do this ignorantly or maliciously, but they may also allow for repaint purposely to increase reaction time, knowing they are taking a calculated risk by acting more aggressively not waiting for bar close.

Hopefully I have explained this in a way where you will see that repaint can be both a good thing and a bad thing, depending on whether it is understood and applied appropriately.
Raoashok
very good sir . you can earn lot by using this.
allanster
@Raoashok, thanks for your kind words but this is only a coding example and not meant to be used as an actual strategy.
Maxx_y
Definitely something to look into. Love it.
allanster
@a_o, thanks for your interest and comment, appreciated.
Więcej