TradingView
f4r33x
5 nov 2022 19:26

Encoder Decoder 

BTCUSDT Perpetual ContractBybit

Descrizione

Library "EncoderDecoder"


Simple example how to encode some values into float number and then decode it back to original values



f_calctype()
  Encode parameter
  Returns: encoded value

f_calctype()
  Decode parameter
  Returns: decoded value

f_srctype()
  Encode parameter
  Returns: encoded value

f_srctype()
  Decode parameter
  Returns: decoded value

f_encode(calc_type, src_type, tf, length)
  Encodes 4 paramters into float number
  Parameters:
    calc_type: 1st paramter to encode (its values defined in f_calctype functions) max number of values that can be encoded = 100
    src_type: 2nd paramter to encode (its values defined in f_src_type functions) max number of values that can be encoded = 100
    tf: 3rd paramter to encode (may be int number with format.price precision length!)
    length: 4th paramter to encode (may be any int number)
  Returns: float number

f_decode()
  Decodes 4 paramters into tuple
  Returns: tuple [calc_type, src_type, length, tf]

Note di rilascio

v2

Added:
float value can contain longer value, that cannot end by '0 or 9'
f_count_intdigits()
  Count int digits in number
  Returns: number of int digits in number

f_count_floatdigits()
  Count float digits in number
  Returns: number of float digits in number

Note di rilascio

v3 fix bugs

Note di rilascio

v4
code cleaning
Commenti
kaigouthro
Have you considered a non-limited version allowing user's freedom of inputs? something i've been meaning to get at myself to encode an entire array of strings and floats into one single float value to pass as a plot to another indicator.
f4r33x
@kaigouthro, due to pinescript limitations thats not possible to encode more than ~30 10 bit values, also length of encoded values should be known, so for every case you should encode and decode values differently
kaigouthro
@f4r33x, my thoughts are towards pseudo-compression to binary, by turning floats into a string, concatenating strings each of same length, then convert the long string number to binary, pass the binary through and decode to string and split strings back to floats on the other side.
Altro