Converting Dev Market Profile from TradingView

I

ironlion2012

New member
Hello, I am new to TOS and am in need of assistance converting code from pinescript in TradingView to thinkscript for TOS. Can anyone assist in converting this code for a developing market profile? Again the code below is in PineScript Version 4 from TradingView. Looking to convert to ThinkScript for TOS.

Code:
//@version=4
study(title='Dev Market Profile', shorttitle='MP', overlay=true)
//  ||--    Inputs:
session_timeframe = input('D')
percent_of_tpo = input(0.70)
tf_high = high
tf_low = low
tf_close = close
//  ||--    Bars since session started:
session_bar_counter = bar_index - valuewhen(change(time(session_timeframe)) != 0, bar_index, 0)
//plot(session_bar_counter)
//  ||--    session high, low, range:
session_high = tf_high
session_low = tf_low
session_range = tf_high - tf_low

session_high := nz(session_high[1], tf_high)
session_low := nz(session_low[1], tf_low)
session_range := nz(session_high - session_low, 0.0)

//      ||--    recalculate session high, low and range:
if session_bar_counter == 0
    session_high := tf_high
    session_low := tf_low
    session_range := tf_high - tf_low
    session_range
if tf_high > session_high[1]
    session_high := tf_high
    session_range := session_high - session_low
    session_range
if tf_low < session_low[1]
    session_low := tf_low
    session_range := session_high - session_low
    session_range
plot(series=session_high, title='Session High', color=color.blue)
plot(series=session_low, title='Session Low', color=color.blue)
//plot(series=session_range, title='Session Range', color=black)
//  ||--    define tpo section range:
tpo_section_range = session_range / 21
//  ||--    function to get the frequency a specified range is visited:
f_frequency_of_range(_src, _upper_range, _lower_range, _length) =>
    _adjusted_length = _length < 1 ? 1 : _length
    _frequency = 0
    for _i = 0 to _adjusted_length - 1 by 1
        if _src[_i] >= _lower_range and _src[_i] <= _upper_range
            _frequency := _frequency + 1
            _frequency
    _return = nz(_frequency, 0)  // _adjusted_length
    _return
//  ||--    frequency the tpo range is visited:
tpo_00 = f_frequency_of_range(tf_close, session_high, session_high - tpo_section_range * 1, session_bar_counter)
tpo_01 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 1, session_high - tpo_section_range * 2, session_bar_counter)
tpo_02 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 2, session_high - tpo_section_range * 3, session_bar_counter)
tpo_03 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 3, session_high - tpo_section_range * 4, session_bar_counter)
tpo_04 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 4, session_high - tpo_section_range * 5, session_bar_counter)
tpo_05 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 5, session_high - tpo_section_range * 6, session_bar_counter)
tpo_06 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 6, session_high - tpo_section_range * 7, session_bar_counter)
tpo_07 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 7, session_high - tpo_section_range * 8, session_bar_counter)
tpo_08 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 8, session_high - tpo_section_range * 9, session_bar_counter)
tpo_09 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 9, session_high - tpo_section_range * 10, session_bar_counter)
tpo_10 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 10, session_high - tpo_section_range * 11, session_bar_counter)
tpo_11 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 11, session_high - tpo_section_range * 12, session_bar_counter)
tpo_12 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 12, session_high - tpo_section_range * 13, session_bar_counter)
tpo_13 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 13, session_high - tpo_section_range * 14, session_bar_counter)
tpo_14 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 14, session_high - tpo_section_range * 15, session_bar_counter)
tpo_15 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 15, session_high - tpo_section_range * 16, session_bar_counter)
tpo_16 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 16, session_high - tpo_section_range * 17, session_bar_counter)
tpo_17 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 17, session_high - tpo_section_range * 18, session_bar_counter)
tpo_18 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 18, session_high - tpo_section_range * 19, session_bar_counter)
tpo_19 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 19, session_high - tpo_section_range * 20, session_bar_counter)
tpo_20 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 20, session_high - tpo_section_range * 21, session_bar_counter)
//  ||--    function to retrieve a specific tpo value
f_get_tpo_count_1(_value) =>
    _return = 0.0
    if _value == 0
        _return := tpo_00
        _return
    if _value == 1
        _return := tpo_01
        _return
    if _value == 2
        _return := tpo_02
        _return
    if _value == 3
        _return := tpo_03
        _return
    if _value == 4
        _return := tpo_04
        _return
    if _value == 5
        _return := tpo_05
        _return
    if _value == 6
        _return := tpo_06
        _return
    if _value == 7
        _return := tpo_07
        _return
    if _value == 8
        _return := tpo_08
        _return
    if _value == 9
        _return := tpo_09
        _return
    if _value == 10
        _return := tpo_10
        _return
    if _value == 11
        _return := tpo_11
        _return
    if _value == 12
        _return := tpo_12
        _return
    if _value == 13
        _return := tpo_13
        _return
    if _value == 14
        _return := tpo_14
        _return
    if _value == 15
        _return := tpo_15
        _return
    if _value == 16
        _return := tpo_16
        _return
    if _value == 17
        _return := tpo_17
        _return
    if _value == 18
        _return := tpo_18
        _return
    if _value == 19
        _return := tpo_19
        _return
    if _value == 20
        _return := tpo_20
        _return
    _return
