ConverterTF
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hapharmonic

//@version=5

// @description I have found a bug Regarding the timeframe display, on the chart I have found that the display is numeric, for example 4Hr timeframe instead of '4H', but it turns out to be '240', which I want it to be displayed in abbreviated form. And in all other timeframes it's the same. So this library was created to solve those problems. It converts a timeframe from a numeric string type to an integer type by selecting a timeframe manually and displaying it on the chart.
library("ConverterTF")

// @function X.GetTF(TF)
// @returns String Timeframe >> 1s....1m .... 4h...
///
TFCVmulti() =>
    tf = timeframe.multiplier
    tfstr = ""
    if timeframe.isseconds
        tfstr := "s"
    else if timeframe.isminutes
        if tf >= 60
            tf := tf / 60
            tfstr := "h"
        else
            tfstr := "m"
    else if timeframe.isdaily
        tfstr := "D"
    else if timeframe.isweekly
        tfstr := "W"
    else if timeframe.ismonthly
        tfstr := "M"  
        
    [tfstr, str.tostring(tf)]

TFCVcustom(float TF , string DWM) =>
    tf = float(na)
    tfstr = ""
        
    if DWM == "D" or DWM == "W" or DWM == "M"
        tf := TF
        tfstr := DWM
        
    else if TF >= 60 and TF <= 1380
        tf := TF / 60
        tfstr := "h"
    else if TF <= 59
        tf := TF
        tfstr := "m"
        
    [tfstr, str.tostring(tf)]


export CTF(string str) =>
    newStr = str
    st = str.split(str, '') // SUBtextarray
    sizeTF = array.size(st)-1 //MAXSIZE
    typetf = str.replace_all(newStr, array.get(st,sizeTF), "") //= remove DWM //= num
    DMW = array.get(st,sizeTF) //=  DWM 
    
    if DMW == 'D' or DMW == 'W' or DMW == 'M'
        newStr := typetf
    
    TF = str.tonumber(newStr)
    
    tf = string(na) , period = string(na)
    if str != ''
        [tf1, period1] = TFCVcustom(TF,DMW)
        tf:=tf1,period:=period1
    else
        [tf2, period2] = TFCVmulti()
        tf:=tf2,period:=period2
        
    TimeF = period+tf
    TimeF


str = input.timeframe(title='Time frame', defval='240')
TimeF = CTF(str)
L=label.new(bar_index, high, 'Before>> Timeframe '+str+'\nAfter>> Timeframe '+TimeF,style=label.style_label_down,size=size.large)
label.delete(L[1])
