Добави в этот код отображение ещё одной линии skewness с длинной period3 + Линия с period2 с тайм фрема 1 часи линия с period2 с таймфрема 4 часа. Только линия, в таблицу не добавляй. Сделай выключатель на новые линии.
//@version=5
indicator("Risk/Performance x3", overlay = false)

// === Настройки ===
period = input.int(240, title="Период для всех моделей", minval=1)
market_symbol = input.symbol("BINANCE:BTCUSDT.P", title="Benchmark")
risk_free_rate_annual = input.float(0.01, title="Годовая безрисковая ставка", minval=0.0, step=0.001)
days_in_year = input.int(365, title="Количество торговых дней в году", minval=1)
timeframe = input.timeframe("", title="Таймфрейм для расчета")
disable_bg_color = input.bool(false, title="Отключить закраску фона для всех моделей (кроме Beta и Omega)")
disable_beta_bg_color = input.bool(true, title="Отключить закраску фона для Beta")
disable_omega_bg_color = input.bool(true, title="Отключить закраску фона для Omega")

// === Настройки цветов ===
positive_color_base = input.color(#5b95aa, title="Базовый цвет для положительных значений")
negative_color_base = input.color(#b2182c, title="Базовый цвет для отрицательных значений")
text_color = input.color(color.rgb(255, 255, 255), title="Цвет текста")
bgcolor_4_left = input.color(color.rgb(252, 252, 252, 100), title="Базовый цвет для Моделей") 

// Параметр сглаживания
smoothing_length = input.int(14, title="Длина сглаживания среднего индекса", minval=1)

// Параметры для настроек таблицы
table_position = input.string("top_right", title="Положение таблицы", options=["top_left", "top_right", "bottom_left", "bottom_right"])
table_border_width = input.int(1, title="Ширина рамки таблицы", minval=0)

// Выключатель для отображения линий метрик
show_metrics_lines = input.bool(false, title="Показать линии метрик")

// Выключатель для отображения среднего индекса
show_average_index = input.bool(true, title="Показать средний индекс1")
show_average_index2 = input.bool(true, title="Показать средний индекс2")
show_average_index3 = input.bool(true, title="Показать средний индекс3")

// === Настройка отображения гистограммы ===
show_histogram = input.bool(false, title="Показать гистограмму направления")

// Периоды для расчета метрик
period1 = input.int(90, title="Период 1", minval=1)
period2 = input.int(240, title="Период 2", minval=1)
period3 = input.int(1200, title="Период 3", minval=1)


// Преобразуем годовую безрисковую ставку в дневную
risk_free_rate = risk_free_rate_annual / days_in_year

// === Данные ===
[returns, market_returns] = request.security(syminfo.tickerid, timeframe, [ta.roc(close, 1), request.security(market_symbol, timeframe, ta.roc(close, 1))])

// === Функции ===
sharpe_ratio(returns, risk_free_rate, period) =>
    excess_returns = returns - risk_free_rate
    avg_excess_returns = ta.sma(excess_returns, period)  // Вынесен вызов ta.sma
    stddev_excess_returns = ta.stdev(excess_returns, period)
    stddev_excess_returns != 0 ? avg_excess_returns / stddev_excess_returns : na

covariance(x, y, length) =>
    avg_x = ta.sma(x, length)
    avg_y = ta.sma(y, length)
    sum_xy = 0.0
    for i = 0 to length - 1
        sum_xy := sum_xy + ((x[i] - avg_x) * (y[i] - avg_y))
    sum_xy / length

beta(portfolio_returns, market_returns, period) =>
    cov = covariance(portfolio_returns, market_returns, period)
    market_variance = ta.variance(market_returns, period)
    cov / market_variance

array_stdev(arr) =>
    if array.size(arr) == 0
        0.0
    else
        mean = 0.0
        for i = 0 to array.size(arr) - 1
            mean := mean + array.get(arr, i)
        mean := mean / array.size(arr)
        
        variance = 0.0
        for i = 0 to array.size(arr) - 1
            variance := variance + math.pow(array.get(arr, i) - mean, 2)
        variance := variance / array.size(arr)
        math.sqrt(variance)

sortino_ratio(returns, risk_free_rate, period) =>
    downside_returns_array = array.new_float(period)
    count = 0
    for i = 0 to period - 1 
        if (returns[i] < risk_free_rate)
            array.set(downside_returns_array, count, returns[i])
            count += 1
    downside_returns = array.slice(downside_returns_array, 0, count)
    downside_stddev = array_stdev(downside_returns) 
    avg_excess_returns = ta.sma(returns - risk_free_rate, period)  // Вынесен вызов ta.sma
    downside_stddev != 0 ? avg_excess_returns / downside_stddev : na

treynor_ratio(returns, market_returns, risk_free_rate, period) =>
    beta_val = beta(returns, market_returns, period)
    avg_excess_returns = ta.sma(returns - risk_free_rate, period)  // Вынесен вызов ta.sma
    avg_excess_returns / beta_val

alpha(portfolio_returns, market_returns, risk_free_rate, period) =>
    beta_val = beta(portfolio_returns, market_returns, period)
    market_excess_returns = ta.sma(market_returns - risk_free_rate, period)
    expected_portfolio_return = risk_free_rate + beta_val * market_excess_returns
    avg_portfolio_return = ta.sma(portfolio_returns, period)
    avg_portfolio_return - expected_portfolio_return

omega_ratio(returns, period) =>
    gains = array.new_float(0)
    losses = array.new_float(0)
    
    for i = 0 to period - 1
        if (returns[i] > 0)
            array.push(gains, returns[i])
        else
            array.push(losses, -returns[i]) 
    
    avg_gain = array.size(gains) > 0 ? array.sum(gains) / array.size(gains) : 0.0
    avg_loss = array.size(losses) > 0 ? array.sum(losses) / array.size(losses) : 0.0
    
    avg_loss != 0 ? avg_gain / avg_loss : na

var_value(returns, period) =>
    sorted_returns = array.new_float(period)
    for i = 0 to period - 1
        array.set(sorted_returns, i, returns[i])
    array.sort(sorted_returns, order.ascending)
    percentile_index = math.floor(period * 0.05) 
    array.size(sorted_returns) > 0 ? array.get(sorted_returns, percentile_index) : na

// === Новые метрики ===
// Исправленная функция calmar_ratio
calmar_ratio(returns, period) =>
    close_price = close // Переименована переменная close
    max_drawdown = ta.highest(close_price, period) - ta.lowest(close_price, period)
    cagr = math.pow(close_price / ta.lowest(close_price, period), 365.0 / period) - 1 
    max_drawdown != 0 ? cagr / max_drawdown : na

// Исправленная функция ulcer_index
ulcer_index(close_price, period) => // Переименована переменная close
    drawdowns = math.max(close_price - ta.lowest(close_price, period), 0) 
    math.sqrt(ta.sma(drawdowns * drawdowns, period)) 

rachev_ratio(returns, period) =>
    sorted_returns = array.new_float(period)
    for i = 0 to period - 1
        array.set(sorted_returns, i, returns[i])
    array.sort(sorted_returns, order.ascending)
    top_percentile_index = math.floor(period * 0.05)
    bottom_percentile_index = math.floor(period * 0.95)
    top_returns = array.slice(sorted_returns, 0, top_percentile_index)
    bottom_returns = array.slice(sorted_returns, bottom_percentile_index, period)
    avg_top_returns = array.size(top_returns) > 0 ? array.sum(top_returns) / array.size(top_returns) : na
    avg_bottom_returns = array.size(bottom_returns) > 0 ? array.sum(bottom_returns) / array.size(bottom_returns) : na
    avg_bottom_returns != 0 ? avg_top_returns / avg_bottom_returns : na

skewness(returns, period) =>
    avg_returns = ta.sma(returns, period)
    stddev_returns = ta.stdev(returns, period)
    
    // Определяем cubed_deviations с типом float и изначально присваиваем значение 'na'
    var float cubed_deviations = na
    
    // Выполняем проверку на ненулевое стандартное отклонение, чтобы избежать деления на ноль
    if stddev_returns != 0
        cubed_deviations := math.pow((returns - avg_returns) / stddev_returns, 3) 
    
    // Возвращаем усреднённое значение кубических отклонений
    ta.sma(cubed_deviations, period)

// Исправленная функция covar (была covariance)
covar(portfolio_returns, market_returns, period) =>
    beta_val = beta(portfolio_returns, market_returns, period)
    market_var = ta.stdev(market_returns, period)
    beta_val * market_var

// === Вычисление показателей для разных периодов ===
// Функция для расчета всех метрик для заданного периода
calculate_metrics(period) =>
    sharpe = sharpe_ratio(returns, risk_free_rate, period)
    beta_val = beta(returns, market_returns, period)
    sortino = sortino_ratio(returns, risk_free_rate, period)
    treynor = treynor_ratio(returns, market_returns, risk_free_rate, period)
    alpha_val = alpha(returns, market_returns, risk_free_rate, period)
    omega = omega_ratio(returns, period)
    var_val = var_value(returns, period)
    calmar = calmar_ratio(returns, period)
    ulcer = ulcer_index(close, period)
    rachev = rachev_ratio(returns, period)
    skewness_val = skewness(returns, period)
    covar_val = covar(returns, market_returns, period)
    [sharpe, beta_val, sortino, treynor, alpha_val, omega, var_val, calmar, ulcer, rachev, skewness_val, covar_val]

// Вычисление метрик для каждого периода
[sharpe1, beta_val1, sortino1, treynor1, alpha_val1, omega1, var_val1, calmar1, ulcer1, rachev1, skewness_val1, covar_val1] = calculate_metrics(period1)
[sharpe2, beta_val2, sortino2, treynor2, alpha_val2, omega2, var_val2, calmar2, ulcer2, rachev2, skewness_val2, covar_val2] = calculate_metrics(period2)
[sharpe3, beta_val3, sortino3, treynor3, alpha_val3, omega3, var_val3, calmar3, ulcer3, rachev3, skewness_val3, covar_val3] = calculate_metrics(period3)

// === Определение направления с использованием всех метрик (без весов) ===

// Функция для определения направления по одной метрике
// Возвращает 1, если метрика указывает на рост, -1, если на падение, и 0, если нейтрально
get_direction(value, positive_is_good) =>
    if positive_is_good
        value > 0 ? 1 : (value < 0 ? -1 : 0)
    else
        value < 0 ? 1 : (value > 0 ? -1 : 0)

// Определение направления по каждой метрике
direction_sharpe = get_direction(sharpe2, true)
direction_beta = get_direction(beta_val2, true) 
direction_sortino = get_direction(sortino2, true)
direction_treynor = get_direction(treynor2, true)
direction_alpha = get_direction(alpha_val2, true)
direction_omega = get_direction(omega2, true)
direction_var = get_direction(var_val2, false) // Исправлено: учтен VaR
direction_calmar = get_direction(calmar2, true)
direction_ulcer = get_direction(ulcer2, false)
direction_rachev = get_direction(rachev2, true)
direction_skewness = get_direction(skewness_val2, true)
direction_covar = get_direction(covar_val2, true) 

// Суммарный балл для роста и падения (исправлено)
growth_score = 0
fall_score = 0

growth_score := growth_score + (direction_sharpe > 0 ? direction_sharpe : 0)
growth_score := growth_score + (direction_beta > 0 ? direction_beta : 0)
growth_score := growth_score + (direction_sortino > 0 ? direction_sortino : 0)
growth_score := growth_score + (direction_treynor > 0 ? direction_treynor : 0)
growth_score := growth_score + (direction_alpha > 0 ? direction_alpha : 0)
growth_score := growth_score + (direction_omega > 0 ? direction_omega : 0)
growth_score := growth_score + (direction_var > 0 ? direction_var : 0)
growth_score := growth_score + (direction_calmar > 0 ? direction_calmar : 0)
growth_score := growth_score + (direction_ulcer > 0 ? direction_ulcer : 0)
growth_score := growth_score + (direction_rachev > 0 ? direction_rachev : 0)
growth_score := growth_score + (direction_skewness > 0 ? direction_skewness : 0)
growth_score := growth_score + (direction_covar > 0 ? direction_covar : 0)

fall_score := fall_score + (direction_sharpe < 0 ? -direction_sharpe : 0)
fall_score := fall_score + (direction_beta < 0 ? -direction_beta : 0)
fall_score := fall_score + (direction_sortino < 0 ? -direction_sortino : 0)
fall_score := fall_score + (direction_treynor < 0 ? -direction_treynor : 0)
fall_score := fall_score + (direction_alpha < 0 ? -direction_alpha : 0)
fall_score := fall_score + (direction_omega < 0 ? -direction_omega : 0)
fall_score := fall_score + (direction_var < 0 ? -direction_var : 0)
fall_score := fall_score + (direction_calmar < 0 ? -direction_calmar : 0)
fall_score := fall_score + (direction_ulcer < 0 ? -direction_ulcer : 0)
fall_score := fall_score + (direction_rachev < 0 ? -direction_rachev : 0)
fall_score := fall_score + (direction_skewness < 0 ? -direction_skewness : 0)
fall_score := fall_score + (direction_covar < 0 ? -direction_covar : 0)

// Нормализация баллов
max_score = math.max(growth_score, fall_score)
normalized_growth_score = max_score > 0 ? growth_score / max_score : 0
normalized_fall_score = max_score > 0 ? fall_score / max_score : 0

// === Отображение гистограммы (исправлено) ===
plot_growth = show_histogram and normalized_growth_score >= 0 ? normalized_growth_score : na // Отображаем только положительные значения
plot_fall = show_histogram and normalized_fall_score >= 0 ? normalized_fall_score : na // Отображаем только положительные значения

plot(plot_growth, title="Вероятность роста", style=plot.style_histogram, color=color.rgb(1, 76, 79,40), linewidth=2)
plot(plot_fall, title="Вероятность падения", style=plot.style_histogram, color=color.rgb(178, 24, 44,40), linewidth=2)

// Средний индекс (без Treynor)
//average_index = (sharpe1 + beta_val1 + sortino1 + alpha_val1 + omega1 + var_val1 + calmar1 + ulcer1 + rachev1 + skewness_val1 + covar_val1) / 11
average_index = (sharpe1 + beta_val1 + sortino1 + alpha_val1 + omega1 + var_val1 + ulcer1 + rachev1 + skewness_val1 + covar_val1) / 10
average_index2 = (sharpe2 + beta_val2 + sortino2 + alpha_val2 + omega2 + var_val2 + ulcer2 + rachev2 + skewness_val2 + covar_val2) / 10
average_index3 = (sharpe3 + beta_val3 + sortino3 + alpha_val3 + omega3 + var_val3  + ulcer3 + rachev3 + skewness_val3 + covar_val3) / 10

//average_index = (sharpe1 + sharpe2 + sharpe3 + beta_val1 + beta_val2 + beta_val3 + sortino1 + sortino2 + sortino3 + alpha_val1 + alpha_val2 + alpha_val3 + omega1 + omega2 + omega3 + var_val1 + var_val2 + var_val3 + calmar1 + calmar2 + calmar3 + ulcer1 + ulcer2 + ulcer3 + rachev1 + rachev2 + rachev3 + skewness_val1 + skewness_val2 + skewness_val3 + covar_val1 + covar_val2 + covar_val3) / 11

// Сглаживание среднего индекса
smoothed_average_index = ta.sma(average_index, smoothing_length)
smoothed_average_index2 = ta.sma(average_index2, smoothing_length)
smoothed_average_index3 = ta.sma(average_index3, smoothing_length)

// === Отображение сглаженного среднего индекса ===
plot(show_average_index ? smoothed_average_index : na, title="Сглаженный Средний Индекс1", color=color.rgb(219, 219, 219), linewidth=2)
plot(show_average_index2 ? smoothed_average_index2 : na, title="Сглаженный Средний Индекс2", color=color.rgb(0, 188, 201), linewidth=2)
plot(show_average_index3 ? smoothed_average_index3 : na, title="Сглаженный Средний Индекс3", color=color.rgb(0, 119, 255), linewidth=2,style=plot.style_stepline)


// === Функция для динамического цвета ячеек ===
dynamic_color(value, positive_color_base, negative_color_base) =>
    value >= 0 ? color.new(positive_color_base, 80 - math.min(80, math.abs(value * 100))) : color.new(negative_color_base, 80 - math.min(80, math.abs(value * 100)))

// === Функция для подсветки фона ===
highlight_background(value, positive_color_base, negative_color_base, positive_is_good) =>
    positive_is_good ? (value >= 0 ? color.new(positive_color_base, 90) : color.new(negative_color_base, 90)) : (value <= 0 ? color.new(positive_color_base, 90) : color.new(negative_color_base, 90))

// === Отображение линий метрик ===
plot(show_metrics_lines ? sharpe2 : na, title="Sharpe Ratio", color=color.aqua)
plot(show_metrics_lines ? beta_val2 : na, title="Beta", color=color.blue)
plot(show_metrics_lines ? sortino2 : na, title="Sortino Ratio", color=color.fuchsia)
plot(show_metrics_lines ? treynor2 : na, title="Treynor Ratio", color=color.gray)
plot(show_metrics_lines ? alpha_val2 : na, title="Alpha", color=color.green)
plot(show_metrics_lines ? omega2 : na, title="Omega Ratio", color=color.lime)
plot(show_metrics_lines ? var_val2 : na, title="VaR", color=color.red, linewidth=2) // Изменен цвет и толщина линии VaR
plot(show_metrics_lines ? calmar2 : na, title="Calmar Ratio", color=color.navy)
plot(show_metrics_lines ? ulcer2 : na, title="Ulcer Index", color=color.olive)
plot(show_metrics_lines ? rachev2 : na, title="Rachev Ratio", color=color.orange)
plot(show_metrics_lines ? skewness_val2 : na, title="Skewness", color=color.white) // Изменен цвет линии Skewness
plot(show_metrics_lines ? covar_val2 : na, title="CoVaR", color=color.red)


// Определение позиции таблицы
var table_position_enum = position.top_right
if table_position == "top_left"
    table_position_enum := position.top_left
if table_position == "bottom_left"
    table_position_enum := position.bottom_left
if table_position == "bottom_right"
    table_position_enum := position.bottom_right




// === Создаем таблицу с учётом выбранного положения и ширины рамки
var table t = table.new(table_position_enum, 4, 39, border_width = table_border_width, frame_width = table_border_width, frame_color=color.gray, border_color=color.gray)

// Заполняем таблицу значениями и добавляем разделители
if (bar_index == last_bar_index)
    // Разделитель для "Показатели риска"
    table.cell(t, 0, 0, text = "Risk", text_color=color.rgb(255, 255, 255), bgcolor=color.rgb(49, 49, 49, 59))
    
    // Beta
    table.cell(t, 0, 1, text = "Beta", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 1, text = str.tostring(beta_val1, "#.##"), text_color=text_color, bgcolor=dynamic_color(beta_val2, positive_color_base, negative_color_base))
    table.cell(t, 2, 1, text = str.tostring(beta_val2, "#.##"), text_color=text_color, bgcolor=dynamic_color(beta_val1, positive_color_base, negative_color_base)) // Period 1
    table.cell(t, 3, 1, text = str.tostring(beta_val3, "#.##"), text_color=text_color, bgcolor=dynamic_color(beta_val3, positive_color_base, negative_color_base)) // Period 3
    
    // VaR
    table.cell(t, 0, 4, text = "VaR", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 4, text = str.tostring(var_val1, "#.##"), text_color=text_color, bgcolor=highlight_background(var_val2, positive_color_base, negative_color_base, false))
    table.cell(t, 2, 4, text = str.tostring(var_val2, "#.##"), text_color=text_color, bgcolor=highlight_background(var_val1, positive_color_base, negative_color_base, false)) // Period 1
    table.cell(t, 3, 4, text = str.tostring(var_val3, "#.##"), text_color=text_color, bgcolor=highlight_background(var_val3, positive_color_base, negative_color_base, false)) // Period 3

    // Ulcer
    table.cell(t, 0, 7, text = "Ulcer", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 7, text = str.tostring(ulcer1, "#.##"), text_color=text_color, bgcolor=highlight_background(ulcer2, positive_color_base, negative_color_base, false))
    table.cell(t, 2, 7, text = str.tostring(ulcer2, "#.##"), text_color=text_color, bgcolor=highlight_background(ulcer1, positive_color_base, negative_color_base, false)) // Period 1
    table.cell(t, 3, 7, text = str.tostring(ulcer3, "#.##"), text_color=text_color, bgcolor=highlight_background(ulcer3, positive_color_base, negative_color_base, false)) // Period 3

    // CoVaR
    table.cell(t, 0, 10, text = "CoVaR", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 10, text = str.tostring(covar_val1, "#.##"), text_color=text_color, bgcolor=highlight_background(covar_val2, positive_color_base, negative_color_base, true))
    table.cell(t, 2, 10, text = str.tostring(covar_val2, "#.##"), text_color=text_color, bgcolor=highlight_background(covar_val1, positive_color_base, negative_color_base, true)) // Period 1
    table.cell(t, 3, 10, text = str.tostring(covar_val3, "#.##"), text_color=text_color, bgcolor=highlight_background(covar_val3, positive_color_base, negative_color_base, true)) // Period 3
    
    // Разделитель для "Показатели доходности/эффективности"
    table.cell(t, 0, 13, text = "Performance", text_color=color.rgb(255, 255, 255), bgcolor=color.rgb(49, 49, 49, 59))
    
    // Alpha
    table.cell(t, 0, 14, text = "Alpha", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 14, text = str.tostring(alpha_val1, "#.##"), text_color=text_color, bgcolor=dynamic_color(alpha_val2, positive_color_base, negative_color_base))
    table.cell(t, 2, 14, text = str.tostring(alpha_val2, "#.##"), text_color=text_color, bgcolor=dynamic_color(alpha_val1, positive_color_base, negative_color_base)) // Period 1
    table.cell(t, 3, 14, text = str.tostring(alpha_val3, "#.##"), text_color=text_color, bgcolor=dynamic_color(alpha_val3, positive_color_base, negative_color_base)) // Period 3
    
    // Sortino
    table.cell(t, 0, 17, text = "Sortino", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 17, text = str.tostring(sortino1, "#.##"), text_color=text_color, bgcolor=dynamic_color(sortino2, positive_color_base, negative_color_base))
    table.cell(t, 2, 17, text = str.tostring(sortino2, "#.##"), text_color=text_color, bgcolor=dynamic_color(sortino1, positive_color_base, negative_color_base)) // Period 1
    table.cell(t, 3, 17, text = str.tostring(sortino3, "#.##"), text_color=text_color, bgcolor=dynamic_color(sortino3, positive_color_base, negative_color_base)) // Period 3
    
    // Omega
    table.cell(t, 0, 20, text = "Omega", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 20, text = str.tostring(omega1, "#.##"), text_color=text_color, bgcolor=highlight_background(omega2, positive_color_base, negative_color_base, true))
    table.cell(t, 2, 20, text = str.tostring(omega2, "#.##"), text_color=text_color, bgcolor=highlight_background(omega1, positive_color_base, negative_color_base, true)) // Period 1
    table.cell(t, 3, 20, text = str.tostring(omega3, "#.##"), text_color=text_color, bgcolor=highlight_background(omega3, positive_color_base, negative_color_base, true)) // Period 3

// Skewness
    table.cell(t, 0, 23, text = "Skewness", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 23, text = str.tostring(skewness_val1, "#.##"), text_color=text_color, bgcolor=highlight_background(skewness_val2, positive_color_base, negative_color_base, true))
    table.cell(t, 2, 23, text = str.tostring(skewness_val2, "#.##"), text_color=text_color, bgcolor=highlight_background(skewness_val1, positive_color_base, negative_color_base, true)) // Period 1
    table.cell(t, 3, 23, text = str.tostring(skewness_val3, "#.##"), text_color=text_color, bgcolor=highlight_background(skewness_val3, positive_color_base, negative_color_base, true)) // Period 3
    
    // Разделитель для "Показатели соотношения доходности и риска"
    table.cell(t, 0, 26, text = "Risk/Reward", text_color=color.rgb(255, 255, 255), bgcolor=color.rgb(49, 49, 49, 59))
    
    // Sharpe
    table.cell(t, 0, 27, text = "Sharpe", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 27, text = str.tostring(sharpe1, "#.##"), text_color=text_color, bgcolor=dynamic_color(sharpe2, positive_color_base, negative_color_base))
    table.cell(t, 2, 27, text = str.tostring(sharpe2, "#.##"), text_color=text_color, bgcolor=dynamic_color(sharpe1, positive_color_base, negative_color_base)) // Period 1
    table.cell(t, 3, 27, text = str.tostring(sharpe3, "#.##"), text_color=text_color, bgcolor=dynamic_color(sharpe3, positive_color_base, negative_color_base)) // Period 3
    
    // Treynor
    table.cell(t, 0, 30, text = "Treynor", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 30, text = str.tostring(treynor1, "#.##"), text_color=text_color, bgcolor=dynamic_color(treynor2, positive_color_base, negative_color_base))
    table.cell(t, 2, 30, text = str.tostring(treynor2, "#.##"), text_color=text_color, bgcolor=dynamic_color(treynor1, positive_color_base, negative_color_base)) // Period 1
    table.cell(t, 3, 30, text = str.tostring(treynor3, "#.##"), text_color=text_color, bgcolor=dynamic_color(treynor3, positive_color_base, negative_color_base)) // Period 3

    // Calmar
    table.cell(t, 0, 33, text = "Calmar", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 33, text = str.tostring(calmar1, "#.##"), text_color=text_color, bgcolor=highlight_background(calmar2, positive_color_base, negative_color_base, true))
    table.cell(t, 2, 33, text = str.tostring(calmar2, "#.##"), text_color=text_color, bgcolor=highlight_background(calmar1, positive_color_base, negative_color_base, true)) // Period 1
    table.cell(t, 3, 33, text = str.tostring(calmar3, "#.##"), text_color=text_color, bgcolor=highlight_background(calmar3, positive_color_base, negative_color_base, true)) // Period 3
    
    // Rachev
    table.cell(t, 0, 36, text = "Rachev", text_color=text_color, bgcolor=bgcolor_4_left)
    table.cell(t, 1, 36, text = str.tostring(rachev1, "#.##"), text_color=text_color, bgcolor=highlight_background(rachev2, positive_color_base, negative_color_base, true))
    table.cell(t, 2, 36, text = str.tostring(rachev2, "#.##"), text_color=text_color, bgcolor=highlight_background(rachev1, positive_color_base, negative_color_base, true)) // Period 1
    table.cell(t, 3, 36, text = str.tostring(rachev3, "#.##"), text_color=text_color, bgcolor=highlight_background(rachev3, positive_color_base, negative_color_base, true)) // Period 3

        // === Закрашивание фона на истории ===
bg_color_sharpe = disable_bg_color ? na : highlight_background(sharpe2, positive_color_base, negative_color_base, true)
bg_color_beta = disable_beta_bg_color ? na : highlight_background(beta_val2, positive_color_base, negative_color_base, true)
bg_color_sortino = disable_bg_color ? na : highlight_background(sortino2, positive_color_base, negative_color_base, true)
bg_color_treynor = disable_bg_color ? na : highlight_background(treynor2, positive_color_base, negative_color_base, true)
bg_color_alpha = disable_bg_color ? na : highlight_background(alpha_val2, positive_color_base, negative_color_base, true)
bg_color_omega = disable_omega_bg_color ? na : highlight_background(omega2, positive_color_base, negative_color_base, true)
//bg_color_var = disable_bg_color ? na : highlight_background(var_val2, positive_color_base, negative_color_base, false)
bg_color_calmar = disable_bg_color ? na : highlight_background(calmar2, positive_color_base, negative_color_base, true)
bg_color_ulcer = disable_bg_color ? na : highlight_background(ulcer2, positive_color_base, negative_color_base, false)
bg_color_rachev = disable_bg_color ? na : highlight_background(rachev2, positive_color_base, negative_color_base, true)
bg_color_skewness = disable_bg_color ? na : highlight_background(skewness_val2, positive_color_base, negative_color_base, true)
bg_color_covar = disable_bg_color ? na : highlight_background(covar_val2, positive_color_base, negative_color_base, true)

// Закрашиваем фон для каждой модели отдельно
bgcolor(bg_color_sharpe)
//bgcolor(bg_color_beta)
bgcolor(bg_color_sortino)
bgcolor(bg_color_treynor)
bgcolor(bg_color_alpha)
bgcolor(bg_color_omega)
//bgcolor(bg_color_var)
bgcolor(bg_color_calmar)
bgcolor(bg_color_ulcer)
bgcolor(bg_color_rachev)
bgcolor(bg_color_skewness)
bgcolor(bg_color_covar)

hline(0, title="Горизонтальная линия", color=#ffffff, linestyle=hline.style_dashed, linewidth=1)
hline(0.5, title="Горизонтальная линия", color=#00c753, linestyle=hline.style_dashed, linewidth=1)
hline(1, title="Горизонтальная линия", color=#ff0000, linestyle=hline.style_dashed, linewidth=2)
hline(-1, title="Горизонтальная линия", color=#ff0000, linestyle=hline.style_dashed, linewidth=2)
hline(-0.5, title="Горизонтальная линия", color=#00c753, linestyle=hline.style_dashed, linewidth=1)