PineCoders Squawk Box
3.84K subscribers
60 photos
166 links
News & Tips on TradingView's Pine programming language
Download Telegram
πŸ“ˆ #newfeature
Plots disabled in Settings/Style no longer appear in the Data Window

Continuing to show plots in the Data Window when users disabled them from the Settings/Style db confused users, so unchecking them in the Settings/Style db now also hides them in the Data Window. See in these screenshots how Plot 4 plot does not appear in the Data Window, nor in the Indicator's Values.

NOTE: This recent change has also introduced behavior which will cause user-selected transparency levels from the Settings/Style db to be reflected in the value rendered in the Data Window, whereas before, the value was always rendered with transparency zero. The transparency of Plot 1 was changed to 50% in the Settings/Style db here. We will try to have this side effect corrected.
πŸ”ˆ #news
The recent problem where existing scripts are throwing the:
Pine cannot determine the referencing length of a series. Try using max_bars_back in the study or strategy function.

error can usually be fixed by using max_bars_back=300 in your study() or strategy() declaration statement.
πŸ”ˆ #news
PineCoders is now on Twitter.
https://twitter.com/PineCoders
🌲 #newfeature
A new resolution= parameter to study() provides coders with a simple way to give their script MTF functionality without using security().

See how the "Moving Average" built-in from the Editor's "New" menu uses it. Make sure you are comfortable with the feature before publishing scripts using it. The HTF values returned contain gaps.
πŸ”ˆ #news
midtownsk8rguy has updated his color chart. Labels make it easier to identify colors. This is a good and pretty complete selection of colors that work well:

https://www.tradingview.com/script/yyDYIrRQ-Pine-Color-Magic-and-Chart-Theme-Simulator/
❀1
🌲 #newfeature
else if
The else if structure is now allowed!

//@version=4
study("")
a = 0
if close > open
a := 3
else if close < open
a := 2
else
a := 1
plot(a)
❀1
🌲 #newfeature
Premium accounts can now control the expiry date on access to their invite-only script publications. See the blog post.
πŸ’ͺ #tip
Ever wonder how the Strategy Tester values are calculated? This doc explains it all.
πŸ”ˆ #news
alexgrover has added Ema() and Atr() functions accepting series lengths to his brilliant Functions Allowing Series As Length script published from the PineCoders account.
🌲 #newfeature
We now have alerts on strategies! Pine coders can use the new alert_message= parameter in order-placing strategy.*() calls to define an alert message that varies with each type of order. Please read feature specs carefully.
https://www.tradingview.com/blog/en/strategy-alerts-are-live-now-18770/
πŸ’ͺ #tip
When using security() and you want to avoid repainting, remember that it's critical to use two techniques TOGETHER:
1. Offset the series with [1]
2. Use lookahead = barmerge.lookahead_on

noRepaintAndNoFutureData  = security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)

We see code in scripts that uses lookahead on but doesn't offset the series, which produces 2 adverse effects:
a) Future data is used on historical bars, which let's your script cheat and misleads traders, as there is no way your code can reproduce that behavior in realtime, because there are no future bars to cheat with then.
b) The value will repaint in realtime.

//@version=4
study("", "", true)
noRepaintAndNoFutureData = security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)
repaintsAndUsesFutureData = security(syminfo.tickerid, "D", close, lookahead = barmerge.lookahead_on)
plot(noRepaintAndNoFutureData, "Good", color.green, 2)
plot(repaintsAndUsesFutureData, "Bad", color.red, 2)

https://www.tradingview.com/x/hkfEyExW/
πŸ’ͺ #tip
To repaint or not to repaint?
Traders ask script authors all the time if our scripts repaint, as if it was something inherently bad, which it isn't. The decision to code a repainting or non-repainting signal is yours to make, and should be based on your design, your calculations, what features you want to offer users of your script, and how you intend alerts to be used with your script. The best option is often to provide users with a Repaint/No Repaint choice, but that is not always possible.

Note that a simple RSI like:
r = rsi(close, 14)
plot(r)

is a repainting signal, as the value of r will vary during the realtime bar.

Also note that if your users ask for a non-repainting version of that plot, then you will need to plot a late signal, and so users should realize this. They can't have their cake and eat it too: non-repainting signals are by definition late, like this:
r = rsi(close, 14)[1]
plot(r)

or this equivalent code:
r = rsi(close[1], 14)
plot(r)

or this one:
r = rsi(close, 14)
plot(r[1])

Which version you will use will depend on your needs and the code's context.
πŸ’ͺ #tip
When using security(), the way we achieve repainting or non-repainting needs to take into account the context of that function's call. These are your 2 options:

//@version=4
study("", "", true)
repaint = security(syminfo.tickerid, "D", close)
noRepaint = security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)
plot(repaint, "repaint", color.green, 8, transp = 70)
plot(noRepaint, "noRepaint", color.green, 2)


Again, it is critical NOT to mix up using no offset to the series as in the repaint case AND using lookahead = barmerge.lookahead_on, as this will produce lookahead bias by using future data.

https://www.tradingview.com/x/H0gjYIDP/
❀1
🐞#bug
The textalign= parameter defaults to center, regardless of the argument you use, when you create a label. Until the problem is fixed, there is a workaround:

//@version=4
study("")
if bar_index % 5 == 0
// Alignment doesn't work here.
_b = label.new(bar_index, high, "T\nTTTTT", textalign = text.align_right)
// Works here.
label.set_textalign(_b, text.align_right)
πŸ‘1
🌲 #newfeature
Previously, second, minute, hour, year, month, dayofmonth and dayofweek always returned time in the exchange's time. A new timezone= parameter was added to them so you can now retrieve the bar's time in any timezone.
https://www.tradingview.com/pine-script-reference/v4/#fun_hour
🌲 #newfeature
The syminfo.basecurrency variable was added. It returns the base currency of the current symbol, so "EUR" for "EURUSD".
https://www.tradingview.com/pine-script-reference/v4/#var_syminfo{dot}basecurrency