f_get_tpo_count_2(_value) =>
    _return = 0.0
    if _value == 0
        _return := tpo_00
        _return
    if _value == 1
        _return := tpo_01
        _return
    if _value == 2
        _return := tpo_02
        _return
    if _value == 3
        _return := tpo_03
        _return
    if _value == 4
        _return := tpo_04
        _return
    if _value == 5
        _return := tpo_05
        _return
    if _value == 6
        _return := tpo_06
        _return
    if _value == 7
        _return := tpo_07
        _return
    if _value == 8
        _return := tpo_08
        _return
    if _value == 9
        _return := tpo_09
        _return
    if _value == 10
        _return := tpo_10
        _return
    if _value == 11
        _return := tpo_11
        _return
    if _value == 12
        _return := tpo_12
        _return
    if _value == 13
        _return := tpo_13
        _return
    if _value == 14
        _return := tpo_14
        _return
    if _value == 15
        _return := tpo_15
        _return
    if _value == 16
        _return := tpo_16
        _return
    if _value == 17
        _return := tpo_17
        _return
    if _value == 18
        _return := tpo_18
        _return
    if _value == 19
        _return := tpo_19
        _return
    if _value == 20
        _return := tpo_20
        _return
    _return

tpo_sum = 0.0
current_poc_position = 0.0
current_poc_value = 0.0
for _i = 0 to 20 by 1
    _get_tpo_value = f_get_tpo_count_1(_i)
    tpo_sum := tpo_sum + _get_tpo_value
    if _get_tpo_value > current_poc_value
        current_poc_position := _i
        current_poc_value := _get_tpo_value
        current_poc_value
//plot(series=tpo_sum, title='tpo_sum', color=red)
poc_upper = session_high - tpo_section_range * current_poc_position
poc_lower = session_high - tpo_section_range * (current_poc_position + 1)
plot(series=poc_upper, title='POC Upper', color=color.black)
plot(series=poc_lower, title='POC Lower', color=color.black)

//  ||--    get value area high/low
vah_position = current_poc_position
val_position = current_poc_position
current_sum = current_poc_value

for _i = 0 to 20 by 1
    if current_sum < tpo_sum * percent_of_tpo
        vah_position := max(0, vah_position - 1)
        current_sum := current_sum + f_get_tpo_count_2(round(vah_position))
        current_sum
    if current_sum < tpo_sum * percent_of_tpo
        val_position := min(20, val_position + 1)
        current_sum := current_sum + f_get_tpo_count_2(round(val_position))
        current_sum

vah_value = session_high - tpo_section_range * vah_position
val_value = session_high - tpo_section_range * (val_position + 1)
plot(series=vah_value, title='VAH', color=color.navy)
plot(series=val_value, title='VAL', color=color.navy)
//plot(series=current_sum, title='SUM', color=red)
 
Top