Indicator · Pine Script v4 · Own pane

Test-Alphabet

by ricardosantos79· code credited to RicardoSantos

This indicator builds a string from an integer by counting its digits, splitting the value into two-digit indices, and mapping each index to an uppercase letter or a printable ASCII character.

View on GitHub

GitHub stars261on the repository
Pine versionv4older, still runs
Lines of code108
Settings1inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago13 Nov 2021

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

108 lines of Pine Script v4 from beta/arrays/test-036-intostr.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

test-036-intostr.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=4
study(title='test-alphabet')


// f_encode(_integers)=>
// //https://upscaledb.com/0009-32bit-integer-compression-algorithms.html
//     int _size = array.size(id=_integers)
//     int _value = na
//     if _size > 0
//         _value := array.get(id=_integers, index=0)
//         for _i = 1 to _size - 1
//             _value := array.get(id=_integers, index=_i) - _value



f_ndigit(_value)=>
    _abs = abs(_value)
    _count = 0
    for _i = 0 to 9999999
        if _abs == 0
            break
        _abs := floor(_abs / 10)
        _count := _count + 1
    _count

f_int_shift_digit(_integer, _shift)=>
    int(floor(_integer / pow(10, _shift)))

f_upper_alphabet(_i)=>
    (_i==00?'':(_i==01?'A':(_i==02?'B':(_i==03?'C':(_i==04?'D':(_i==05?'E':(_i==06?'F':(_i==07?'G':(_i==08?'H':(_i==09?'I':
     (_i==10?'J':(_i==11?'K':(_i==12?'L':(_i==13?'M':(_i==14?'N':(_i==15?'O':(_i==16?'P':(_i==17?'Q':(_i==18?'R':(_i==19?'S':
     (_i==20?'T':(_i==21?'U':(_i==22?'V':(_i==23?'W':(_i==24?'X':(_i==25?'Y':(_i==26?'Z':(_i==27?'':(_i==28?'':(_i==29?'':''
     )))))))))) )))))))))) ))))))))))
     
f_ascii_alphabet(_i)=>
    (_i==00?'':(_i==01?'!':(_i==02?'"':(_i==03?'#':(_i==04?'$':(_i==05?'%':(_i==06?'&':(_i==07?"'":(_i==08?'(':(_i==09?')':
     (_i==10?'*':(_i==11?'+':(_i==12?',':(_i==13?'-':(_i==14?'.':(_i==15?'/':(_i==16?'0':(_i==17?'1':(_i==18?'2':(_i==19?'3':
     (_i==20?'4':(_i==21?'5':(_i==22?'6':(_i==23?'7':(_i==24?'8':(_i==25?'9':(_i==26?':':(_i==27?';':(_i==28?'<':(_i==29?'=':
     (_i==30?'>':(_i==31?'?':(_i==32?'@':(_i==33?'A':(_i==34?'B':(_i==35?'C':(_i==36?'D':(_i==37?'E':(_i==38?'F':(_i==39?'G':
     (_i==40?'H':(_i==41?'I':(_i==42?'J':(_i==43?'K':(_i==44?'L':(_i==45?'M':(_i==46?'N':(_i==47?'O':(_i==48?'P':(_i==49?'Q':
     (_i==50?'R':(_i==51?'S':(_i==52?'T':(_i==53?'U':(_i==54?'V':(_i==55?'W':(_i==56?'X':(_i==57?'Y':(_i==58?'Z':(_i==59?'[':
     (_i==60?'\\':(_i==61?']':(_i==62?'^':(_i==63?'_':(_i==64?'`':(_i==65?'a':(_i==66?'b':(_i==67?'c':(_i==68?'d':(_i==69?'e':
     (_i==70?'f':(_i==71?'g':(_i==72?'h':(_i==73?'i':(_i==74?'j':(_i==75?'k':(_i==76?'l':(_i==77?'m':(_i==78?'n':(_i==79?'o':
     (_i==80?'p':(_i==81?'q':(_i==82?'r':(_i==83?'s':(_i==84?'t':(_i==85?'u':(_i==86?'v':(_i==87?'w':(_i==88?'x':(_i==89?'y':
     (_i==90?'z':(_i==91?'{':(_i==92?'|':(_i==93?'}':(_i==94?'~':(_i==95?'':(_i==96?'':(_i==97?'':(_i==98?'':(_i==99?'':''
     )))))))))) )))))))))) )))))))))) )))))))))) )))))))))) )))))))))) )))))))))) )))))))))) )))))))))) ))))))))))

