Then we switch the label to bar numbers with the t_xloc() function: // Change the label to bar numbers, and move it 6 bars to the right t_xloc(id =myLabel, x = bar_index + 6, xloc = xloc.bar_index) That way we still have a way to access the label. We store the label identifier we get from label.new() in the myLabel variable. It has a bigger size than normal ( size.large). The label’s style points left ( label.style_label_left) and its colour is fuchsia ( color.fuchsia). The xloc.bar_time value tells the label to use time values (rather than the default bar numbers). This code draws a label at the current bar’s time and close price. Style = label.style_label_left, color = color.fuchsia , MyLabel = label.new(x = time, y = close, xloc = xloc.bar_time , First let’s make a label with the label.new() function: // Make a time-based label at the bar's close The alternative is to switch a label from time values to bar numbers. From now on, the label uses time values instead of the default bar numbers. So for the third argument we use the xloc.bar_time value. Next we tell the label to use time values. This gives a time coordinate that’s 6 hours beyond the current bar’s time. We use the current bar’s time ( time), increased ( +) with 6 times the number of milliseconds in an hour (3.6 million). We use a time value since that’s what we want to change the label to. Then we set the label’s new x-axis coordinate. That’s how we tell the function which label to change. Then we change the label’s time-axis coordinate style: // Have the label use time values and move it 6 hours // to the right of the current bar t_xloc(id =myLabel, x = time + 6 * 3600000, xloc = xloc.bar_time) With this variable we can now access the label. The identifier that label.new() returns we store in the myLabel variable. That means the label uses the default bar numbers. We don’t tell label.new() which time coordinate style to use. The label’s size is bigger than normal ( size.large). Its style points left ( label.style_label_left) while its colour is fuchsia ( color.fuchsia). This code draws a label at the current bar’s close ( bar_index, close). MyLabel = label.new(x = bar_index, y = close, style = label.style_label_left ,Ĭolor = color.fuchsia, size = size.large) So let’s make one with the label.new() function: // Create a bar-based label at this bar's close To make a label use times instead of bar numbers, we first need a label. Or to toggle a label from time values to bar numbers. To switch a label from bar numbers to time values. xloc.bar_time: lets the label use time values for its x-axis coordinates.(This is also what labels use by default.) xloc.bar_index: makes the label uses bar numbers for its x-axis coordinates.xloc is a constant that sets the new coordinate style of the label.Which of those two depends on what xloc argument is. This coordinate is either a bar number or time value. x is a number with the label’s new time coordinate. The function won’t error with na but silently does nothing instead. When we (accidentally) use the na value with this argument, t_xloc() cannot change a label’s time coordinate style.The label.new() function returns this identifier the moment we make the label.Without it, Pine Script doesn’t know what label we want to change. Thanks to the identifier Pine Script knows which label to modify.id defines the identifier of the label we want to change.To make that change in time coordinate style, t_xloc() needs three things: which label to modify, the new time coordinate, and which style to use. Or how a time-based label can now use bar numbers instead. That’s how a label that initially uses bar numbers can now work with time values going forward. What t_xloc() does is change which coordinate option the existing label uses Pine Script can set that coordinate in two ways: with a bar number or time value. After our Pine Script code draws a label, we change that label’s time-axis coordinate style with the t_xloc() functionĮvery TradingView label requires an x-axis coordinate.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |