Tengo problemas para que la línea se trace correctamente con entradas de tiempo para que sea más interactivo y más fácil mover las líneas de tendencia en el gráfico. Tengo entendido que para trazar una línea necesito hacer referencia al número de barra y, como tal, estoy usando un ciclo para comparar input.time con el tiempo de un valor de barra para una coincidencia que dibuja una línea con éxito.
Sin embargo, el problema es que la línea no se traza de x1 a x2 debido a un valor/a hasta después de calcular el valor de x2 en esa barra y, por lo tanto, no se dibuja nada antes de esa barra.
//@version=5 indicator("My Trend Line Script For Webhook", overlay=true) start_x1_time = input.time(title="S Time/Profit #1", defval=(timestamp("06 Nov 2021 04:30 +0000")), inline = "start", group = "Start Position Trend Line", confirm=(true)) start_y1 = input.price(title="", defval=0.2, inline = "start", group = "Start Position Trend Line", confirm=(true)) start_x2_time = input.time(title="S Time/Profit #2", defval=(timestamp("07 Nov 2021 04:30 +0000")), inline = "start2", group = "Start Position Trend Line", confirm=(true)) start_y2 = input.price(title="", defval=0.3, inline = "start2", group = "Start Position Trend Line", confirm=(true)) // for correlating time to appropriate bar index i=0 float start_x1_bar = na float start_x2_bar = na while i <= 1500 if start_x1_time == time[i] start_x1_bar := bar_index-i if start_x2_time == time[i] start_x2_bar := bar_index-i if start_x2_bar and start_x1_bar !=na break i += 1 // TRENDLINE CODE // -------------- get_slope(x1,x2,y1,y2)=> m = (y2-y1)/(x2-x1) get_y_intercept(m, x1, y1)=> b=y1-m*x1 get_y(m, b, ts)=> Y = m * ts + b res_m = get_slope(start_x1_bar,start_x2_bar,start_y1,start_y2) res_b = get_y_intercept(res_m, start_x1_bar, start_y1) res_y = get_y(res_m, res_b, bar_index) plot(res_y, color=color.red, title='Trendline Price Value', linewidth=1)Imagen de la línea que falta de x1 a x2: