TradingView
MichelT
Feb 11, 2020 6:56 PM

Emulating binary operations and several values in one variable 

Apple Inc.NASDAQ

描述

Binary operations and storing several numbers in one variable.

It's useful when you need to pass a values numbers to another study. Study-on-study (SOS) in Tradingview allows passing only one value, which is not always convinient. So if we put all those numbers in one - we can pass more values from one study to another.

In Pine we can use up to 52 bits for our data. Because of that we can put 6 1-byte (8-bit) values in one float. Or 12 4-bit values. Or 52 1-bit values.

评论
LucF
Another great and useful piece of code. Thx Michel.
MichelT
@LucF, Thanks, Luc.
michl
... and don't forget the single var return from security :)
MichelT
@michl, Oh, yes. But as far I know, it won't be a problem soon - security will be allowed to return a tuple.
theheirophant
bravo, ingenious
yatrader2
This is great, thank you!
Daveatt
May I call you "sensei"? Brilliant
Daveatt
@Daveatt, what could be the use cases for such a script?
Apart from passing output signals for buy/sell/close buy/close sell signals

Curious to know what are the general use cases you have in mind?
MichelT
@Daveatt, the only I can thik of are passing values to another script and returning more values from the security function. Few times I met cases when people used too much variables in their scripts, so the scripts couldn't be compiled, because of restriction on amount of the variables. It might (franckly, I doubt, but it might) be a workaround for the restriction - putting together several variables to make a script working.
MichelT
@Daveatt, You are welcome, Daveatt!
更多