f_select_alphabet(_i, _v)=>
    (_i==00?f_ascii_alphabet(_v):(_i==01?f_upper_alphabet(_v):na))

f_indices_to_string(_indices, _alphabet)=>
    int _size = array.size(id=_indices)
    string _output = ''
    if _size > 0
        for _c = 0 to _size-1
            int _indice = array.get(id=_indices, index=_c)
            _output := _output + f_select_alphabet(_alphabet, _indice)
    _output

f_int_to_alphabet_indices(_integer)=>
    int[] _integers = array.new_int(0)
    int _digits = f_ndigit(_integer)
    int _old = _integer
    for _i = 0 to _digits
        if _old <= 0
            break
        float _shifted = _old / 100
        int _new = floor(_shifted)
        int _indice = int((_shifted - floor(_new)) * 100)
        array.unshift(id=_integers, value=_indice)
        _old := floor(_new)
    _integers

string _text = f_ascii_alphabet(input(-1))
int _N = input(0102030405060708)//09//10//11121314151617181920212223242526
if barstate.ishistory[1] and barstate.isrealtime
    int[] indices = f_int_to_alphabet_indices(_N)
    _text := _text + '\n' + tostring(_N) + ' -> looks ok\n'
    _text := _text + '\n' + tostring(indices) + ' -> repeats 6 and doesnt print first step\n'
    _text := _text + f_indices_to_string(indices, 1) + ' -> conversion correct'// 0:ascii, 1:upper
    // for _i = 0 to 999999
    //     _text := _text + '\n' + tostring(_i) + ' : '
    //     if _N <= 0
    //         break
    //     float _shifted = _N / 100
    //     int _new = floor(_shifted)
    //     int _rest = int((_shifted - _new) * 100)
    //     string _str = f_upper_alphabet(_rest)
    //     _text := _text + tostring(_N) + ' : ' + _str
    //     _N := _new
    
    label.new(bar_index, close, _text)


//|----------------------------------------------------------------------------|
// BINARY           >>>>    01
// OCTAL            >>>>    01234567
// DECIMAL          >>>>    0123456789
// HEXADECIMAL      >>>>    0123456789ABCDEF
// DNA              >>>>    ACGT
// LOWERCASE        >>>>    abcdefghijklmnopqrstuvwxyz
// UPPERCASE        >>>>    ABCDEFGHIJKLMNOPQRSTUVWXYZ
// PROTEIN          >>>>    ACDEFGHIKLMNPQRSTVWY
// BASE64           >>>>    ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
// ASCII base-95    >>>>    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Overview

A selector chooses which alphabet function is used, and the mapped characters are concatenated. The visible input supplies the integer passed into the ASCII mapping. A commented routine sketches integer-array encoding but is not executed. It is a study in a separate pane and does not plot prices or generate trade signals.

Details

Published by

ricardosantos79 on GitHub

Code credit

RicardoSantos, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
_Nint0102030405060708_N
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator
549 stars

Range Volume Change compares volume inside a chosen session window with the same window on the previous day and plots that change as a percentage. It accumulates volume during the window and, when enabled, volume outside it, drawing growing columns in a separa

Indicator v5 VolumeSessions & time Repaints
Updated 10 months ago · None stated GitHub repository of Range Volume Change

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers